Integrating Razorpay in FastAPI for Payment Processing

40 Views Asked by At

I am working on integrating Razorpay for payment processing in my FastAPI application. Currently, I have implemented an endpoint that creates a Razorpay order, and the response includes an order ID. However, I am facing issues when trying to test the payment process using Postman.

Here is the endpoint I am hitting:

POST https://api.razorpay.com/v1/payments

And here is the sample request body I am using:

{ "order_id": "order_NbIu1AqCESRuIu", "amount": 1000, "currency": "INR", "email": "[email protected]", "contact": "9123456780" }

Upon testing, I expected to receive a payment link, but instead, I received the following error:

{ "error": { "code": "BAD_REQUEST_ERROR", "description": "Your payment was not successful as you have entered invalid card details. To pay successfully, try adding the right details", "source": "customer", "step": "payment_initiation", "reason": "incorrect_card_details", "metadata": {} } }

I don't have a frontend for the payment procedure yet, and I want to ensure that my backend is functioning correctly. Could someone guide me on the required fields and their formats for the request body and headers to successfully initiate a payment using Razorpay?

Your assistance will be greatly appreciated!

Description of the Issue:

I have attempted to perform a payment using the Razorpay API for a specific order ID in my FastAPI application. Here's what I have done so far:

Endpoint Setup:
    I have implemented an endpoint in my FastAPI app that successfully creates a Razorpay order.
    The response from this endpoint includes an order ID.

Testing with Postman:
    To test the payment process, I used Postman to send a POST request to the Razorpay API endpoint (https://api.razorpay.com/v1/payments).
    The request body includes the necessary parameters such as order_id, amount, currency, email, and contact.

Expected Outcome:
    I expected to receive a payment link or a successful payment confirmation.

Actual Result:
    However, the response I received indicates a payment failure with the following error:

    json

    {
        "error": {
            "code": "BAD_REQUEST_ERROR",
            "description": "Your payment was not successful as you have entered invalid card details. To pay successfully, try adding the right details",
            "source": "customer",
            "step": "payment_initiation",
            "reason": "incorrect_card_details",
            "metadata": {}
        }
    }

Objective:

I am seeking guidance on the necessary fields and their formats for the request body and headers to successfully initiate a payment using the Razorpay API for a given order ID. My goal is to perform a payment transaction and ensure that my backend is functioning correctly.

Any assistance or insights regarding this issue would be highly appreciated. Thank you!

0

There are 0 best solutions below