Struct mpesa::Mpesa [−][src]
pub struct Mpesa { /* fields omitted */ }
Expand description
Mpesa client that will facilitate communication with the Safaricom API
Implementations
impl<'a> Mpesa
[src]
impl<'a> Mpesa
[src]pub fn new(
client_key: String,
client_secret: String,
environment: Environment
) -> Self
[src]
pub fn new(
client_key: String,
client_secret: String,
environment: Environment
) -> Self
[src]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 set_initiator_password(&self, initiator_password: &str)
[src]
pub fn set_initiator_password(&self, initiator_password: &str)
[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(), ); client.set_initiator_password("your_initiator_password");
pub fn is_connected(&self) -> bool
[src]
pub fn is_connected(&self) -> bool
[src]Checks if the client can be authenticated
pub fn b2c(&'a self, initiator_name: &'a str) -> B2cBuilder<'a>
[src]
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") .party_a("600496") .party_b("600000") .result_url("https://testdomain.com/err") .timeout_url("https://testdomain.com/ok") .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]
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") .party_a("600496") .party_b("600000") .result_url("https://testdomain.com/err") .timeout_url("https://testdomain.com/ok") .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]
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]
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]
pub fn account_balance(
&'a self,
initiator_name: &'a str
) -> AccountBalanceBuilder<'a>
[src]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") .result_url("https://testdomain.com/err") .timeout_url("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();
pub fn express_request(
&'a self,
business_short_code: &'a str
) -> MpesaExpressRequestBuilder<'a>
[src]
pub fn express_request(
&'a self,
business_short_code: &'a str
) -> MpesaExpressRequestBuilder<'a>
[src]Mpesa Express Request/ STK push Builder
Creates a MpesaExpressRequestBuilder
struct
Requires a business_short_code
- The organization shortcode used to receive the transaction
See more from the Safaricom API docs here
Example
let response = client .express_request("174379") .phone_number("254708374149") .party_a("254708374149") .party_b("174379") .amount(500) .callback_url("https://test.example.com/api") .transaction_type(CommandId::CustomerPayBillOnline) // Optional, defaults to `CommandId::CustomerPayBillOnline` .transaction_desc("Description") // Optional, defaults to "None" .send();
Trait Implementations
impl MpesaSecurity for Mpesa
[src]
impl MpesaSecurity for Mpesa
[src]fn gen_security_credentials(&self) -> MpesaResult<String>
[src]
fn gen_security_credentials(&self) -> MpesaResult<String>
[src]Generates security credentials M-Pesa Core authenticates a transaction by decrypting the security credentials. Security credentials are generated by encrypting the base64 encoded initiator password with M-Pesa’s public key, a X509 certificate. Returns base64 encoded string. Read more