jerrygeorge360 / flaskpaypallib

This easy to use library ensures seamless integration of the paypal sdk into the flask framework.
https://pypi.org/project/flaskpaypallib/0.0.2/
MIT License
3 stars 2 forks source link
flask payment-integration paypal-rest-api

flaskpaypallib

Description

This easy to use library ensures seamless integration of the paypal sdk into the flask framework. (Invoices and subscriptions yet to be added.)

Installing the flaskpaypallib.

pip install flaskpaypallib

Quick start

    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.

Prerequisites

You can do that by:


Sandbox

Live

Steps needed to make a payment

  1. Import the module.
  2. Create an instance of the class.
  3. Initialize the instance.
  4. Call the generate token method
  5. Call the create order route method
  6. Call the complete process method.
  7. Hoera!! you are done.

    Terms that you need to know.

    • 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.

To capture a payment.(sandbox)

    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()

To approve a payment.

    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()

Parameters

N.B: any parameters you would not use such as the shipping_discount e.t.c pass in a "0"(zero).