Payment Workflow
PayTabs provides you with the backend packages that make the integrating with PayTabs payment gateway very easy by providing ready-made classes that handle the payment process.
This manual provides a step-by-step workflow for using the PayTabs package. To customize the UI of the hosted payment page, check this article.
In this manual, we will wake you through the payment workflow for Node.js PayTabs Page.
You will need to make a function invocation for the
createPaymentPage()
function, to do that you will need to do the following steps:Require the package "paytabs_pt2":
const paytabs = require('paytabs_pt2');
Set the mandatory configurations:
paytabs.setConfig(profileID, serverKey, region)
the you can call the
createPaymentPage()
function:paytabs.createPaymentPage(
paymentMethodsFilter, //Array of all or filtered payment methods.
transaction, //Array of transaction class and type
cartDetails, //Array of cart details ID, currency, amount, etc
customerDetails, //Array of customer details name, email, phone, etc
shippingDetails, //Array of shipping details name, email, phone, etc
urls, //Array URLs endpoints used to return and callback
language, //Payment page language
callback, // the callback method to call after the payment page created
framed // boolean parameter to use the framed mode or note
);
After the payment page is created, and the callback is triggered, you will receive the result object, if successful, that contains the parameter
redirect_url
to redirect your customer to the payment page.function callbackMethod(result) {
//failed to create the payment page.
if (result['response_code:'] === 400) {
// get the message
console.log(result['result']);
// Next step
}
//success to create the payment page.
else {
//On success, redirect the customer to complete the payment.
console.log(result.redirect_url);
// Next step
}
}- Once the payment is completed, PayTabs will redirect the customer back to the merchantβs website, to the return URL that the merchant specified in the
urls
parameter, and the payment basic results will be posted to that URL.