Logo Lanfrica

levos-snr/pesafy

Domaine:

digital infrastructure

Type de record:

software
Créateur:
lev
Hôte:
A powerful, type-safe payment gateway library for African payment systems, starting with M-Pesa Daraja API # pesafy 💳 > **Type-safe M-PESA Daraja SDK** for Node.js, Bun, Deno, Cloudflare Workers, > Next.js, Fastify, Hono, and Express. --- ## Table of Contents - Installation - Quick Start - CLI - API Reference - STK Push (M-PESA Express) - C2B (Customer to Business) - B2C Account Top Up - B2C Disbursement - B2B Express Checkout - B2B Pay Bill - B2B Buy Goods - Account Balance - Transaction Status - Transaction Reversal - Tax Remittance (KRA) - Dynamic QR Code - Bill Manager - Webhooks - Framework Adapters - Express - Hono (Bun / Cloudflare Workers) - Next.js App Router - Fastify - Branded Types - Error Handling - Utilities - Configuration Reference - Roadmap --- ## Installation ```bash npm install pesafy # npm yarn add pesafy # yarn pnpm add pesafy # pnpm bun add pesafy # bun ``` --- ## Quick Start ```typescript import { Mpesa } from 'pesafy' const mpesa = new Mpesa({ consumerKey: process.env.MPESA_CONSUMER_KEY!, consumerSecret: process.env.MPESA_CONSUMER_SECRET!, environment: 'sandbox', // "sandbox" | "production" lipaNaMpesaShortCode: '174379', lipaNaMpesaPassKey: process.env.MPESA_PASSKEY!, }) // Send an STK Push const response = await mpesa.stkPush({ amount: 100, phoneNumber: '0712345678', callbackUrl: 'example.com', accountReference: 'INV-001', transactionDesc: 'Payment', }) console.log(response.CheckoutRequestID) ``` --- ## CLI The pesafy CLI lets you interact with Daraja directly from your terminal — great for testing, debugging, and scripting. ### Setup ```bash # Interactive setup — creates .env in your project npx pesafy init # Validate your .env config npx pesafy doctor ``` ### Commands ``` npx pesafy init Scaffold .env interactively npx pesafy doctor Validate .env for common mistakes npx pesafy token Print a fresh OAuth token npx pesafy encrypt …