Search code examples
firebasereact-nativegoogle-cloud-firestorerazorpay

How to create order_id on firebase for razorpay? I am using react-native with firebase for mobile application


I tried to provide uuid of users as order_id but then i read that it should be different every time. So, I tried to provide a random generated uuid as the order_id from my front end but then it only redirected to the payment page the first time and after that it threw an error: "id doesn't not exist" If somebody can help, Thank you in advance!

This is the document razorpay has provided for reference: https://razorpay.com/docs/payment-gateway/react-native-integration/standard/android/

But it would help if Creating order_id was explained in terms of react native.


Solution

  • Don't use UUID as an order id because it would not help you must have to generate an order from Razorpay API. in response that will send you a server-generated order id

    https://razorpay.com/docs/api/orders/#create-an-order

    fetch("https://api.razorpay.com/v1/orders", {
      method: "POST",
      headers: {
        Accept: "application/json",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        amount: 50000,
        currency: "INR",
      }),
    })
      .then((response) => response.json())
      .then((order) => console.log(order));
    

    in response the created order looks like

    {
      "id": "order_EKwxwAgItmmXdp",
      "entity": "order",
      "amount": 50000,
      "amount_paid": 0,
      "amount_due": 50000,
      "currency": "INR",
      "offer_id": null,
      "status": "created",
      "attempts": 0,
      "notes": [],
      "created_at": 1582628071
    }