Development
Preview changes locally to update your docs
Payment Popup
If you wish to integrate Paytring’s JS / iframe checkout into your platform, follow the steps outlined below.
1. Include Paytring Iframe JavaScript Library
Include the Paytring Iframe JavaScript library by adding the following CDN link to your HTML file:
2. Creating an Order
After including the Paytring Iframe library, you can create an order and initiate the iframe checkout. Use the following JavaScript code:
Explanation
-
fail_handle Function:
- This function is a callback that will be executed if the transaction fails.
- It receives the
order_id
as an argument, allowing you to handle and log information about failed transactions. - You can use the Fetch API or other methods to check and retrieve details about the failed order.
-
success_handle Function:
- This function is a callback that will be executed if the transaction is successful.
- Similar to
fail_handle
, it receives theorder_id
as an argument. - You can use the Fetch API or other methods to check and retrieve details about the successful order.
-
event_happen Function:
- This function is a callback that logs events related to the Paytring Iframe.
- It logs the event name and event value to the console.
- The function is intended to be used for debugging and monitoring purposes.
-
on_close Function:
- This function is a callback that will be executed if the popup is closed for any reason.
- Similar to other callback functions, it receives the
order_id
as an argument. - You can use the Fetch API or other methods to check and retrieve details about the order.
-
options Object:
- An object that holds various options for configuring the Paytring Iframe.
- It includes the
order_id
received when creating the order, success and failed callback functions, and an events callback for logging events. - The
order_id
is mandatory, while the other parameters (success
,failed
, andevents
) are optional.
-
Paytring Instance:
- Creates an instance of the Paytring class with the specified options.
-
Open Iframe:
- The
open()
method is called on the Paytring instance, which opens the Paytring Iframe for the user to complete the payment. - Ensure that you replace
response.order_id
with the actual order id obtained from your order creation process. The provided callbacks (fail_handle
,success_handle
, andevent_happen
) allow you to customize how your application handles different aspects of the payment process.
- The
3. Handling Events
If you prefer not to pass callback functions directly in the options, you can alternatively use event handling to capture specific events during the iframe checkout process. This approach allows you to receive notifications for various actions, such as successful payments (payment.success
), failed transactions (payment.failed
), and the user closing the iframe before completing the transaction (payment.close
).
Event Handling Example
To capture events, you can utilize the following code:
-
Failed Event
-
Success Event
-
Close Event
If you prefer using these events, you don’t need to pass functions in the options. Simply use the following code:
Payment Callback Request
Param | Datatype | Sample Value |
---|---|---|
order_id | string | 488659548274428965 |
receipt_id | string | TXN01071200893 |
hash | string | ceb38f5bfba8ba190754d6cadd7af58b845406010b01aa297e10b145ca45da8f9eb1632d814158d0e88c15cc78ccc8e0a8661ae93c8a7f2356432e2b25fada65 |
Above is a sample of a request in Form Data Format. We strongly suggest you perform a lookup of the transaction in your database with the given details and fetch the order using the “Fetch by Order ID” API endpoint before updating your database.
Payment Webhook Request
Above is a sample of a request in JSON format. We strongly suggest you verify the hash, fetch the transaction, and perform a lookup of the transaction in your database with the given details before updating your database.