Sandbox.payex-checkout-v1.Frontend API - Frontend API 
Page of - pēdējo reizi mainījis Asbjørn Ulsberg laiks 2018/07/05 12:48 
Frontend API 

Asbjørn Ulsberg

2018/07/05 12:48
Satura rādītājs
Add JavaScript reference
Basic usage
Basic usage with options
Flexibility usage
Reference
payex.checkout(paymentSessionUrl, options)
payex.checkout(paymentSessionUrl, command)
payex.checkout(paymentSessionUrl, options, command)
payex.checkout(options)

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 . 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 
�	onClose 
�	onError 
�	onComplete 
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
		
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 
�	onOpen 
�	onError 
�	onComplete 	
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
		
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" - 	
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
		
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 
�	onOpen 
�	onError 
�	onComplete 	
command
string	The command to be excuted
�	"open" - 	
Example
payex.checkout("<payment_session_url>", {
        onComplete: function() {
              // Your code goes here.
      }
}, "open");
payex.checkout(options)
Sets defaults options for all Payment Sessions.
Arguments
		
options
object
  	Set options for the payment session.
�	onClose 
�	onOpen 
�	onError 
�	onComplete 	
Example
payex.checkout({
        onOpen: function(){
                console.log("The modal was opened");
        }
});