Singularity Payments LogoSingularity Payments

API Reference

Complete reference for all M-Pesa operations in Singularity Payments SDK

API Reference

Complete documentation for all M-Pesa operations available in the Singularity Payments SDK.

Overview

The Singularity Payments SDK provides a type-safe, framework-agnostic way to integrate M-Pesa payments into your application. All operations are built on top of the @singularity-payments/core package with framework-specific adapters.

Available Operations

Payment Operations

Transaction Management

SDK Features

Quick Example

import { MpesaClient } from "@singularity-payments/core";

const client = new MpesaClient({
  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: "https://yourdomain.com/api/mpesa/callback",
});

// Initiate STK Push
const response = await client.stkPush({
  amount: 100,
  phoneNumber: "254712345678",
  accountReference: "INV-001",
  transactionDesc: "Payment for invoice",
});

Common Configuration

All SDK packages require the following M-Pesa credentials:

FieldRequiredDescription
consumerKeyM-Pesa API consumer key
consumerSecretM-Pesa API consumer secret
passkeySTK Push passkey
shortcodeM-Pesa business shortcode
environment"sandbox" or "production"
callbackUrlRecommendedURL for receiving callbacks
initiatorNameFor B2C/B2BInitiator username
securityCredentialFor B2C/B2BEncrypted security credential

See Configuration for detailed setup instructions.

Next Steps

Edit on GitHub

On this page