Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The id provided does not exist razorpay in nodejs

i'm implementing razorpay payment gateway in my React.js app with backend nodejs.

here frontend.jsx

razorpayHandler = () =>{
        const payment_amount  = this.props.TotalPrice;
        const backend_url = 'https://25234399bb.ngrok.io';
        const self = this;
        const options = {
        key: config.RAZOR_PAY_KEY,
        amount: payment_amount * 100,
        name: 'StanPlus',
        description: 'pay your ambulance fare',
        handler(response) {
            const paymentId = response.razorpay_payment_id;
            const url =  backend_url+'/razorpay/'+paymentId+'/'+payment_amount+'/'+self.id;
            console.log(paymentId)
            // Using my server endpoints to capture the payment
            fetch(url, {
            method: 'get',
            headers: {
                "Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
            }
            })
            .then(resp =>  resp.json())
            .then(function (data) {
                    console.log(data)
            })
            .catch(function (error) {
                console.log('Request failed', error);
            });
        },
        theme: {
            color: '#40A9FF',
        },
        };
        const rzp1 = new window.Razorpay(options);

        rzp1.open();
    }

backend.js(nodejs)

var express = require('express');
var router = express.Router();
var config = require('../config');

const Razorpay = require('razorpay');
const instance = new Razorpay({
  key_id: config.razorpay_live_key,
  key_secret: config.razorpay_live_secret,
});

router.get('/:payment_id/:amount/:BID',function(req,res,next){
    const {payment_id } = req.params;
    const {BID} = req.params;
    const amount = Number(req.params.amount*100);
    instance.payments.capture(payment_id, amount).then((data) => {
        data.Bid = BID;
        res.json(data);
    }).catch((error) => {
        res.json(error);
    });
})
module.exports = router;

it showing me error

"statusCode":400,"error":{"code":"BAD_REQUEST_ERROR","description":"The id provided does not exist"

but if the same code if do process using test key its getting successfully completed but it is not working with live api.
here i'm passing an extra parameter to the backend which required for us but if removed that parameter then also it is not working.but with parameter it is working with test api.
when we send request to backend it is generating id and sending to backend also but still it showing The id provided does not exist.

like image 976
zulqarnain Avatar asked Nov 28 '18 02:11

zulqarnain


People also ask

How do you implement Razorpay in node JS?

Explanation: The first script tag is loading a js file from the Razorpay server. It has some code inside it, which is responsible for executing this whole code snippet. In the second script tag, we are creating an object which later will be sent to the Razorpay server to proceed with payment.

Is Razorpay order ID unique?

When a customer clicks the pay button on your website or app, an order is created with a unique identifier. This contains details such as the transaction amount and currency. The order ID secures the payment request and one cannot tamper with the order amount. Pass this order ID to the Razorpay Checkout.


1 Answers

if you are using test mode then just remove order_id parameter from json object.

like image 154
saigopi.me Avatar answered Sep 19 '22 11:09

saigopi.me