Initiating the payment
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 is dedicated to walking you through how to initiate the payment/request payload using the configuration options and parameters that have already been clarified in the previous step, "Step 2 - Configure the integration method". Please follow the below steps to initiate a Hosted Payment Page via this package:
First thing, assigning the PayTabs Node.js module
paytabs_pt2
to a variable and set the configs as mentioned on the previous step.const PayTabs = require('paytabs_pt2');
PayTabs.setConfig( profileID, serverKey, region);Then, you MUST call the
createPaymentPage()
function to initiate the payment page along with passing the payment, transaction, cart, URLs, customer, and shipping details to initiate a pre-filled payment page with your provided information.let paymentMethods = ["all"];
let transactionDetails = [
transaction.type,
transaction.class
];
let cartDetails = [
cart.id,
cart.currency,
cart.amount,
cart.description
];
let customerDetails = [
customer.name,
customer.email,
customer.phone,
customer.street,
customer.city,
customer.state,
customer.country,
customer.zip,
customer.IP
];
let shippingDetails = customer_details; // If both are the same, otherwise set the shipping details.
let response_URLs = [
url.response,
url.callback
];
let lang = "ar";
callback = function ($results) {
console.log($results);
}
let frameMode = true;
PayTabs.createPaymentPage(
paymentMethods,
transactionDetails,
cartDetails,
customerDetails,
shippingDetails,
responseURLs,
lang,
callback,
frameMode
);
To get to know each function and its passed parameters, kindly check the below:
📄️ Manage the Payment Methods
- Payment filter
📄️ Manage the Transaction Details
- handle transaction type and class
📄️ Manage the Cart Details
- sendCart()
📄️ Manage Shipping and Billing Details
- sendShippingDetails() & sendCustomerDetails()
📄️ Manage the Return and Callback URLs
- set the Return and Callback URLs to get transactions response.
📄️ Manage the Payment Page Display Language
- Set the payment page language.
📄️ Manage The Callable Function
- Set the callback to next action after generating the payment page.
📄️ Initiate an iFramed/Embedded Payment Page
- Set famed mode status.