Getting Started
Installation
Learn how to install the M-Pesa SDK for JavaScript.
Installation
Get started with Singularity Payments by installing the appropriate package for your project.
Prerequisites
Before installing, make sure you have:
- Node.js 18+ installed
- A Safaricom Daraja account
- Your M-Pesa API credentials (Consumer Key and Secret), if you don't know how to get them you can follow this guide here
Choose Your Package
Server-Side
Next JS
npm install @singularity-payments/nextjspnpm add @singularity-payments/nextjs yarn add @singularity-payments/nextjs bun add @singularity-payments/nextjs Client-Side
Security Warning
Client-side packages require a backend server. Never expose M-Pesa credentials in client-side code, these packages are designed to simplify integration with the backend
React
npm install @singularity-payments/reactpnpm add @singularity/payments-reactyarn add @singularity/payments-reactbun add @singularity/payments-reactEnvironment Variables
After installation, set up your environment variables:
MPESA_CONSUMER_KEY=your_consumer_key
MPESA_CONSUMER_SECRET=your_consumer_secret
MPESA_SHORTCODE=your_shortcode
MPESA_PASSKEY=your_passkey
MPESA_ENVIRONMENT=sandbox # or 'production'Never commit your .env file to version control. Add it to .gitignore.