MERN项目集成Razorpay支付网关时UPI选项缺失问题求助
MERN栈集成Razorpay支付网关:UPI选项不显示问题求助
我在MERN栈项目中集成Razorpay支付网关时遇到问题:支付界面仅显示银行卡、网银、钱包、先买后付选项,UPI选项完全不显示。以下是项目相关代码,希望有人能帮忙排查解决。
相关截图说明
- 截图1:支付界面仅展示银行卡、网银、钱包、先买后付四种支付方式
- 截图2:支付方式展开详情,无任何UPI相关选项
server.js 后端代码
router.post("/checkout", async (req, res) => { try { const { totalPrice } = req.body; const { totalprice } = totalPrice; const amount = totalprice; // 转换为最小货币单位(如派萨) console.log('Request Body:', req.body); console.log('Total Amount:', totalprice); console.log('Amount in paisa:', amount); // 打印转换后的金额 // 创建支付订单 const options = { amount, // 订单金额(最小货币单位) currency: "INR", receipt: "receipt#1", payment_capture: 1, }; const order = await instance.orders.create(options); console.log(order); res.status(200).json({ success: true, order }); } catch (error) { console.error('Error during checkout:', error); res.status(500).json({ success: false, error: 'Error during checkout' }); } }); // 支付验证接口 router.post("/paymentverification", async (req, res) => { try { const { razorpay_order_id, razorpay_payment_id, razorpay_signature } = req.body; const body = razorpay_order_id + "|" + razorpay_payment_id; const expectedSignature = crypto.createHash('sha256', process.env.RAZORPAY_API_SECRET) .update(body.toString()) .digest('hex'); const isAuthentic = expectedSignature === razorpay_signature; if (isAuthentic) { await razorpayment.create({ razorpay_order_id, razorpay_payment_id, razorpay_signature }); res.redirect(`http://localhost:3000/success?reference=${razorpay_payment_id}`); } else { res.status(400).json({ success: false, message: 'Invalid signature' }); } } catch (error) { console.error('Error during payment verification:', error); res.status(500).json({ success: false, error: 'Error during payment verification' }); } }); router.get("/api/getkey", (req, res) => { return res.status(200).json({ key: process.env.RAZORPAY_API_KEY }); });
checkout.js(React前端)代码
const checkouthandler = async (totalPrice) => { try { console.log('Total Price:', totalPrice); // 打印订单总价 // 获取Razorpay密钥 const { data: { key } } = await axios.get("http://localhost:5000/api/getkey"); // 创建支付订单 const { data: { order } } = await axios.post("http://localhost:5000/checkout", { totalPrice }); // 配置支付选项 const options = { key, totalprice: order.totalprice, currency: "INR", payment_method: 'upi', name: "Sinmplyjs", description: "Razorpay tutorials", image: "", order_id: order.id, callback_url: 'http://localhost:5000/paymentverification', prefill: { name: "raj gupta", email: "raj@gmail.com", contact: "1234567890" }, notes: { "address": "razorpay official" }, theme: { "color": "#3399cc" } }; // 初始化Razorpay并打开支付弹窗 const razorpay = new window.Razorpay(options); razorpay.open(); } catch (error) { console.error('Error during checkout:', error); // 错误处理 } }
内容的提问来源于stack exchange,提问作者kk queen
相关产品推荐
相关产品推荐

