Mpesa Class

The Mpesa class provides methods for interacting with the Mpesa API.

Usage

Before using the Mpesa class, make sure to set up the required configurations.

import { Mpesa } from './mpesa';

const config = {
  consumerKey: "YOUR_CONSUMER_KEY",
  consumerSecret: "YOUR_CONSUMER_SECRET",
  environment: "sandbox",
  shortCode: "YOUR_SHORT_CODE",
  passKey: "YOUR_PASS_KEY",
}

const mpesa = new Mpesa(config);

Getting the Configuration from Daraja

Before you can use the Mpesa API, you need to obtain the required configuration values from Daraja. These values will be specific to your Mpesa account and environment.

The config object contains the following properties:

  • consumerKey: The consumer key obtained from Daraja. It is a unique identifier for your application.
  • consumerSecret: The consumer secret obtained from Daraja. It is used to authenticate your application.
  • environment: The environment in which you want to make API requests. It can be either "sandbox" or "production".
  • shortCode: Your Mpesa short code. It is a unique identifier for your organization or business.
  • passKey: The pass key obtained from Daraja. It is used for encryption and verification purposes.

Make sure to replace the placeholder values in the config object with the actual values obtained from Daraja.

const config = {
  consumerKey: "YOUR_CONSUMER_KEY",
  consumerSecret: "YOUR_CONSUMER_SECRET",
  environment: "sandbox",
  shortCode: "YOUR_SHORT_CODE",
  passKey: "YOUR_PASS_KEY",
}