snippe 0.1.0

Async Rust client for the Snippe payments API (Tanzania) — collections, hosted checkout sessions, disbursements, and verified webhooks.
Documentation
//! Create a mobile-money payment.
//!
//! Run with:
//! ```bash
//! SNIPPE_API_KEY=snp_test_xxx cargo run --example create_mobile_payment
//! ```

use snippe::models::common::Customer;
use snippe::models::payment::{CreatePaymentRequest, MobilePayment};
use snippe::{Client, IdempotencyKey};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let api_key = std::env::var("SNIPPE_API_KEY")
        .expect("set SNIPPE_API_KEY to a Snippe API key with collection:create scope");

    let client = Client::new(api_key)?;

    let request = CreatePaymentRequest::Mobile(
        MobilePayment::new(
            500,
            "255781000000",
            Customer::new("Jane", "Doe", "jane@example.com"),
        )
        .with_webhook_url("https://yoursite.com/webhooks/snippe"),
    );

    // Idempotency keys must be ≤ 30 bytes — IdempotencyKey::new enforces it.
    // Pick a stable key per logical request and reuse it on retries.
    let key = IdempotencyKey::new("ord-12345-att-1")?;

    let payment = client.payments().create(&request, Some(&key)).await?;

    println!("created payment {} (status: {:?})", payment.reference, payment.status);
    println!("expires at {}", payment.expires_at);
    Ok(())
}