Frontend API

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:

<script src="https://checkout.payex.com/js/payex-checkout.min.js"></script>

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

<form action="<url_to_your_server>" method="post">
  <!-- ... -->
   <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

<form action="<url_to_your_server>">
   <!-- ... -->
    <button data-payex-checkout="<payment_session_url>" disabled>Pay</button>
</form>

JavaScript

payex.checkout("<payment_session_url>", {
    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

// Remember to remove the data-payex-checkout attribute if you implemented it.

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

ParamDetails

paymentSessionUrl
string

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
object
 

Set options for the payment session.

  • onClose   function - Callback called when the PayEx Checkout modal is closed.
  • onOpen  function - Callback called when the PayEx Checkout modal is opened.
  • onError  function - Callback called when PayEx Checkout is unable to open or complete a session.
  • onComplete  function - Callback called when PayEx Checkout user flow is completed.

Example

payex.checkout("<payment_session_url>", {
    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

ParamDetails

paymentSessionUrl
string

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
string
 

The command to be excuted

  • "open"   - Opens the PayEx Checkout user flow.

Example

payex.checkout("<payment_session_url>", "open");

payex.checkout(paymentSessionUrl, options, command)

Sets options for a payment session and executes a PayEx Checkout action.

Arguments

ParamDetails

paymentSessionUrl
string

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
object
 

Set options for the payment session.

  • onClose   function - Callback called when the PayEx Checkout modal is closed.
  • onOpen  function - Callback called when the PayEx Checkout modal is opened.
  • onError  function - Callback called when PayEx Checkout is unable to open or complete a session.
  • onComplete  function - Callback called when PayEx Checkout user flow is completed.
command
string

The command to be excuted

  • "open"   - Opens the PayEx Checkout user flow.

Example

payex.checkout("<payment_session_url>", {
    onComplete: function() {
       // Your code goes here.
   }
}, "open");

payex.checkout(options)

Sets defaults options for all Payment Sessions.

Arguments

ParamDetails

options
object
 

Set options for the payment session.

  • onClose   function - Callback called when the PayEx Checkout modal is closed.
  • onOpen  function - Callback called when the PayEx Checkout modal is opened.
  • onError  function - Callback called when PayEx Checkout is unable to open or complete a session.
  • onComplete  function - Callback called when PayEx Checkout user flow is completed.

Example

payex.checkout({
    onOpen: function(){
        console.log("The modal was opened");
    }
});
Created by Asbjørn Ulsberg on 2018/07/05 12:48
   

Tips

Jump to any page in the wiki with Ctrl+G or Meta+G.
See more shortcuts.

Need help?

If you need help with XWiki you can contact: