This easy to use library ensures seamless integration of the paypal sdk into the flask framework. (Invoices and subscriptions yet to be added.)
pip install flaskpaypallib
From flask import Flask,render_template
from flask_paypal_lib import Sandbox
app=Flask(__name__)
# The home route that displays the item to be bought.
@app.route("/")
def home_page():
return render_template("index.html")
# This is the implementation of the groundnut payment.
ground_nut=Sandbox(configuration of what you are selling)
# Initialize the app
ground_nut.init_app(app)
ground_nut.generate_access_token(client_id,client_secret_key)
ground_nut.create_route('ground_nut')
ground_nut.complete_process()
# Implementation of beans payment.
beans = Sandbox(configuration of what you are selling)
# initialize the app
beans.init_app(app)
beans.create_order_route('beans')
beans.complete_process()
This is for the the front. As easy as just adding the link.
home_page.html
<a href="https://www.sample.com/groundnut">Buy Now </a>
<a href="https://www.sample.com/beans"> Buy Now</a>
You can do that by:
Sandbox
Get a Paypal account Here
Create an App and get the client id and secret key from here ( You are getting it from the business account)
Live
Log into the Developer Dashboard with your merchant account.
On the My Apps & Credentials page, change to Live.
Click Create App in the REST API apps section.
Type a name for your app and click Create App.
Make a note of your REST API client ID and secret.
from flask_paypal_lib import Sandbox
Payer = Sandbox('USD',10, 'shirts', 6, 'nice shirts', 10, 20,2, 3, 7,2, 'CAPTURE', 'http://localhost:5000/okme','okme', 'http://localhost:5000')
Payer.init_app(app)
Payer.generate_access_token("client_id","client_secret_key")
Payer.create_order_route('shirts')
Payer.complete_process()
Payer = Sandbox('USD',10, 'shirts', 6, 'nice shirts', 10, 20,2, 3, 7,2, 'AUTHORIZE', 'http://localhost:5000/goods','goods', 'http://localhost:5000/cancel')
Payer.init_app(app)
Payer.generate_access_token("client_id","client_secret_key")
Payer.create_order_route('shirts')
Payer.complete_process()
N.B: any parameters you would not use such as the shipping_discount e.t.c pass in a "0"(zero).