The Checkout module is a javascript plugin to integrate BeSafe Pay in your e-commerce system in a few minutes.
The module will generate a payment button, based on the transaction parameters passed in the init function, that will redirect the user to the secure payment page to complete the transaction.
Once the transaction has been completed the user will be redirected to your e-commerce page along with the status of the transaction sent as a query parameter.
Init the module
To create the checkout module you first need to add the BeSafe Checkout Javascript to your web page. The scrit requires the API KEY of the hotel.
(function (b,e,s,a,f,p,y) {
b['BspGlobalObject'] = f
b[f] = b[f] || function () {
(b[f].q = b[f].q || []).push(arguments)
}
p = e.createElement(s), y = e.getElementsByTagName(s)[0]
p.async = 1
p.src = a
y.parentNode.insertBefore(p, y)
})(window, document, 'script', 'https://pay.besafesuite.com/js/checkout.js', 'bsp')
Now you can use the script to render the BeSafe Pay button send all the details of the reservation.
- [DIV_ID] must be replaced with the div id where you want the plugin to be mounted
- [PUBLIC_KEY] must be replaced with the hotel public key.
bsp('createButton', '[DIV_ID]', '[PUBLIC_KEY]', {
"arrival": "2021-08-07",
"departure": "2021-08-10",
"total": 556,
"first_name": "Mark",
"last_name": "Doe",
"email": "[email protected]",
"language_id": 'IT',
"s2sUrl": "https://yourserver.com/callback"
}, {
onSuccess: function (transactionId) {
alert('payment ok')
},
onFail: function (errorMessage) {
alert('payment nok')
}
})
Script parameters
arrival | Date of arrival in YYYY-MM-DD format |
departure | Date of arrival in YYYY-MM-DD format |
total | Total amount of the reservation |
first_name | First name of the payer |
last_name | Last name of the payer |
Email of the payer | |
language_id | Language code in ISO 2 Letter format |
s2sUrl | Callback url, we will make a post request to this endpoint with details about the charge. |
This function will generate a payment button using the given DIV ID as container. The button will fire a payment window on top of your e-commerce.
When the payment is completed you will receive a callback (onSuccess, onFail) with the details of the event.