Add JavaScript reference
Before implementing PayEx Checkout on your web site, you need to add a reference to the PayEx Checkout script to your page:
Please note that the above URL points to PayEx Checkout's production environment. If you want to integrate with PayEx' test environment, please refer to the FAQ for the correct URLs.
Basic usage
The simplest way to implement PayEx Checkout in your frontend is with the data-payex-checkout attribute.
Choose the button you want to open the PayEx Checkout modal and add the attribute data-payex-checkout with the value returned paymentSessionUrl from the initial POST. Then add the disable attribute - the PayEx Checkout script will enable it when it is properly loaded. The button should be wrapped inside a form that posts to your server.
The PayEx Checkout script will submit the <form> when the PayEx Checkout user flow is complete.
HTML
<!-- ... -->
<button data-payex-checkout="<payment_session_url>" disabled>Pay</button>
</form>
Basic usage with options
The PayEx Checkout script can be configured with options to get callbacks on certain events in the checkout user flow.
Availialbe callbacks:
- onOpen - Callback called when the PayEx Checkout modal is opened.
- onClose - Callback called when the PayEx Checkout modal is closed.
- onError - Callback called when PayEx Checkout is unable to open or complete a session.
- onComplete - Callback called when PayEx Checkout user flow is completed.
HTML
<!-- ... -->
<button data-payex-checkout="<payment_session_url>" disabled>Pay</button>
</form>
JavaScript
onClose: function(){
console.log("The modal was closed");
}
});
Flexibility usage
If you need more flexibility in your frontend, you can open the PayEx Checkout modal and post to your server programmatically.
If you have added it, start by removing the data-payex-checkout attribute to prevent the PayEx Checkout script to open and post automatically.
You can open the checkout modal on demand with the "open" argument and use the onComplete callback to post to your server when the PayEx Checkout user flow is completed to continue with the Get Payment Status step.
Please note that Checkout must be opened with a trusted context in order to prevent pop-up blockers. The code has a trusted context when it runs as result of an user action. Code running within async callbacks such as ajax and timeout loses trusted context, so make sure you have acquired a payment session url before the user click on your buy button.
JavaScript
payex.checkout("<payment_session_url>", {
onComplete: function() {
// Post or send a ajax request to your server to get the payment status step
}
}, "open");
Reference
payex.checkout(paymentSessionUrl, options)
Sets options for a payment session.
Arguments
Param | Details |
paymentSessionUrl | A string of the URL to the Payment Session. This URL should be retrieved before page is rendered in the browser by completing the intial server-to-server POST request. |
options | Set options for the payment session.
|
Example
onClose: function(){
console.log("The modal was closed");
}
});
payex.checkout(paymentSessionUrl, command)
Executes a PayEx Checkout action, such as opening the PayEx Checkout user flow.
Arguments
Param | Details |
paymentSessionUrl | A string of the URL to the Payment Session. This URL should be retrieved before page is rendered in the browser by completing the intial server-to-server POST request. |
command | The command to be excuted
|
Example
payex.checkout(paymentSessionUrl, options, command)
Sets options for a payment session and executes a PayEx Checkout action.
Arguments
Param | Details |
paymentSessionUrl | A string of the URL to the Payment Session. This URL should be retrieved before page is rendered in the browser by completing the intial server-to-server POST request. |
options | Set options for the payment session.
|
command string | The command to be excuted
|
Example
onComplete: function() {
// Your code goes here.
}
}, "open");
payex.checkout(options)
Sets defaults options for all Payment Sessions.
Arguments
Param | Details |
options | Set options for the payment session.
|
Example
onOpen: function(){
console.log("The modal was opened");
}
});