PaymentRoute.post(“/”, async (req, res) => {
try {
const { transaction_id, amount, user_phone } = req.body;
console.log(amount)
// Create the payment data object
const data = {
merchantId: "PGTESTPAYUAT",
merchantTransactionId: "MT7850590068188104",
merchantUserId: "MUID123", // Consider replacing this with dynamic data if needed
amount:100000, // Convert to the smallest currency unit if required
redirectUrl: `http://localhost:3000`,
redirectMode: 'POST',
CallbackUrl: `http://localhost:3000`,
mobileNumber: "9021733853", // Use provided phone number
paymentInstrument: {
type: 'PAY_PAGE'
}
};
const key = "099eb0cd-02cf-4e2a-8aca-3e6c6aff0399";
const keyIndex = 1;
// Convert the payment data to base64
const payload = JSON.stringify(data);
console.log(payload)
const payloadMain = Buffer.from(payload).toString("base64");
console.log("payloadMain" + payloadMain)
const stringToHash = payloadMain + "/pg/v1/pay" + key;
console.log("STring", stringToHash)
const sha256 = crypto.createHash('sha256').update(stringToHash).digest('hex');
console.log("hello", sha256)
const checksum = sha256 + "###" + keyIndex;
console.log(checksum)
// PhonePe API URL
const prod_URL = "https://api-preprod.phonepe.com/apis/pg-sandbox/pg/v1/pay";
// Send the payment request to PhonePe
// const options = {
// method: 'POST',
// url: prod_URL,
// headers: {
// accept: 'application/json',
// 'Content-Type': 'application/json',
// 'X-VERIFY': checksum
// },
// data: {
// request: payloadMain
// }
// };
// console.log(options)
axios.post(prod_URL, {
request: payloadMain
}, {
headers: {
accept: 'application/json',
'Content-Type': 'application/json',
'X-VERIFY': checksum
}
}).then(response => {
console.log("Payment successful:", response.data);
}).catch(error => {
console.error("Error in Axios request:", error.message);
if (error.response) {
console.error("Status:", error.response.status);
console.error("Data:", error.response.data);
}
});
// const redirect=response.data.data.instrumentResponse.redirectInfo.url;
// console.log(redirect)
// res.status(201).send({
// msg: "Payment initiated",
// status: "success",
// data: response.data,
// redirectUrl: redirectUrl
// });
// axios.request(options)
// .then(async function (response) {
// // const phonePeTransactionId = response.data.transactionId;
// res.status(201).send({
// msg: "payment done",
// status: "success",
// data: response.data,
// // phonePeTransactionId: phonePeTransactionId,
// });
// console.log("Payment API Response:", response.data);
// })
// .catch(function (error) {
// console.error("Payment API Error:", error.message);
// res.status(500).json({ msg: "Payment Failed", status: "error", error: error.message });
// });
} catch (error) {
console.error("Error in PhonePe payment route:", error);
res.status(500).send({
isError: true,
message: "Internal Server Error",
error
});
}
})
Error in Axios request: Request failed with status code 429
Status: 429
Data: {
success: false,
code: ‘TOO_MANY_REQUESTS’,
message: ‘Too many requests. Please try again.’,
data: {}
}
this is i am getting can anyone help me with my code why i am getting this error
New contributor
Pankaj Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.