This is an async rust library for accessing the mpesa apis.
To get an access token
use ;
use ;
async
Making a request
An Example of a Mpesa Express (STK Push) request:
let config = new.with_access_token;
/// Create a client to make requests with default config or you can provide your own check the docs for more info
let client = with_config;
/// all fields must be provided as strings
let request = default
.PartyA
.PartyB
.Amount
.Password
.AccountReference
.TransactionType
.BusinessShortCode
.CallbackURL
.TransactionDesc
.Timestamp
.PhoneNumber
.build
.unwrap;
let response = client
///the appropriate method is required for the respective api you are trying to access.
.stkpush
.create
.await
.unwrap;
println!;
Methods to make requests to the mpesa api
To access different request use the following methods to access the apis mpesa provides.
- Account Balance
Default
- B2B Express
Default
- B2C Account Top Up
Default
- B2C
Default
- Business Buy Goods
Default
- Payment and Reconciliation
Default
- Bill Manager Onboarding Generic API
Default
- Updating Optin Details
Default
- Business PayBill
Default
- Cancel Single Invoicing
Default
- Mpesa Express Query
Default
- QR code
Default
- Mpesa Ratiba
Default
- Reverse Transaction
Default
- Mpesa Express (STK Push)
Default
- Transaction Status
Default
- Tax Remit
Default
Note you can override the default configs eg. The Mpesa API urls. You can do this by using the
.with_access_token
.with_api_url
.with_environment
functions when creating the client to override the default behaviour and switch url or switch url environments by specifying the environment, by passing this enum to the with_environment function.