Logo Lanfrica

darthlotu5/mpesasync

Domaine:

digital infrastructure

Type de record:

software
Créateur:
dar
Hôte:
A fast async mpesa library # Mpesasync A asynchronous python library to the Mpesa Daraja API. Latest Release # Features This includes the following: 1. A python library to accept send and receive MPESA payments in less than 10 lines of code. 2. A sample implementation of the library in fast api. # Installation `$ pip install mpesasync` # Development * Create a virtual environment `python -m venv venv` * Activate your virtual environment `$source venv\bin\activate` or in windows `> venv\scripts\activate` * Install Poetry `pip install poetry` * Install project `poetry install` * Run tests `pytest` # Getting started To get started you need the following from the Mpesa Daraja Portal [STK PUSH] 1. Your consumer key. 2. Your consumer secret. 3. The business shortcode. [B2C/B2B] 5. Your organisation shortcode 6. Initiator name 7. Security credential 8. QueueTimeOutURL 9. Result url => This has to be a publicly accessible callback that mpesa will send transaction results to. For testing purposes, you can get test credentials here. On the sandbox portal, create an new app and use the provided credentials. # Using the library ## STK Push 1. Initialise and authenticate the STKPush sdk ```python from mpesasync import Mpesa, MpesaEnvironment from mpesasync.lipa_na_mpesa import STKPush import asyncio mpesa_app = STKPush( Environment=MpesaEnvironment.production, # use sandbox to authenticate with sandbox credentials BusinessShortCode=1234, CallBackURL="mydomain.com", PassKey="" # use the passkey obtained from the daraja portal ) coro = mpesa_app.authorize(consumer_key="YOUR CONSUMER KEY", consumer_secret="YOUR CONSUMER SECRET") loop = asyncio.get_event_loop() print(loop.run_until_complete(coro)) ``` 2. Send an STKPush prompt ```python coro = mpesa_app.stk_push( amount=1.0, phone_number="phone number" ) loop = asyncio.get_event_loop() print(loop.run_until_complete(coro)) ``` _The phone number can be any of +254XXXXXXXXX, 254XXXXXXXXX, 0XXXXXXXXX, the SDK will sanitise the phon …