# @paylend/mpesa

> A simple wrapper for safaricom daraja api

Latest version **1.0.8** (published 2022-02-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install @paylend/mpesa
pnpm add @paylend/mpesa
yarn add @paylend/mpesa
bun add @paylend/mpesa
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2022-02-24 |
| First published | 2022-02-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 28.2 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| Author | Paylend |
| Maintainers | paylend |
| Keywords | mpesa, safaricom, payments |

## Links

- npm: https://www.npmjs.com/package/@paylend/mpesa
- npm.io page: https://npm.io/package/@paylend/mpesa

## Dependencies (3)

- [joi](https://npm.io/package/joi.md) ^17.6.0
- [axios](https://npm.io/package/axios.md) ^0.26.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.21

## Recent versions

- 1.0.8 (latest) — 2022-02-24
- 1.0.7 — 2022-02-24
- 1.0.6 — 2022-02-22
- 1.0.5 — 2022-02-18
- 1.0.4 — 2022-02-14
- 1.0.3 — 2022-02-14
- 1.0.2 — 2022-02-05
- 1.0.1 — 2022-02-05
- 1.0.0 — 2022-02-03

## README

<div align="center">

[![Paylend](https://paylend.africa/assets/landing/paylend-logo.svg)](https://paylend.africa/)

</div>

## Installation

To install the package do this

```js
const { Mpesa } = require('@paylend/mpesa')
```

Alternatively, you can require the package and initialize the default configurations as follows:

```js
const { Mpesa } = require('@paylend/mpesa')({
  baseUrl: 'https://sandbox.safaricom.co.ke',
  consumerKey: process.env.consumerKey,
  consumerSecret: process.env.consumerSecret
})
```

## Generating An Oauth Token

To generate an oauth token do:

```js
const { access_token: accessToken } = Mpesa.generateOauthToken()
```

## B2B Payment Request

To make a b2b payment request

```js
const response = Mpesa.b2bPaymentRequest({
  initiator,
  securityCredential,
  commandID,
  senderIdentifierType,
  recieverIdentifierType,
  amount,
  partyA,
  partyB,
  accountReference,
  remarks,
  queueTimeOutURL,
  resultURL
})
```

## Transaction Reversal

To make a reversal

```js
const response = Mpesa.reversal({
  initiator,
  securityCredential,
  transactionID,
  amount,
  receiverParty,
  resultURL,
  queueTimeOutURL,
  recieverIdentifierType,
  remarks,
  occasion = ''
})
```

## Query A Transaction Status

Getting the status of a transaction

```js
const response = Mpesa.transactionStatus({
  initiator,
  securityCredential,
  transactionID,
  partyA,
  identifierType,
  resultURL,
  queueTimeOutURL,
  remarks,
  occasion
})
```

## Simulate C2B Payment

Simulate a c2b payment

```js
const response = Mpesa.simulateC2bPayment({
  shortCode,
  amount,
  msisdn,
  billRefNumber
})
```

## Make an STK Push

Make an STK push to a customer's phone number

```js
const response = Mpesa.stkPush({
  businessShortCode,
  password,
  timestamp,
  amount,
  partyA,
  partyB,
  phoneNumber,
  accountReference,
  transactionDesc,
  callbackUrl
})
```

## Query an STK Push Status

Make an STK push to a customer's phone number

```js
const response = Mpesa.stkPushStatus({
  businessShortCode,
  password,
  timestamp,
  checkoutRequestId
})
```

## Account Balance

Query an account balance

```js
const response = Mpesa.accountBalance({
  initiator,
  securityCredential,
  partyA,
  remarks,
  queueTimeOutURL,
  resultURL,
  identifierType
})
```

## Register C2B Confirmation URL

Register a c2b confirmation URL

```js
const response = Mpesa.registerC2bConfirmationUrl({
  shortCode,
  responseType,
  confirmationUrl,
  validationUrl
})
```

## B2C Payment Request

Make a business to customer payment request

```js
const response = Mpesa.accountBalance({
  initiatorName,
  securityCredential,
  commandID,
  amount,
  partyA,
  partyB,
  remarks,
  queueTimeOutURL,
  resultURL,
  occasion
})
```

---
_Source: https://npm.io/package/@paylend/mpesa · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
