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 should have your client id and client secret key
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.
- Import the module.
- Create an instance of the class.
- Initialize the instance.
- Call the generate token method
- Call the create order route method
- Call the complete process method.
- Hoera!! you are done.
-
capture : Payment capture is the process to complete a credit or debit card purchase by capturing or settling the funds for the transaction. After the payment has been authorized, the capture request can be submitted by the payment gateway to the issuing bank either immediately or at a time of the merchant's choosing.
-
authorize : Card authorization is approval from a credit or debit card issuer (usually a bank or credit union) that states the cardholder has sufficient funds or the available credit needed to cover the cost of a transaction they're using a card to complete.
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()
- currency code
- item_unit_value
- item_name
- item_quantity
- item_description
- shipping_value
- handling_value
- tax_value
- insurance_value
- shipping_discount
- discount_value
- intent
- return_url
- return_url_endpoint
- cancel_url
- app (also supports app factory method.)
N.B: any parameters you would not use such as the shipping_discount e.t.c pass in a "0"(zero).