Skip to main content

Python wrapper for Mpesa's Daraja API

Project description

pydaraja

PyPI version Wheel Status License: MIT

Description

This Python wrapper allows developers to seamlessly interact with the MPESA's Daraja API and manage payment requests within their Python applications.

It streamlines and abstracts the complexity of integrating with the MPESA's Daraja API, providing developers with a convenient and efficient means of handling payment transactions

Daraja API services offered by pydaraja are:

  • Lipa na M-PESA online API also known as M-PESA express (STK Push/NI push)
  • STK push query API -> Used to check the status of Lipa na Mpesa online payment

More services will come soon.

Installation

pip install -U pydaraja

Usage

  1. Lipa na Mpesa Online API (STK push) and STK push query API.
from pydaraja import MpesaPaymentGateway

# Create MpesaPaymentGateway instance
mpesa = MpesaPaymentGateway(
    consumer_key="consumer_key",
    consumer_secret="consumer_secret",
    business_shortcode="business_shortcode",
    passkey="passkey"
    endpoint="https://sandbox.safaricom.co.ke",
)

# Trigger STK push prompt
response = mpesa.trigger_stk_push(phone_number="+254700000000", amount=1, callback_url="https://example.com")

print(response.json())
# Output
{
    'MerchantRequestID': '2654-4b64-97ff-b827b542881d164797',
    'CheckoutRequestID': 'ws_CO_18072024175449513769356298',
    'ResponseCode': '0',
    'ResponseDescription': 'Success. Request accepted for processing',
    'CustomerMessage': 'Success. Request accepted for processing'
}


# use checkout_request_id from the above stk push as parameter for the function below
response = mpesa.query_stk_push(checkout_request_id=your_checkout_request_id)

print(response.json())
# Output
{
    'ResponseCode': '0',
    'ResponseDescription': 'The service request has been accepted successsfully',
    'MerchantRequestID': '2654-4b64-97ff-b827b542881d164797',
    'CheckoutRequestID': 'ws_CO_18072024175449513769356298',
    'ResultCode': '0',
    'ResultDesc': 'The service request is processed successfully.'
 }

Contributing

To contribute to this project, we kindly request you to review the CONTRIBUTING.md file for detailed guidelines.

License

This python package is available as open source under the terms of the MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydaraja-0.3.7.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydaraja-0.3.7-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file pydaraja-0.3.7.tar.gz.

File metadata

  • Download URL: pydaraja-0.3.7.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for pydaraja-0.3.7.tar.gz
Algorithm Hash digest
SHA256 79b2a344827cf9f06eb5f9051aae7e643add04c610da978aeb5421ac30fd0232
MD5 e0192fc0252248e130105032c1407c7e
BLAKE2b-256 305e1a7f9ff1d6b5f73799f59cb8357041db30800b63660ce88df269f82546db

See more details on using hashes here.

File details

Details for the file pydaraja-0.3.7-py3-none-any.whl.

File metadata

  • Download URL: pydaraja-0.3.7-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for pydaraja-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 b11243b81c7fbf3909c1ead4dbea7fffbcea995aa6146729cf8376cd1c05ec00
MD5 e5be535fec06ef4449751cfb146db322
BLAKE2b-256 1f697020ac7f8e64dc69536ee07129596d48ead5bf928fcc579259640428e2f3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page