Skip to main content

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

  1. 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.
  2. success_handle Function:
    • This function is a callback that will be executed if the transaction is successful.
    • Similar to fail_handle, it receives the order_id as an argument.
    • You can use the Fetch API or other methods to check and retrieve details about the successful order.
  3. 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.
  4. 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.
  5. 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, and events) are optional.
  6. Paytring Instance:
    • Creates an instance of the Paytring class with the specified options.
  7. 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, and event_happen) allow you to customize how your application handles different aspects of the payment process.

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

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.