Logo Lanfrica

martinmogusu/django-daraja

Domaine:

digital infrastructure

Type de record:

software
Créateur:
mar
Hôte:
A python django library for interacting with the MPESA Daraja API # django-daraja This is a django library based on the Safaricom MPESA daraja API. This is a django library based on the Safaricom MPESA daraja API. Use it for a simplified experience, spend less time setting up... Read the full documentation at django-daraja.readthedocs.io MPESA Daraja API documentation can be found at developer.safaricom.co.ke ## Installation To install the package, run ``` $ pip install django_daraja ``` ## Examples ### STK Push An example, to send an STK push prompt to customer phone, then display response message ```python from django_daraja.mpesa.core import MpesaClient def index(request): cl = MpesaClient() phone_number = '0700111222' amount = 1 account_reference = 'reference' transaction_desc = 'Description' callback_url = 'api.darajambili.com' response = cl.stk_push(phone_number, amount, account_reference, transaction_desc, callback_url) return HttpResponse(response) ``` On your browser, you will receive a message `Success. Request accepted for processing` on success of the STK push, and on the phone number specified you will receive an MPESA PIN prompt. Once the transaction is complete, you will receive a notification on the callback URL you provided. If you used the exact callback URL in the example above (i.e. api.darajambili.com), you can head over to darajambili.com to view the notification received ### B2C Payment An example, to perform a BusinessPayment B2C (Business to Customer) transaction ```python from django_daraja.mpesa.core import MpesaClient def index(request): cl = MpesaClient() phone_number = '0700111222' amount = 1 transaction_desc = 'Business Payment Description' occassion = 'Test business payment occassion' callback_url = 'api.darajambili.com' response = cl.business_payment(phone_number, amount, transaction_desc, callback_url, occassion) return HttpResponse(response) ``` On your browser, you will receive a me …