Create a simple purchase order using the PayPal REST api with a Flask application.
- A personal or business PayPal account.
- Have an application created in PayPal Developer to have access to client_id and secret_client credentials.
- Have Python installed.
This project was made with Python and the Flask micro framework, and consuming the PayPal REST api.
- Download the repository.
$ git clone https://github.com/Remy349/paypal-payments-flask
- Move to the repository and activate a Python virtual environment to install the necessary dependencies.
$ cd paypal-payments-flask
# It may be just python depending on how you installed Python on your computer.
$ python3 -m venv venv
# Linux
$ . venv/bin/activate
# Windows
$ venv\Scripts\activate
- Install the dependencies found in the requirements.txt file.
# It may be just "pip" depending on how you installed Python on your computer.
(venv) $ pip3 install -r requirements.txt
- Create an ".env" file in the root of the project to add your environment variables.
SECRET_KEY=ab07778a3653971df13e144d26315afb
# When in production use this "https://api-m.paypal.com".
PAYPAL_API_URL=https://api-m.sandbox.paypal.com
PAYPAL_CLIENT_ID=
PAYPAL_CLIENT_SECRET=
You get the credentials by creating an application in the PayPal Developer panel, log in with your personal or business PayPal account.
- Run the application and test purchase.
(venv) $ flask run
* Serving Flask app 'application.py'
* Running on http://127.0.0.1:5000 (Press CTRL+C to quit)