M-Pesa payments,
engineered for TypeScript.

Stop hand-crafting PascalCase payloads, wrestling EAT timestamp drift, and managing OAuth tokens manually. @lumierelabs/daraja provides strict end-to-end types, client-side pre-flight validation, and native edge compatibility with zero dependencies.

>_pnpm add @lumierelabs/daraja
Explore Documentation
No runtime dependenciesFully typed payloadsServer & Edge ready
Architectural Solutions

Daraja is straightforward.
Integrating it cleanly isn't.

The hard part of an M-Pesa integration is rarely calling the API endpoints. It's managing token lifecycles, timezone drift, callback parsing, validation, and multi-runtime compatibility.

01

Automated OAuth 2.0 Token Lifecycle

Eliminates manual Basic auth encoding, credential fetching, and race conditions. Manages token rotation with a proactive 60-second safety buffer to prevent mid-flight 401s.

02

EAT Timezone & Hashing Correction

Automatically synchronizes timestamps to East Africa Time (UTC+3) and handles Base64 shortcode derivation, eliminating silent STK Push rejections from time drift.

03

Webhook ResultParameter Flattening

Transforms nested Daraja callback arrays and string-encoded booleans into strongly typed domain models with discriminated union states.

04

Client-Side Pre-Flight Validation

Validates payload structures, callback URLs, and phone prefixes locally before network dispatch, cutting out sandbox trial-and-error.

05

Edge-First Web Standards Core

Built strictly on native fetch and AbortController without Node.js core locks. Runs seamlessly on Vercel Edge, Cloudflare Workers, Deno, and Bun.

06

Native Timeout & Cancellation Control

Protects server resources during upstream sandbox degradation with built-in AbortSignal support, preventing hanging requests.

07

Zero-Dependency Footprint

Ships with zero third-party runtime dependencies, dual ESM/CJS outputs, and a single bundled declaration file for clean bundle hygiene.

Built for the environmentsyou already use.

One clean API across TypeScript, Next.js, Astro, and webhook infrastructure. Keep your code predictable and let the SDK handle the complexity.

Read the documentation

Everything Daraja
needs. Nothing it doesn't.

The SDK handles the awkward parts of the M-Pesa API while keeping your application code predictable, typed, and easy to maintain.

End-to-End Strict TypeScript Payloads

01

Every interaction across the M-Pesa ecosystem is strongly typed, from STK Push, C2B, B2C Account Top Up, B2B Hakikisha, Dynamic QR, and Mobile Data Bundles to synchronous responses and asynchronous webhooks. Daraja quirks and legacy property names are represented accurately, giving you reliable autocomplete and compile-time guarantees.

STK PushC2BB2CB2BQRData Bundles

Automated OAuth 2.0 Token Lifecycle & Caching

02

Authentication is handled for you. Consumer credentials are exchanged automatically, access tokens are cached in memory according to their server-defined TTL, and a proactive 60-second refresh window prevents expiring credentials from turning into intermittent 401 responses.

OAuth 2.0In-memory cacheAuto refresh60s buffer

Upstream Quirk Normalization & Pre-Flight Validation

03

Daraja-specific protocol details are normalized before a request leaves your server. The SDK handles EAT timestamp generation, Base64 password derivation, required parameter formatting, URL checks, payload constraints, and local validation so invalid requests fail early with useful errors.

UTC+3 / EATBase64ValidationEarly errors

Runtime-Agnostic & Multi-Framework Compatibility

04

Built entirely on standard Web APIs such as fetch and AbortController. Run the same SDK across Node.js, Vercel Edge, Cloudflare Workers, Deno, and Bun, with clean integration into Next.js, Remix, Astro, SvelteKit, Express, and Fastify.

Node.jsVercel EdgeCloudflareDenoBun

Ergonomic Callback Parsing & Data Transformation

05

Turn deeply nested Daraja callback payloads into usable typed data. Static parsing utilities unpack ResultParameter arrays, coerce string-encoded values, and expose discriminated success and failure states for predictable webhook processing.

WebhooksParsingType coercionDiscriminated unions

Zero Heavy Dependencies & Dual-Module Packaging

06

No Axios, node-fetch, or heavyweight runtime wrappers. The package stays small, minimizes serverless cold starts, reduces supply-chain exposure, and ships ESM, CommonJS, and bundled TypeScript declarations for modern and legacy toolchains.

Zero dependenciesESMCommonJS.d.tsTree-shaking
Ready to deploy

Start building your M-Pesa flow.

Stop maintaining payment boilerplate. Install the SDK, configure your Daraja credentials, and ship your integration in minutes.

npm install @lumierelabs/daraja