[][src]Struct mpesa::Mpesa

pub struct Mpesa { /* fields omitted */ }

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]

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]

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]

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]

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]

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]

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

impl Debug for Mpesa[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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.