Struct mpesa::services::B2cBuilder
source · pub struct B2cBuilder<'mpesa, Env: ApiEnvironment> { /* private fields */ }
Expand description
B2C transaction builder struct
Implementations§
source§impl<'mpesa, Env: ApiEnvironment> B2cBuilder<'mpesa, Env>
impl<'mpesa, Env: ApiEnvironment> B2cBuilder<'mpesa, Env>
sourcepub fn new(
client: &'mpesa Mpesa<Env>,
initiator_name: &'mpesa str
) -> B2cBuilder<'mpesa, Env>
pub fn new( client: &'mpesa Mpesa<Env>, initiator_name: &'mpesa str ) -> B2cBuilder<'mpesa, Env>
Create a new B2C builder.
Requires an initiator_name
, the credential/ username used to authenticate the transaction request
sourcepub fn command_id(self, command_id: CommandId) -> B2cBuilder<'mpesa, Env>
pub fn command_id(self, command_id: CommandId) -> B2cBuilder<'mpesa, Env>
Adds the CommandId
. Defaults to CommandId::BusinessPayment
if not explicitly provided.
sourcepub fn party_a(self, party_a: &'mpesa str) -> B2cBuilder<'mpesa, Env>
pub fn party_a(self, party_a: &'mpesa str) -> B2cBuilder<'mpesa, Env>
Adds Party A
which is a required field
Party A
should be a paybill number.
Errors
If Party A
is invalid or not provided
sourcepub fn party_b(self, party_b: &'mpesa str) -> B2cBuilder<'mpesa, Env>
pub fn party_b(self, party_b: &'mpesa str) -> B2cBuilder<'mpesa, Env>
Adds Party B
which is a required field
Party B
should be a mobile number.
Errors
If Party B
is invalid or not provided
sourcepub fn parties(
self,
party_a: &'mpesa str,
party_b: &'mpesa str
) -> B2cBuilder<'mpesa, Env>
👎Deprecated
pub fn parties( self, party_a: &'mpesa str, party_b: &'mpesa str ) -> B2cBuilder<'mpesa, Env>
Adds Party A
and Party B
. Both are required fields
Party A
should be a paybill number while Party B
should be a mobile number.
Errors
If either Party A
or Party B
is invalid or not provided
sourcepub fn remarks(self, remarks: &'mpesa str) -> B2cBuilder<'mpesa, Env>
pub fn remarks(self, remarks: &'mpesa str) -> B2cBuilder<'mpesa, Env>
Adds Remarks
. This is an optional field, will default to “None” if not explicitly provided
sourcepub fn occasion(self, occasion: &'mpesa str) -> B2cBuilder<'mpesa, Env>
pub fn occasion(self, occasion: &'mpesa str) -> B2cBuilder<'mpesa, Env>
Adds Occasion
. This is an optional field, will default to an empty string
sourcepub fn amount<Number: Into<f64>>(
self,
amount: Number
) -> B2cBuilder<'mpesa, Env>
pub fn amount<Number: Into<f64>>( self, amount: Number ) -> B2cBuilder<'mpesa, Env>
Adds an amount
to the request
This is a required field
sourcepub fn timeout_url(self, timeout_url: &'mpesa str) -> B2cBuilder<'mpesa, Env>
pub fn timeout_url(self, timeout_url: &'mpesa str) -> B2cBuilder<'mpesa, Env>
Error
If QueueTimeoutUrl
is invalid or not provided
sourcepub fn result_url(self, result_url: &'mpesa str) -> B2cBuilder<'mpesa, Env>
pub fn result_url(self, result_url: &'mpesa str) -> B2cBuilder<'mpesa, Env>
Error
If ResultUrl
is invalid or not provided
sourcepub fn urls(
self,
timeout_url: &'mpesa str,
result_url: &'mpesa str
) -> B2cBuilder<'mpesa, Env>
👎Deprecated
pub fn urls( self, timeout_url: &'mpesa str, result_url: &'mpesa str ) -> B2cBuilder<'mpesa, Env>
Adds QueueTimeoutUrl
and ResultUrl
. This is a required field
Error
If either QueueTimeoutUrl
and ResultUrl
is invalid or not provided
sourcepub async fn send(self) -> MpesaResult<B2cResponse>
pub async fn send(self) -> MpesaResult<B2cResponse>
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 here
A successful request returns a B2cResponse
type
Errors
Returns a MpesaError
on failure.