diff --git a/README.md b/README.md index d7b6fe8..14e361b 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,14 @@ Start by adding the `@paytmScripts` tag into the `` tag of your page. For @paytmScripts ``` -Next, to initiate the Checkout Payment Page, you need to callout `openJsCheckoutPopup(orderId, txnToken, amount)` and pass it the `orderId`, `txntoken` and the `amount` received in **Step # 1**. + +Next, to initiate the Checkout Payment Page, you have 2 available methods - + +##### Method # 1 + +This method will invoke the payment gateway and upon completion, will redirect the user to the callback url set earlier (or in the config file). + +To achieve that, you need to call the `openJsCheckoutPopup(orderId, txnToken, amount)` function and pass it the `orderId`, `txntoken` and the `amount` received in **Step # 1**. ```php // Somewhere in your page @@ -122,8 +129,36 @@ Next, to initiate the Checkout Payment Page, you need to callout `openJsCheckout ``` Upon clicking the `Pay Now` button, a pop-up for the Paytm PG will open with all the options to make the payment. Once the payment is complete, you will be redirected to the `callback_url` set in the .env file as `PAYTM_CALLBACK_URL`. -### Step # 3 - Receiving Callback -The **callback** from the Paytm PG will provide an array containing the following (for a successful transaction) - +##### Method # 2 + +This method will allow you to handle the response on the same page (and ignore any callback urls set for this transaction). Useful when you want to process transaction without a redirect. + +```php +// Somewhere in your page + + +// Before the closing tag + +``` +Once you set the redirect flag as false, you can use the `paymentCompleted` function to excute further queries using the returned data. + +### Step # 3 - Receiving Response +The **response** from the Paytm PG (via callback or same page) will provide an array containing the following (for a successful transaction) - ```php array:14 [▼ "BANKNAME" => "State Bank of India" diff --git a/resources/dist/js/paytm.js b/resources/dist/js/paytm.js index 8eb487e..add9e6f 100644 --- a/resources/dist/js/paytm.js +++ b/resources/dist/js/paytm.js @@ -1,4 +1,4 @@ -function openJsCheckoutPopup(orderId, txnToken, amount) { +function openJsCheckoutPopup(orderId, txnToken, amount, redirect) { var config = { "root": "", "flow": "DEFAULT", @@ -9,13 +9,15 @@ function openJsCheckoutPopup(orderId, txnToken, amount) { "amount": amount }, "merchant": { - "redirect": true + "redirect": redirect ?? true }, "handler": { - "notifyMerchant": function (eventName, data) { - console.log("notifyMerchant handler function called"); + notifyMerchant: function notifyMerchant(eventName, data) { console.log("eventName => ", eventName); - console.log("data => ", data); + // console.log("data => ", data); // only enable for debugging + }, + transactionStatus: function transactionStatus(paymentStatus) { + paymentCompleted(paymentStatus); // only called when redirect is set to false } } };