The id provided does not exist razorpay in nodejs
Asked Answered
M

9

16

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.

Macfarlane answered 28/11, 2018 at 2:45 Comment(3)
please refer the index.js file here: github.com/razorpay/razorpay-node/blob/master/examples/index.js which contains the snippets of all the API calls.Contrapositive
@HarshaMarri I'm following this repo.i'm doing same as razorpay APIs mentioned.and id generating in test module but not liveMacfarlane
Simply don't pass wth order id, it worked for meAmabelle
F
45

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

Fascicle answered 24/3, 2020 at 2:29 Comment(7)
it helps, in test mode. but I think you are passing your internal order id and not the razorpay order id. If you pass correct razorpay id then you don't need to remove the order id even in test mode.Gammon
@Gammon Can you please help to find the correct id? order = client.order.create(......) So I have passed order['id'] as order id. Tell me if this id is not the one in test mode.Bertiebertila
@PranKumarSarkar, you can know if you are in test mode if razorpay doesn't ask you credentials of you internet banking(if you choose it). You will get two buttons like Success or Failure. You have the choice to make this transaction Successful or FailureGammon
@Gammon Yes, I am in test mode. From my understanding this error is shown because I am passing order_id in test mode. In live mode I have to pass order_id and it will not show any error. Please correct me if I am wrong.Bertiebertila
@PranKumarSarkar Removing order_id will work. but that is not the correct way. You will have to obtain Test order id from Razorpay. Removing Order id is like a trick to make it work but it is not the correct way. You will run into issues later.Gammon
@Gammon How to find test order id from razorpay? Is there a separate method to obtain that?Bertiebertila
@PranKumarSarkar Actually, my company provided it. I don't remember. I think it was the api key.Gammon
R
12

I also faced this error a week ago. This error arrived when we changed the test keys to the production keys for final payment to work.

So I faced this issue The id provided does not exist because of the mismatch of Razorpay Keys on the frontend and backend side(node.js side.)

So make sure you have the same client key and secret of the production environment on both backend and frontend side.

Let me know in comments if it still is not resolved.

Roca answered 9/7, 2019 at 15:5 Comment(3)
I have verified my keys both are same, but still get this error.Lorilee
this was exactly my issue. had forgotten to update the key id on the frontend.Once
I am facing this issue... I checked key_id and key_secret in front end and backend both are exactly same... still getting this error :( please helpPreter
R
2
  1. For Test Remove the OrderId from your options json data.
  2. For Live mode Pass the autogenerated Orderid From the user Control.
Rant answered 9/7, 2020 at 11:46 Comment(0)
A
1

Removing order_id is not good practice we should follow documentation. To get order_id in React you have to first create a order in your backend eg(node.js). follow this steps to get order_id from Razorpay.

Step - 1

var instance = new Razorpay({  key_id: 'YOUR_KEY_ID',  key_secret: 'YOUR_KEY_SECRET'})

this will initiate new Razorpay object.

Step - 2

MyOrder = instance.orders.create({amount, currency, receipt, notes})

this will create an order for you and then you have access to order_id. You can log MyOrder to see more available attributes or just console.log(MyOrder.id) to get order_id and finally you have to pass your order_id in your case you have to pass order_id in options.

Note : You can access order id like this MyOrder.id

for more information check official doc.

you can find Razorpay SDKs for various Platform here

Applause answered 1/6, 2021 at 15:42 Comment(0)
Z
1

I got a very fantastic solution of this error. there was a mismatch of key and key_id I resolved my error by replacing key_id with key in options object in Frontend Side.

Zygo answered 19/12, 2023 at 2:53 Comment(0)
K
0

If you are using for payments, than remove order_id from options JSON value.

 var options = {
        "key": "xxxxxxxxxxxxxxx", // Enter the Key ID generated from the Dashboard
        "amount": "50000", // Amount is in currency subunits. Default currency is INR. Hence, 50000 refers to 50000 paise
        "currency": "INR",
        "name": "Acme Corp",
        "description": "Test Transaction",
        "image": "https://example.com/your_logo",
        // "order_id": "order_9A33XWu170gUtm", //This is a sample Order ID. Pass the `id` obtained in the response of Step 1
        "handler": function (response){
            alert(response.razorpay_payment_id);
            alert(response.razorpay_order_id);
            alert(response.razorpay_signature)
        },
        "prefill": {
            "name": "Gaurav Kumar",
            "email": "[email protected]",
            "contact": "9999999999"
        },
        "notes": {
            "address": "Razorpay Corporate Office"
        },
        "theme": {
            "color": "#3399cc"
        }
    };
Kwh answered 22/6, 2021 at 10:5 Comment(0)
B
0

This error happens when you pass an incorrect order_id to trigger the payment modal. Basically an order_id that does not belong to your razorpay account, or an invalid one.

Example: if you generated an order_id with one set of credentials and use another set of credentials afterwards, this issue can happen.

Banksia answered 25/9, 2021 at 17:51 Comment(0)
P
0

I too faced the same problem while integrating Razorpay for subscription payments Initially, I passed order_id in the options param, which yielded the error -

{
  "code": "BAD_REQUEST_ERROR",
  "description": "The id provided does not exist",
  "source": "business",
  "step": "payment_initiation",
  "reason": "input_validation_failed",
  "metadata": {}
}

Hence replaced order_id with subscription_id.
Works now!

Pigpen answered 2/11, 2021 at 23:19 Comment(0)
L
0

Check for the rp_type, for subscription pass options["subscription_id"], for orders pass options["order_id"]

Lash answered 18/8, 2022 at 8:21 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.