M-Pesa API client for Daraja
This Python package is automatically generated by the Swagger Codegen project:
- API version: 1.0.0
- Package version: 1.0.0
- Build package: io.swagger.codegen.v3.generators.python.PythonClientCodegen
Python 2.7 and 3.4+
If the python package is hosted on Github, you can install directly from Github
pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git(you may need to run pip with root permission: sudo pip install git+https://github.com/GIT_USER_ID/GIT_REPO_ID.git)
Then import the package:
import mpesa_client Install via Setuptools.
python setup.py install --user(or sudo python setup.py install to install the package for all users)
Then import the package:
import mpesa_clientPlease follow the installation procedure and then run the following:
from __future__ import print_function
import time
import mpesa_client
from mpesa_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: bearerAuth
configuration = mpesa_client.Configuration()
configuration.api_key['Authorization'] = 'YOUR_API_KEY'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['Authorization'] = 'Bearer'
# create an instance of the API class
api_instance = mpesa_client.DisbursementApi(mpesa_client.ApiClient(configuration))
body = mpesa_client.B2CPaymentRequest() # B2CPaymentRequest |
try:
# Make a B2C Payment Request
api_response = api_instance.mpesa_b2c_v3_paymentrequest_post(body)
pprint(api_response)
except ApiException as e:
print("Exception when calling DisbursementApi->mpesa_b2c_v3_paymentrequest_post: %s\n" % e)All URIs are relative to https://sandbox.safaricom.co.ke
| Class | Method | HTTP request | Description |
|---|---|---|---|
| DisbursementApi | mpesa_b2c_v3_paymentrequest_post | POST /mpesa/b2c/v3/paymentrequest | Make a B2C Payment Request |
| ExperienceApi | mpesa_accountbalance_v1_query_post | POST /mpesa/accountbalance/v1/query | Make an Account Balance query |
| ExperienceApi | mpesa_reversal_v1_request_post | POST /mpesa/reversal/v1/request | Reverse an M-Pesa Transaction |
| ExperienceApi | mpesa_stkpushquery_v1_query_post | POST /mpesa/stkpushquery/v1/query | Query the status of a Lipa na M-Pesa Online Payment |
| ExperienceApi | mpesa_transactionstatus_v1_query_post | POST /mpesa/transactionstatus/v1/query | Query the Transaction Status of an M-Pesa Transaction |
| PaymentsApi | mpesa_b2b_v1_paymentrequest_post | POST /mpesa/b2b/v1/paymentrequest | Make a B2B Payment Request |
| PaymentsApi | mpesa_c2b_v1_simulate_post | POST /mpesa/c2b/v1/simulate | Simulate a C2B Payment |
| PaymentsApi | mpesa_c2b_v2_registerurl_post | POST /mpesa/c2b/v2/registerurl | Register C2B Confirmation and Validation URLs |
| PaymentsApi | mpesa_stkpush_v1_processrequest_post | POST /mpesa/stkpush/v1/processrequest | Initiate a Lipa na M-Pesa Online Payment |
| SecurityApi | oauth_v1_generate_get | GET /oauth/v1/generate | Generate an OAuth Access Token |
- AccountBalanceQueryRequest
- AccountBalanceQueryResponse
- B2BPaymentRequest
- B2BPaymentResponse
- B2CErrorResponse
- B2CPaymentRequest
- B2CPaymentResponse
- C2BPaymentSimulationRequest
- C2BPaymentSimulationResponse
- C2BURLRegistrationRequest
- C2BURLRegistrationResponse
- OAuthAccessTokenResponse
- StkPushQueryRequest
- StkPushQueryResponse
- StkPushRequest
- StkPushResponse
- TransactionReversalRequest
- TransactionReversalResponse
- TransactionStatusQueryRequest
- TransactionStatusQueryResponse
- Type: HTTP basic authentication
- Type: API key
- API key parameter name: Authorization
- Location: HTTP header