This project demonstrates how to integrate Cashfree's payment gateway into a Flask web application. It includes functionality for creating orders, handling payments, and fetching order details.
- Create an order using Cashfree's API.
- Handle payments via Cashfree's modal checkout.
- Fetch order details to verify payment status.
- Redirect users to a "Thank You" page upon successful payment.
- Python 3.7 or higher
- Flask
- Cashfree sandbox/test credentials
- Internet connection to load the Cashfree SDK
-
Clone the repository:
git clone <repository-url> cd cf_flask
-
Create a virtual environment: python3 -m venv venv source venv/bin/activate
-
Install dependencies: pip install -r requirements.txt
-
Set up your Cashfree credentials: Replace the placeholders in app.py with your Cashfree x-client-id and x-client-secret.
-
Run the Flask application: python app.py or flask run
-
Open your browser and navigate to: http://127.0.0.1:5000/
cfflask/ ├── app.py # Main Flask application ├── templates/ │ ├── index.html # Main page with payment integration │ ├── thankyou.html # Thank You page after successful payment ├── static/ │ ├── css/ │ └── styles.css # Optional CSS for styling ├── requirements.txt # Python dependencies └── README.md # Project documentation
-
/create_order (POST)
- Creates a new order using Cashfree's API.
- Returns a payment_session_id for initiating the payment.
-
/get-order (GET)
- Fetches order details using the order_id. eg: GET /get-order?order_id=<order_id>
-
/thank-you (GET)
- Displays a "Thank You" page after successful payment.
-
Create Order:
- When the "Pay Now" button is clicked, a POST request is sent to /create_order.
- The server generates an order and returns a payment_session_id.
-
Payment Modal:
- The Cashfree SDK opens a modal for the user to complete the payment.
-
Verify Payment:
- After payment, the /get-order endpoint is called with the order_id to verify the payment status.
-
Thank You Page:
- If the payment is successful, the user is redirected to the /thank-you page.
The project uses the Cashfree SDK v3 for handling payments. The SDK is loaded via: <script src="https://sdk.cashfree.com/js/v3/cashfree.js"></script>
1. use below two variables to make the flow work.
CLIENT_ID
CLIENT_SECRET