Integrating Razorpay Payment Gateway with Python Flask – A Step-by-Step Guide

Posted by

Integrating Razorpay Payment Gateway with Python Flask

Integrating Razorpay Payment Gateway with Python Flask

If you are looking to integrate Razorpay’s payment gateway with your Python Flask web application, you’ve come to the right place. Razorpay’s APIs and SDKs make it easy to accept online payments in your web application, and integrating it with Flask is a straightforward process.

Step 1: Sign up for a Razorpay account

Before you can start integrating Razorpay’s payment gateway with your Python Flask application, you’ll need to sign up for a Razorpay account. Once you’ve signed up, you’ll be able to generate API keys that you’ll need to complete the integration process.

Step 2: Install the Razorpay Python SDK

To get started, you’ll need to install the Razorpay Python SDK. You can do this using pip, the Python package manager, by running the following command:

pip install razorpay

Step 3: Create a payment form in your Flask application

Next, you’ll need to create a payment form in your Flask application that allows users to enter their payment details and initiate a transaction. You can use HTML and Flask’s templating system to define the form and handle the payment request.

Step 4: Handle the payment request in your Flask application

Once the user submits the payment form, you’ll need to handle the payment request in your Flask application. This will involve using the Razorpay Python SDK to create a new payment order and retrieve a payment link that can be used to complete the transaction.


from flask import Flask, request
import razorpay

app = Flask(__name__)

razorpay_client = razorpay.Client(auth=("YOUR_KEY_ID", "YOUR_KEY_SECRET"))

@app.route('/create_payment', methods=['POST'])
def create_payment():
amount = request.form['amount']
data = {
'amount': amount,
'currency': 'INR',
'receipt': 'order_rcptid_11',
'payment_capture': 1
}
payment = razorpay_client.order.create(data=data)
return payment['short_url']

Step 5: Complete the payment on the Razorpay payment page

Finally, once you’ve generated the payment link in your Flask application, you can redirect the user to the Razorpay payment page where they can complete the transaction using their preferred payment method. Razorpay’s interface handles the entire payment process, and once the transaction is complete, the user will be redirected back to your Flask application.

By following these steps, you can easily integrate Razorpay’s payment gateway with your Python Flask web application and start accepting online payments from your users. With Razorpay’s powerful APIs and SDKs, you can provide a seamless and secure payment experience for your customers.

0 0 votes
Article Rating
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@mayankpal2010
10 months ago

Pls show how to change bank account in Razorpay