This project demonstrates how to integrate PayPal Checkout with a Flask web application. The application displays a list of products, and when a user selects a product, the PayPal Checkout button allows them to make a purchase.
- Python 3.x
- Virtualenv
-
Clone the repository:
https://github.com/Orrv2904/Flask-Paypal-Integration.git cd Flask-Paypal-Integration code .
-
Create a virtual environment:
virtualenv venv
or
python3 -m venv venv
-
Activate the virtual environment:
-
On Windows:
venv\Scripts\activate
-
On macOS and Linux:
source venv/bin/activate
-
-
Install the requirements:
pip install -r requirements.txt
Replace the placeholder in .env
with your own PostgreSQL database connection string:
DATABASE_URL=your_postgresql_connection_string
-
Create tables in the database:
python -m create
-
Add data to the products table, you can do it from the database manager.
-
Run the application:
flask run
The application should be running at http://127.0.0.1:5000/.
The PayPal integration is implemented in the index.html
file. It fetches product information from the server and uses the PayPal SDK to create a checkout button.
Ensure you have a PayPal Sandbox account, and replace client-id
in the script tag with your own PayPal client ID.
<script src="https://www.paypal.com/sdk/js?client-id=your_paypal_client_id¤cy=USD"></script>
-
Visit http://127.0.0.1:5000/ in your browser.
-
Select a product to view its details.
-
Click the PayPal Checkout button to initiate the payment process.
-
Complete the payment on the PayPal sandbox.
This project is licensed under the MIT License - see the LICENSE file for details.