Payments SDK

M-Pesa PaymentsMade Simple

The modern SDK for integrating M-Pesa payments. Type-safe, fully documented.

Works with your favorite frameworks

React
Next.js
Vue
Svelte
Express
Nuxt

Lightning Fast

Optimized for performance with automatic retries, caching, and intelligent polling. Get payment confirmations in seconds.

Type Safe

Built with TypeScript from the ground up. Full IntelliSense support and compile-time safety for all M-Pesa operations.

Well Documented

Comprehensive guides, API references, and code examples. Get started in minutes with our interactive documentation.

Three Steps to Success

Quick Start

Get up and running in minutes, not hours

1

Install the package

npm install @singularity-payments/nextjs
2

Configure M-Pesa client

export const mpesa = createMpesa({
  consumerKey: process.env.MPESA_CONSUMER_KEY!,
  consumerSecret: process.env.MPESA_CONSUMER_SECRET!,
  passkey: process.env.MPESA_PASSKEY!,
  shortcode: process.env.MPESA_SHORTCODE!,
  environment: "sandbox",
  callbackUrl: `${process.env.NEXT_PUBLIC_URL}/api/callback`,
});
3

Initiate payments

const response = await mpesa.client.stkPush({
  amount: 100,
  phoneNumber: "254712345678",
  accountReference: "ORDER-123",
  transactionDesc: "Payment for order",
});
React Integration

React Hooks Example

Simple payment integration with automatic status tracking

const { initiatePayment, CheckoutRequestID } = useMpesaPayment();
const { isSuccess, isFailed, status } = usePaymentStatus({
  CheckoutRequestID
});

await initiatePayment({
  amount: 100,
  phoneNumber: "254712345678",
  accountReference: "ORDER-123",
});
Apache 2.0 Licensed

Ready to get started?

Join developers building the future of payments in Africa