mpesa-rust
About
A Rust wrapper around the Safaricom API for accessing M-Pesa services.
Notes
Warning! WIP, not production ready
Install & Usage
Cargo.toml
[dependencies]
mpesa = "0.2.2"
In your lib or binary crate:
use Mpesa;
Usage
Creating a Client
You will first need to create an instance of the Mpesa instance (the client). You are required to provide a CLIENT_KEY and
CLIENT_SECRET. Here is how you can get these credentials for the Safaricom sandbox
environment.
NOTE: only calling unwrap for demonstration purposes. Errors are handled appropriately in the lib via the MpesaError enum.
There are two ways you can instantiate Mpesa:
use ;
use env;
let client = new;
assert!
Since the Environment enum implements FromStr, you can pass the name of the environment as a &str and call the parse()
method to create an Enviroment type from the string slice:
use Mpesa;
use env;
let client = new;
assert!
Services
The following services are currently available from the Mpesa client as methods that return builders:
- B2C
let response = client
.b2c
.parties
.urls
.amount
.send;
assert!
- B2B
let response = client
.b2b
.parties
.urls
.account_ref
.amount
.send;
assert!
- C2B Register
let response = client
.c2b_register
.short_code
.confirmation_url
.validation_url
.send;
assert!
- C2B Simulate
let response = client
.c2b_simulate
.short_code
.msisdn
.amount
.send;
assert!
- Account Balance
let response = client
.account_balance
.urls
.party_a
.send;
assert!
More will be added progressively, pull requests welcome
Author
Collins Muriuki
- Twitter: @collinsmuriuki_
- Not affiliated with Safaricom in any way
Contributing
Contributions, issues and feature requests are welcome!Feel free to check issues page. You can also take a look at the contributing guide.
Copyright © 2020 Collins Muriuki. This project is MIT licensed.