[−][src]Struct mpesa::Mpesa
Mpesa client that will facilitate communication with the Safaricom API
Implementations
impl<'a> Mpesa
[src]
pub fn new(
client_key: String,
client_secret: String,
environment: Environment
) -> Self
[src]
client_key: String,
client_secret: String,
environment: Environment
) -> Self
Constructs a new Mpesa
instance.
Example
let client: Mpesa = Mpesa::new( env::var("CLIENT_KEY").unwrap(), env::var("CLIENT_SECRET").unwrap(), "sandbox".parse().unwrap(), );
pub fn environment(&'a self) -> &Environment
[src]
Gets the current Environment
pub fn initiator_password(&'a self) -> &'a [u8]
[src]
Gets the initiator password as a byte slice
If None
, the default password is b"Safcom496!"
pub fn set_initiator_password(self, initiator_password: &str) -> Self
[src]
Optional in development but required for production, you will need to call this method and set your production initiator password. If in development, default initiator password is already pre-set
use mpesa::Mpesa; let client: Mpesa = Mpesa::new( env::var("CLIENT_KEY").unwrap(), env::var("CLIENT_SECRET").unwrap(), "sandbox".parse().unwrap(), ).set_initiator_password("your_initiator_password");
pub fn is_connected(&self) -> bool
[src]
Checks if the client can be authenticated
pub fn auth(&self) -> MpesaResult<String>
[src]
Safaricom Oauth
Generates an access token
Sends GET
request to Safaricom oauth to acquire token for token authentication
The OAuth access token expires after an hour, after which, you will need to generate another access token
See more from the Safaricom API docs here
Returns the auth token as a String
.
Errors
Returns a MpesaError
on failure
pub fn b2c(&'a self, initiator_name: &'a str) -> B2cBuilder<'a>
[src]
B2C Builder
Creates a B2cBuilder
for building a B2C transaction struct.
The builder is consumed and request made by calling its send
method.
See more from Safaricom the API docs here.
Requires an initiator_name
, the credential/ username used to authenticate the transaction request
Example
let response = client .b2c("testapi496") .parties("600496", "254708374149") .urls("https://testdomain.com/err", "https://testdomain.com/res") .amount(1000) .remarks("Your Remark") // optional, defaults to "None" .occasion("Your Occasion") // optional, defaults to "None" .command_id(mpesa::CommandId::BusinessPayment) // optional, defaults to `CommandId::BusinessPayment` .send();
pub fn b2b(&'a self, initiator_name: &'a str) -> B2bBuilder<'a>
[src]
B2B Builder
Creates a B2bBuilder
for building B2B transaction struct.
See more from the Safaricom API docs here
Requires an initiator_name
, the credential/ username used to authenticate the transaction request
Example
let response = client.b2b("testapi496") .parties("600496", "600000") .urls("https://testdomain.com/err", "https://testdomain.com/api") .account_ref("254708374149") .amount(1000) .command_id(mpesa::CommandId::BusinessToBusinessTransfer) // optional, defaults to `CommandId::BusinessToBusinessTransfer` .remarks("None") // optional, defaults to "None" .sender_id(mpesa::IdentifierTypes::ShortCode) // optional, defaults to `IdentifierTypes::ShortCode` .receiver_id(mpesa::IdentifierTypes::ShortCode) // optional, defaults to `IdentifierTypes::ShortCode` .send();
pub fn c2b_register(&'a self) -> C2bRegisterBuilder<'a>
[src]
C2B Register builder
Creates a C2bRegisterBuilder
for registering URLs to the 3rd party shortcode.
See more from the Safaricom API docs here
Example
let response = client .c2b_register() .short_code("600496") .confirmation_url("https://testdomain.com/true") .validation_url("https://testdomain.com/valid") .response_type(mpesa::ResponseTypes::Complete) // optional, defaults to `ResponseTypes::Complete` .send();
pub fn c2b_simulate(&'a self) -> C2bSimulateBuilder<'a>
[src]
C2B Simulate Builder
Creates a C2bSimulateBuilder
for simulating C2B transactions
See more here
Example
let response = client.c2b_simulate() .short_code("600496") .msisdn("254700000000") .amount(1000) .command_id(mpesa::CommandId::CustomerPayBillOnline) // optional, defaults to `CommandId::CustomerPayBillOnline` .bill_ref_number("Your_BillRefNumber>") // optional, defaults to "None" .send();
pub fn account_balance(
&'a self,
initiator_name: &'a str
) -> AccountBalanceBuilder<'a>
[src]
&'a self,
initiator_name: &'a str
) -> AccountBalanceBuilder<'a>
Account Balance Builder
Creates an AccountBalanceBuilder
for enquiring the balance on an MPESA BuyGoods.
Requires an initiator_name
.
See more from the Safaricom API docs here
Example
let response = client .account_balance("testapi496") .urls("https://testdomain.com/err", "https://testdomain.com/ok") .party_a("600496") .command_id(mpesa::CommandId::AccountBalance) // optional, defaults to `CommandId::AccountBalance` .identifier_type(mpesa::IdentifierTypes::ShortCode) // optional, defaults to `IdentifierTypes::ShortCode` .remarks("Your Remarks") // optional, defaults to "None" .send();
Trait Implementations
impl Debug for Mpesa
[src]
impl MpesaSecurity for Mpesa
[src]
pub fn gen_security_credentials(&self) -> MpesaResult<String>
[src]
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,
pub 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.
pub 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>,