The id provided does not exist razorpay in nodejs

zulqarnain picture zulqarnain · Nov 28, 2018 · Viewed 9k times · Source

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.

Answer

Sai Gopi Me picture Sai Gopi Me · Mar 24, 2020

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