SSlcommerz integration in node.js
SSlcommerz is the biggest online payment gateway in Bangladesh. They offer more than 20 payment options for your client. In this article, I’ll try to explain the integration process to node.js server as simple as possible.
Here I will explain sandboxing process first.
First of all, you need to register for SSlcommerz store id, going here. You must fill all of required info. As you are registering for test purpose, you can fill all required box with dummy data.
After completing account creation process, SSlcommerz will send an email with store id and password :
After creating account, go here and login with your username and password (credential as you inputted in the time of registration). Then from navbar, go to My Stores ->IPN Settings and enable HTTP listener.
And by saving this, your SSlcommerz account setting is finished.
Now time to start coding.
First, install sslcommerz-nodejs npm package :
npm i sslcommerz-nodejs
setup your store_id and store_password :
let settings = {
isSandboxMode: true, //false if live version
store_id: STORE_ID_HERE
store_passwd: STORE_PASSWORD_HERE
}
Set perimeter for initializing a transaction session :
const SSLCommerz_payment_init = async (req) => {let sslcommerz = new SSLCommerz(settings);
let post_body = {};
post_body['total_amount'] = 150.25;
post_body['currency'] = "BDT";
post_body['tran_id'] = transaction_id;
post_body['success_url'] = success_url;
post_body['fail_url'] = failed_url;
post_body['cancel_url'] = cancel_url;
post_body['emi_option'] = 0;
post_body['cus_name'] = cus_name;
post_body['cus_email'] = cus_email;
post_body['cus_phone'] = cus_phone;
post_body['cus_add1'] = "Dhaka";
post_body['cus_city'] = "Dhaka";
post_body['cus_country'] = "Bangladesh";
post_body['shipping_method'] = "NO";
post_body['multi_card_name'] = ""
post_body['num_of_item'] = 1;
post_body['product_name'] = "none";
post_body['product_category'] = "none";
post_body['product_profile'] = "general"; let transaction_response = await sslcommerz.init_transaction(post_body)
return transaction_response.GatewayPageURL}
Change perimeters in post_body object as your requirement. From transaction_response.GatewayPageURL you will get an URL which is a SSlcommerz hosted page. Simply, you need to add this this page as a pop-up to your front-end. From here, SSlcommerz will handle everything.
After successful/failed/canceled transaction SSlcommerz will send a post response to the link specified in post_body object with a body containing transaction details.
If you want to go live and real transaction, just change your store id and password and set isSandboxMode = false in settings object.
Happy Coding