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;
500means 500 TZS, not 5.00. - Minimum amounts: 500 TZS for payments, 5,000 TZS for payouts.
- Phone numbers:
255XXXXXXXXXor+255XXXXXXXXX. Local formats like0781000000are rejected. - Idempotency keys must be ≤ 30 characters. This SDK enforces the
length at construction time via
IdempotencyKeyso the crypticPAY_001error from oversized keys can’t reach the API. - Webhook payloads have
data.amountas{value, currency}, not a plain integer like request bodies. Usewebhook::Verifierwhich models this correctly. - Always verify webhook signatures against the raw request bytes — parsing-then-re-serialising the JSON breaks the HMAC.
§Module overview
client— theClienttype and its builder.api— endpoint handles forapi::Payments,api::Sessions,api::Payouts.models— request and response types, organised by resource.webhook— HMAC-SHA256 verifier and typed event enums.error— theErrortype and theErrorCodeenum for programmatic dispatch.
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
Environmentenum. - 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
Resultalias used throughout the crate.