Skip to main content

Crate snippe

Crate snippe 

Source
Expand description

§Snippe Rust SDK

Async Rust client for Snippe, the payments API for Tanzania. The SDK targets the 2026-01-25 API version and supports:

  • Collections — mobile money (M-Pesa, Airtel, Mixx, Halotel), card payments via the hosted Selcom checkout, and dynamic QR codes.
  • Hosted sessions — pre-built checkout pages and short payment links for SMS / WhatsApp distribution.
  • Disbursements — payouts to mobile wallets and 25+ Tanzanian banks.
  • Webhooks — HMAC-SHA256 signature verification with replay protection and typed event dispatch.

§Quick start

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

let client = Client::new("snp_live_xxx")?;

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

let key = IdempotencyKey::new("ord-12345-att-1")?;
let payment = client.payments().create(&request, Some(&key)).await?;
println!("created payment {}", payment.reference);

§Critical rules

These will save you debugging time later — the API enforces them all server-side, but several have non-obvious failure modes:

  • Currency is TZS only. Amounts are integers in the smallest unit; 500 means 500 TZS, not 5.00.
  • Minimum amounts: 500 TZS for payments, 5,000 TZS for payouts.
  • Phone numbers: 255XXXXXXXXX or +255XXXXXXXXX. Local formats like 0781000000 are rejected.
  • Idempotency keys must be ≤ 30 characters. This SDK enforces the length at construction time via IdempotencyKey so the cryptic PAY_001 error from oversized keys can’t reach the API.
  • Webhook payloads have data.amount as {value, currency}, not a plain integer like request bodies. Use webhook::Verifier which models this correctly.
  • Always verify webhook signatures against the raw request bytes — parsing-then-re-serialising the JSON breaks the HMAC.

§Module overview

Re-exports§

pub use client::Client;
pub use client::ClientBuilder;
pub use config::Environment;
pub use error::ApiError;
pub use error::Error;
pub use error::ErrorCode;
pub use idempotency::IdempotencyKey;

Modules§

api
API endpoint handles, returned from the Client.
client
HTTP client for the Snippe API.
config
Client configuration constants and the Environment enum.
error
Error types returned by the SDK.
idempotency
Idempotency key validation.
models
Data models for the Snippe API — request payloads, response types, and the shared primitives (currency, money, customer, channel) referenced by all three resource families.
webhook
HMAC-SHA256 webhook signature verification and typed event dispatch.

Type Aliases§

Result
Convenient Result alias used throughout the crate.