async_mpesa/lib.rs
1//! # async-mpesa
2//!
3//! The `async-mpesa` crate provides a convenient way to access
4//! the mpesa api.
5//!
6//! The client used to call the apis is asynchronous.
7//!
8//! ## Making a request
9//!
10//! You first need to configure the client by providing the api url and key
11//! by default the client is configured to use the correct url so providing your
12//! own will be unnecessary.
13//!
14//! The access token if not provided is sourced in the `MPESA_ACCESS_TOKEN` environment variable that
15//! you will need to set manually.
16//! ```rust
17//! let config = MpesaConfig::new()
18//! .with_access_token(access_token)
19//! .with_api_url(api_url);
20//! ```
21//!
22//! A client is needed to make requests and can be used to
23//! create multiple requests.
24//! ```rust
25//! let client = Client::with_config(config);
26//! ```
27//!
28//! Next to create a request you need to use the specific builder method
29//! for the api you are trying to access, here is an example for the stk
30//! push api which is called by the `ExpressPushRequestArgs::default`
31//! method.
32//!
33//! ```rust
34//! let request = ExpressPushRequestArgs::default()
35//! .PartyA("")
36//! .PartyB("")
37//! .Amount("")
38//! .Password(shortcode, passkey, timestamp)
39//! .AccountReference("")
40//! .TransactionType("")
41//! .BusinessShortCode("")
42//! .CallbackURL("")
43//! .TransactionDesc("")
44//! .Timestamp("")
45//! .PhoneNumber("")
46//! .build()
47//! .unwrap();
48//! ```
49//! To make a request and get a response you also need the specific method for the
50//! builder method used.
51//!
52//! The response is deserialized into a response struct and if it fails it is deserialized
53//! into the error struct using the fields names specified in the mpesa docs.
54//!
55//! ```rust
56//! let response = client
57//! .stkpush()
58//! .create(request)
59//! .await
60//! .unwrap();
61//!
62//! println!("{:?}", response);
63//!```
64
65
66
67pub mod config;
68pub mod types;
69pub mod error;
70mod client;
71mod accountbalance;
72mod b2c;
73mod b2bexpress;
74mod b2ctopup;
75mod bill_reconciliation;
76mod billupdate;
77mod billmanager;
78mod cancelinvoice;
79mod expressquery;
80mod stkpush;
81mod qr;
82mod ratiba;
83mod reversal;
84mod singleinvoice;
85mod tax;
86mod transactionstatus;
87mod bbuygoods;
88mod bpaybill;
89
90pub use client::Client;
91pub use accountbalance::AccountBalance;
92pub use b2c::B2C;
93pub use expressquery::ExpressQuery;
94pub use stkpush::STKPush;
95pub use qr::Qr;
96pub use reversal::Reversal;
97pub use singleinvoice::SingleInvoice;
98pub use tax::Tax;
99pub use transactionstatus::TransactionStatus;
100pub use bbuygoods::Bbuygoods;
101pub use bpaybill::Bpaybill;