Skip to content

Latest commit

 

History

History
40 lines (31 loc) · 857 Bytes

dynamic_qr.md

File metadata and controls

40 lines (31 loc) · 857 Bytes

Dynamic QR

Generates a QR code that can be scanned by a M-Pesa customer to make payments.

Returns a DynamicQRBuilder

Safaricom API docs reference

Example

use mpesa::{Mpesa, Environment};

#[tokio::main]
async fn main() {
    dotenvy::dotenv().ok();

    let client = Mpesa::new(
        dotenvy::var("CONSUMER_KEY").unwrap(),
        dotenvy::var("CONSUMER_SECRET").unwrap(),
        Environment::Sandbox,
    );

    let response = client
        .dynamic_qr()
        .amount(2000)
        .credit_party_identifier("373132")
        .merchant_name("TEST SUPERMARKET")
        .ref_no("Invoice Test")
        .size("300")
        .transaction_type(mpesa::TransactionType::BG)
        .build()
        .unwrap()
        .send()
        .await;

    assert!(response.is_ok())
}