I am using node js to integrate PayTm “Create qr api” with the approch mentioned here -> “https://business.paytm.com/docs/api/create-qr-code-api/”
My code –
const Paytm = require('paytmchecksum');
const express = require('express');
const https = require('https');
const createQr = async (req,res) => {
const paytmParams = {
body: {
"mid": process.env.PAYTM_MERCHANT_ID,
"orderId": req.body.orderid,
"amount": `${req.body.amount}`,
"businessType": "UPI_QR_CODE",
"posId": "S12_123"
}
};
const checksum = await Paytm.generateSignature(JSON.stringify(paytmParams.body), process.env.PAYTM_SECRET_KEY)
console.log(checksum)
paytmParams.head = {
"clientId": "C11", // Replace with your client ID
"version": "v1",
"signature": checksum
};
const post_data = JSON.stringify(paytmParams);
const options = {
hostname: 'securegw.paytm.in',
port: 443,
path: '/paymentservices/qr/create',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': post_data.length
}
};
const post_req = https.request(options, function (post_res) {
let response = '';
post_res.on('data', function (chunk) {
response += chunk;
});
post_res.on('end', function () {
console.log('Response:', response);
res.json({ qrCodeResponse: JSON.parse(response) });
});
});
post_req.on('error', function (error) {
console.error('Error:', error);
res.status(500).send('Error generating QR code');
});
post_req.write(post_data);
post_req.end();
}
The response i am getting –
Response: {"resultInfo":{"resultStatus":"403","resultCodeId":null,"resultCode":null,"resultMsg":"Unauthorized Access","retryable":false}}
I tried using diff test merchant id’s and keys but it is not solving the problem