-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Mpesa Express | ||
|
||
## Mpese Express Request | ||
|
||
Lipa na M-PESA online API also known as M-PESA express (STK Push/NI push) is a Merchant/Business initiated C2B (Customer to Business) Payment. | ||
|
||
Once you, our merchant integrate with the API, you will be able to send a payment prompt on the customer's phone (Popularly known as STK Push Prompt) to your customer's M-PESA registered phone number requesting them to enter their M-PESA pin to authorize and complete payment. | ||
|
||
Requires a `business_short_code` - The organization shortcode used to receive the transaction and | ||
returns a `MpesaExpressRequestBuilder` struct | ||
|
||
Safaricom API docs [reference](https://developer.safaricom.co.ke/APIs/MpesaExpressSimulate) | ||
|
||
### Example | ||
|
||
```rust,ignore | ||
use mpesa::{Mpesa, Environment}; | ||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>>{ | ||
dotenvy::dotenv().ok(); | ||
let client = Mpesa::new( | ||
dotenvy::var("CONSUMER_KEY").unwrap(), | ||
dotenvy::var("CONSUMER_SECRET").unwrap(), | ||
Environment::Sandbox, | ||
); | ||
let response = client | ||
.express_request() | ||
.business_short_code("174379") | ||
.phone_number("254708374149") | ||
.party_a("600584") | ||
.party_b("174379") | ||
.amount(500) | ||
.try_callback_url("https://test.example.com/api")? | ||
.account_ref("Test") | ||
.transaction_type(mpesa::CommandId::CustomerPayBillOnline) // Optional, defaults to `CommandId::CustomerPayBillOnline` | ||
.transaction_desc("Description") // Optional, defaults to "None" | ||
.build()? | ||
.send() | ||
.await; | ||
assert!(response.is_ok()); | ||
Ok(()) | ||
} | ||
``` | ||
|
||
## Mpesa Express Query | ||
|
||
M-PESA Express Query API checks the status of a Lipa Na M-PESA Online Payment. | ||
|
||
Safaricom API docs [reference](https://developer.safaricom.co.ke/APIs/MpesaExpressQuery) | ||
|
||
### Example | ||
|
||
```rust,ignore | ||
use mpesa::{Mpesa, Environment}; | ||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>>{ | ||
dotenvy::dotenv().ok(); | ||
let client = Mpesa::new( | ||
dotenvy::var("CLIENT_KEY").unwrap(), | ||
dotenvy::var("CLIENT_SECRET").unwrap(), | ||
Environment::Sandbox, | ||
); | ||
let response = client | ||
.express_query() | ||
.business_short_code("174379") | ||
.checkout_request_id("ws_CO_271120201234567891") | ||
.build()? | ||
.send() | ||
.await; | ||
assert!(response.is_ok()); | ||
Ok(()) | ||
} | ||
``` |