Welcome to the Flask PayPal Payments API! This project provides a robust RESTful API built with Flask for handling PayPal payments. Whether you're integrating PayPal payments into your e-commerce platform, donation portal, or any other application, this API serves as a reliable backend solution.
PayPal is one of the most popular payment gateways worldwide, offering secure and convenient online transactions. Integrating PayPal into your application can enhance user experience and streamline payment processes. However, building a robust payment system from scratch can be complex and time-consuming. That's where the Flask PayPal Payments API comes in.
This API simplifies the integration of PayPal payments into your Flask application. It abstracts away the complexity of PayPal's API and provides a clean, easy-to-use interface for initiating, executing, and managing payments. Whether you're a seasoned developer or just starting with Flask, this API makes PayPal integration a breeze.
- Integrate PayPal payments into your Flask application with minimal effort.
- Abstracts away the intricacies of PayPal's API, allowing you to focus on your application logic.
- Easily configure payment details such as currency, amount, and description.
- Adapt the API to suit various use cases, including e-commerce, donations, subscriptions, and more.
- Implements OAuth 2.0 authentication for secure communication with PayPal's servers.
- Ensures the confidentiality and integrity of payment transactions.
- Well-documented endpoints and usage examples for easy integration.
- Clear explanations of API functionality and best practices for developers.
Getting started with the Flask PayPal Payments API is straightforward. Follow these steps to set up the project:
-
Clone the Repository:
git clone https://github.com/munuhee/paypal-payment-service.git cd paypal-payment-service
-
Install Dependencies:
pip install -r requirements.txt
-
Set Environment Variables: Create a
.env
file in the project root and add the following variables:PAYPAL_CLIENT_ID=your_paypal_client_id PAYPAL_CLIENT_SECRET=your_paypal_client_secret
-
Run the Application:
python run.py
-
Access the API: The API will be available at
http://localhost:5000
.
Once the API is up and running, you can start using it to handle PayPal payments in your application. Here's a basic example of how to initiate a payment using cURL:
curl -X POST http://localhost:5000/payments \
-H "Content-Type: application/json" \
-d '{"amount": 10.0, "currency": "USD", "description": "Sample payment"}'
For more detailed usage instructions and examples, refer to the Endpoints section below.
The Flask PayPal Payments API provides the following endpoints for interacting with PayPal:
- URL:
/payments
- Method:
POST
- Description: Initiates a PayPal payment with the specified amount, currency, and description.
- Request Body:
{ "amount": 10.0, "currency": "USD", "description": "Sample payment description" }
- Response:
{ "approval_url": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-123456789" }
- URL:
/payments/execute?paymentId={paymentId}&PayerID={PayerID}
- Method:
POST
- Description: Executes a PayPal payment after user approval.
- Response:
{ "message": "Payment successful", "payment": { "id": "PAY-123456789", "state": "approved", ... } }
- URL:
/payments/cancel
- Method:
GET
- Description: Handles payment cancellation.
- Response:
{ "message": "Payment cancelled by user" }
For more information on each endpoint, including request parameters and response formats, consult the API documentation or the source code.
Contributions are welcome! Whether you're fixing a bug, adding a feature, or improving documentation, your contributions help make this project better for everyone. To contribute, simply fork the repository, make your changes, and submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.