GithubHelp home page GithubHelp logo

nobeint / pesapal-py Goto Github PK

View Code? Open in Web Editor NEW

This project forked from twais/pesapal-py

0.0 0.0 0.0 37 KB

A python lib that integrates with PesaPal's API 3.0 - JSON APIs

License: MIT License

Python 100.00%

pesapal-py's Introduction

pesapal-py

A minimalist python library that integrates with PesaPal's API 3.0 - JSON APIs (https://developer.pesapal.com/how-to-integrate/e-commerce/api-30-json/api-reference).

This library abstracts PesaPals API 3.0 into four main methods, authenticate, register_ipn, transact and get_transaction_status

Getting started

Register as a merchant

  1. Register as a PesaPal merchant at https://www.pesapal.com/
  2. On successfull registration, you will receive a consumer key and consumer secret via email - keep these safe as they are your API credentials

Install pesapal-py

pip install pesapal-py

Authenticating

from pesapal_py.payments import PesaPal

pesapal = PesaPal("test_consumer_key", "test_consumer_secret")
auth = pesapal.authenticate()
print(auth)

This step returns a bearer token that is used with all the other methods below. The token expires after every 5 minutes. To prevent calling this method every time you need to transact, I recommend that you store it in an in-memory data store (e.g. redis) and expire it before 5 minutes.

Register IPN

register_ipn = pesapal.register_ipn("sample_token", "https://www.sample-url.com/ipn")
print(register_ipn)

Transact

transact = pesapal.transact(
    token="sample_token",
    description="sample_description",
    transaction_id="sample_transaction_id",
    amount=1000,
    callback_url="https://www.callback-url.com/status",
    ipn_id="sample_ipn_id",
    email_address="[email protected]",
    phone_number="254722001122",
    country_code="KE",
    first_name="first",
    last_name="last",
    currency="KES",
)
print(transact)

Validate Transaction

transaction_status = pesapal.get_transaction_status(
    token="sample_token", order_tracking_id="sample_order_tracking_id"
)
print(transaction_status)

pesapal-py's People

Contributors

twais avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.