daraja 0.1.2
daraja: ^0.1.2 copied to clipboard
M-Pesa STK Push and B2C disbursements for Flutter — initiation, real-time callback delivery, timeout handling, and killed-app recovery. Backed by Appwrite.
Changelog #
0.1.2 — 2026-05-11 #
- Fixed B2C API endpoint (
/v3/→/v1/). - Added
Daraja.restorePendingDisbursement()for killed-app recovery on B2C — mirrorsrestorePendingPayment(). - Added
Daraja.disbursementStreamfor a global B2C state listener, consistent withDaraja.streamfor STK Push. - B2C lifecycle (Realtime subscription, polling at T+15s/T+45s/T+75s, T+90s timeout, SharedPreferences persistence) extracted into
DisbursementNotifier. - Added
==andhashCodeto allPaymentStateandDisbursementStatesubclasses. - Replaced null-bang env var access in the Appwrite Function with a throwing
_env()helper.
0.1.1 — 2026-04-06 #
- Added dartdoc comments across all public API elements (exceeds pub.dev 20% threshold).
- Added
example/lib/main.dartminimal Flutter example for pub.dev scoring. - Added B2C disbursement support:
Daraja.b2cPush(),DisbursementStatesealed class,B2cCommandId,SecurityCredential.
0.1.0 — 2026-03-31 #
Initial release.
Core package
Daraja— public entry point.stkPush()returns aStream<PaymentState>that closes on terminal state.restorePendingPayment()recovers any session killed before the payment resolved.DarajaConfig— typed config withDarajaEnvironment.sandbox/productiontoggle.PaymentState— sealed class with 8 states:PaymentIdle,PaymentInitiating,PaymentPending,PaymentSuccess,PaymentFailed,PaymentCancelled,PaymentTimeout,PaymentError.DarajaClient— direct HTTP to Safaricom. OAuth with in-memory token cache (60-second buffer). EAT password generation. Phone normalisation for all six Kenyan formats.PaymentSubscription— Appwrite Realtime subscription on a single document channel. Database poll fallback on reconnection.PaymentNotifier— orchestrates the full flow.WidgetsBindingObserverfor foreground-resume polling. Timeout cascade at T+10, T+30, T+70 seconds. Hard cutoff at T+90 →PaymentTimeout.SharedPreferencespersistence for killed-app recovery.
Appwrite Function (function/)
- Dart runtime callback handler. Parses Safaricom STK Push callback, writes result document to Appwrite Database. Uses
documentId = checkoutRequestIdfor idempotent duplicate handling. ReturnsResultCode: 0unconditionally so Safaricom stops retrying.
Demo (example/chama/)
- Split-bill chama app demonstrating concurrent per-member payments, shared pot aggregation, all terminal state variants, and killed-app recovery.