0.7.1 • Published 11 months ago

mpesa-sdk v0.7.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

mpesa-sdk

NPM version License

Type safe SDK for M-Pesa API (Mozambique)

Features

  • C2B Payment
  • B2C Payment
  • B2B Payment
  • Query Transaction Status
  • Query Customer Name
  • Reversal

Installation

npm install mpesa-sdk

Usage

Configuration

import MPesa from "mpesa-sdk";

const mpesa = new MPesa({
  mode: "sandbox",
  apiKey: <YOUR_API_KEY>,
  publicKey: <YOUR_PUBLIC_KEY>,
  origin: "developer.mpesa.vm.co.mz",
  serviceProviderCode: "171717"
});

Note: For security reasons, it is a best practice to store sensitive information such as apiKey and publicKey in environment variables rather than hardcoding them directly in your code.

C2B Payment

async function main() {
  const data = await mpesa.c2bPayment({
    amount: 10,
    msisdn: "258843330333",
    transactionReference: "T12344C",
    thirdPartyReference: "11114",
  });

  console.log(data);
}

main();

B2C Payment

async function main() {
  const data = await mpesa.b2cPayment({
    amount: 10,
    msisdn: "258843330333",
    transactionReference: "T12344C",
    thirdPartyReference: "11114",
  });

  console.log(data);
}

main();

B2B Payment

async function main() {
  const data = await mpesa.b2bPayment({
    amount: 10,
    receiverPartyCode: "979797",
    transactionReference: "T12344C",
    thirdPartyReference: "11114",
  });

  console.log(data);
}

main();

Query Transaction Status

async function main() {
  const data = await mpesa.queryTransactionStatus({
    queryReference: "5C1400CVRO",
    thirdPartyReference: "11114",
  });

  console.log(data);
}

main();

Query Customer Name

async function main() {
  const data = await mpesa.queryCustomerName({
    msisdn: "258843330333",
    thirdPartyReference: "11114",
  });

  console.log(data);
}

main();

Reversal

async function main() {
  const data = await mpesa.reversal({
    transactionId: "49XCDF6",
    securityCredential: "Mpesa2019",
    initiatorIdentifier: "MPesa2018",
    thirdPartyReference: "11114",
    reversalAmount: "10",
  });

  console.log(data);
}

main();

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Inspired by mpesa-node-api and mpesa-mz-nodejs-lib

0.7.1

11 months ago

0.7.0

11 months ago

0.6.5

12 months ago

0.6.4

12 months ago

0.6.3

1 year ago

0.6.2

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.1

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago