Skip to content

Commit fdc5970

Browse files
committed
Update README.md
1 parent cb16c0d commit fdc5970

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

README.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,14 @@ Start by adding the `@paytmScripts` tag into the `<head>` tag of your page. For
103103
@paytmScripts
104104
</head>
105105
```
106-
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**.
106+
107+
Next, to initiate the Checkout Payment Page, you have 2 available methods -
108+
109+
##### Method # 1
110+
111+
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).
112+
113+
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**.
107114

108115
```php
109116
// Somewhere in your page
@@ -122,8 +129,36 @@ Next, to initiate the Checkout Payment Page, you need to callout `openJsCheckout
122129
```
123130
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`.
124131

125-
### Step # 3 - Receiving Callback
126-
The **callback** from the Paytm PG will provide an array containing the following (for a successful transaction) -
132+
##### Method # 2
133+
134+
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.
135+
136+
```php
137+
// Somewhere in your page
138+
<button type="button" id="JsCheckoutPayment" name="submit" class="btn btn-primary">Pay Now</button>
139+
140+
// Before the closing </body> tag
141+
<script type="application/javascript">
142+
document.getElementById("JsCheckoutPayment").addEventListener("click", function() {
143+
var orderId = "{{ $response['orderId'] }}";
144+
var txnToken = "{{ $response['txnToken'] }}";
145+
var amount = "{{ $response['amount'] }}";
146+
// Pass an additional "false" attribute which marks redirect as false.
147+
openJsCheckoutPopup(orderId, txnToken, amount, false);
148+
}
149+
);
150+
151+
// To be executed upon completion of the payment (only if false is passed above).
152+
function paymentCompleted(paymentStatus) {
153+
window.Paytm.CheckoutJS.close(); // Close the Paytm PG Pop-up.
154+
console.log(paymentStatus); // Log or use the payment status/details returned.
155+
}
156+
</script>
157+
```
158+
Once you set the redirect flag as false, you can use the `paymentCompleted` function to excute further queries using the returned data.
159+
160+
### Step # 3 - Receiving Response
161+
The **response** from the Paytm PG (via callback or same page) will provide an array containing the following (for a successful transaction) -
127162
```php
128163
array:14 [▼
129164
"BANKNAME" => "State Bank of India"

0 commit comments

Comments
 (0)