[−][src]Struct mpesa::Mpesa
Mpesa client that will facilitate communication with the Safaricom API
Implementations
impl Mpesa
[src]
pub fn new(
client_key: String,
client_secret: String,
environment: Environment,
initiator_password: String
) -> Self
[src]
client_key: String,
client_secret: String,
environment: Environment,
initiator_password: String
) -> Self
Constructs a new Mpesa
instance.
pub fn b2c(
&self,
initiator_name: &str,
command_id: CommandId,
amount: u32,
party_a: &str,
party_b: &str,
remarks: &str,
queue_timeout_url: &str,
result_url: &str,
occasion: &str
) -> Result<B2cResponse, Box<dyn Error>>
[src]
&self,
initiator_name: &str,
command_id: CommandId,
amount: u32,
party_a: &str,
party_b: &str,
remarks: &str,
queue_timeout_url: &str,
result_url: &str,
occasion: &str
) -> Result<B2cResponse, Box<dyn Error>>
B2C API
Sends b2c payment request.
This API enables Business to Customer (B2C) transactions between a company and customers who are the end-users of its products or services. Use of this API requires a valid and verified B2C M-Pesa Short code. See more at: https://developer.safaricom.co.ke/docs?shell#b2c-api
Example
dotenv::dotenv().ok(); let client = mpesa::Mpesa::new( std::env::var("CLIENT_KEY").unwrap(), std::env::var("CLIENT_SECRET").unwrap(), mpesa::Environment::Sandbox, std::env::var("INIT_PASSWORD").unwrap(), ); let response = client.b2c( "testapi496", mpesa::CommandId::BusinessPayment, 1000, "600496", "254708374149", "gg", "https://muriuki.dev/api/a", "https://muriuki.dev/api/b", "Test", ).unwrap();
Errors
TODO
pub fn b2b(
&self,
initiator_name: &str,
command_id: CommandId,
amount: u32,
party_a: &str,
sender_id: u32,
party_b: &str,
receiver_id: u32,
remarks: &str,
queue_timeout_url: &str,
result_url: &str,
account_ref: &str
) -> Result<B2bResponse, Box<dyn Error>>
[src]
&self,
initiator_name: &str,
command_id: CommandId,
amount: u32,
party_a: &str,
sender_id: u32,
party_b: &str,
receiver_id: u32,
remarks: &str,
queue_timeout_url: &str,
result_url: &str,
account_ref: &str
) -> Result<B2bResponse, Box<dyn Error>>
B2B API
Sends b2b payment request.
This API enables Business to Business (B2B) transactions between a business and another business. Use of this API requires a valid and verified B2B M-Pesa short code for the business initiating the transaction and the both businesses involved in the transaction See more at https://developer.safaricom.co.ke/docs?shell#b2b-api
Example
dotenv::dotenv().ok(); let client = mpesa::Mpesa::new( std::env::var("CLIENT_KEY").unwrap(), std::env::var("CLIENT_SECRET").unwrap(), mpesa::Environment::Sandbox, std::env::var("INIT_PASSWORD").unwrap(), ); let b2b_response = client.b2b( "testapi496", mpesa::CommandId::BusinessToBusinessTransfer, 1000, "600496", 4, "600000", 4, "gg", "https://muriuki.dev/api/a", "https://muriuki.dev/api/b", "254708374149", ).unwrap();
Errors
TODO
pub fn c2b_register(
&self,
validation_url: &str,
confirmation_url: &str,
response_type: ResponseType,
short_code: &str
) -> Result<Response, Box<dyn Error>>
[src]
&self,
validation_url: &str,
confirmation_url: &str,
response_type: ResponseType,
short_code: &str
) -> Result<Response, Box<dyn Error>>
Registers the the 3rd party’s confirmation and validation URLs to M-Pesa
Registering maps these URLs to the 3rd party shortcode. Whenever M-Pesa receives a transaction on the shortcode, M-Pesa triggers a validation request against the validation URL and the 3rd party system responds to M-Pesa with a validation response (either a success or an error code). The response expected is the success code the 3rd party
Example
dotenv::dotenv().ok(); let client = mpesa::Mpesa::new( std::env::var("CLIENT_KEY").unwrap(), std::env::var("CLIENT_SECRET").unwrap(), mpesa::Environment::Sandbox, std::env::var("INIT_PASSWORD").unwrap(), ); let c2b_register_response = client.c2b_register( "https://muriuki.dev/api", "https://muriuki.dev/verify", mpesa::ResponseType::Complete, "600496" ).unwrap();
Errors
TODO
pub fn c2b_simulate(
&self,
command_id: CommandId,
amount: u32,
msisdn: &str,
bill_ref_number: &str,
short_code: &str
) -> Result<C2bSimulateResponse, Box<dyn Error>>
[src]
&self,
command_id: CommandId,
amount: u32,
msisdn: &str,
bill_ref_number: &str,
short_code: &str
) -> Result<C2bSimulateResponse, Box<dyn Error>>
Make payment requests from Client to Business
This enables you to receive the payment requests in real time. See more here: https://developer.safaricom.co.ke/c2b/apis/post/simulate
Example
dotenv::dotenv().ok(); let client = mpesa::Mpesa::new( std::env::var("CLIENT_KEY").unwrap(), std::env::var("CLIENT_SECRET").unwrap(), mpesa::Environment::Sandbox, std::env::var("INIT_PASSWORD").unwrap(), ); let c2b_simulate_response = client.c2b_simulate( mpesa::CommandId::CustomerPayBillOnline, 1, "254705583540", "123abc", "600496" ).unwrap();
Errors
TODO
pub fn account_balance(
&self,
party_a: &str,
remarks: &str,
initiator_name: &str,
queue_timeout_url: &str,
result_url: &str
) -> Result<AccountBalanceResponse, Box<dyn Error>>
[src]
&self,
party_a: &str,
remarks: &str,
initiator_name: &str,
queue_timeout_url: &str,
result_url: &str
) -> Result<AccountBalanceResponse, Box<dyn Error>>
Enquire the balance on an M-Pesa BuyGoods (Till Number).
Example
dotenv::dotenv().ok(); let client = mpesa::Mpesa::new( std::env::var("CLIENT_KEY").unwrap(), std::env::var("CLIENT_SECRET").unwrap(), mpesa::Environment::Sandbox, std::env::var("INIT_PASSWORD").unwrap(), ); let account_balance_response = client.account_balance( "600496", "none", "collins", "https://hell.world/api", "https://hello.world/api" ).unwrap();
Errors
TODO
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Mpesa
impl Send for Mpesa
impl Sync for Mpesa
impl Unpin for Mpesa
impl UnwindSafe for Mpesa
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,