SSLCOMMERZ Payment Gateway integration in NodeJs (with MERN example)
It is npm package which provides functionalities to implement SSLCommerz Payment Gateway in Node Based Apps.
Installation
Via NPM
npm i ssl-commerz-node
Via YARN
yarn add ssl-commerz-node
MERN Stack Example (demo)
Set the parameters to make a request
const SSLCommerz = require("ssl-commerz-node");
const PaymentSession = SSLCommerz.PaymentSession;
require("dotenv").config();
const payment = new PaymentSession(
true,
process.env.SSLCOMMERZ_STORE_ID,
process.env.SSLCOMMERZ_STORE_PASSWORD
);
payment.setUrls({
success: "yoursite.com/success",
fail: "yoursite.com/fail",
cancel: "yoursite.com/cancel",
ipn: "yoursite.com/ipn",
});
payment.setOrderInfo({
total_amount: 1570,
currency: "BDT",
tran_id: "ref12345667",
emi_option: 0,
multi_card_name: "internetbank",
allowed_bin: "371598,371599,376947,376948,376949",
emi_max_inst_option: 3,
emi_allow_only: 0,
});
payment.setCusInfo({
name: "Simanta Paul",
email: "simanta@bohubrihi.com",
add1: "66/A Midtown",
add2: "Andarkilla",
city: "Chittagong",
state: "Optional",
postcode: 4000,
country: "Bangladesh",
phone: "010000000000",
fax: "Customer_fax_id",
});
payment.setShippingInfo({
method: "Courier",
num_item: 2,
name: "Simanta Paul",
add1: "66/A Midtown",
add2: "Andarkilla",
city: "Chittagong",
state: "Optional",
postcode: 4000,
country: "Bangladesh",
});
payment.setProductInfo({
product_name: "Computer",
product_category: "Electronics",
product_profile: "general",
});
See this for details: https://developer.sslcommerz.com/doc/v4/#ready-the-parameters
After setting the parameters initialize the payment
exports.SSLCommerz_payment_init = async (req, res) => {
payment.paymentInit().then((response) => {
console.log(response);
});
}
This link containes details about the response parameters: https://developer.sslcommerz.com/doc/v4/#returned-parameters
Response Parameters Examples
After Success
console.log(response["status"]);
SUCCESS
console.log(response["sessionkey"]);
D37CD2C0A0D322991531D217E194F981
console.log(response["GatewayPageURL"]);
https://sandbox.sslcommerz.com/EasyCheckOut/testcded37cd2c0a0d322991531d217e194f981
After Failure (Wrong Store ID)
console.log(response["status"]);
FAILED
console.log(response["failedreason"]);
Store Credential Error Or Store is De-active
The GatewayPageURL is the url of the payment page.