@daraja/client
TypeScript icon, indicating that this package has built-in type declarations

0.0.8 • Public • Published

Daraja Client

A light weight NodeJS library for Safaricom's Daraja API

Logo

Installation

Install @daraja/client with npm

npm install @daraja/client

or with Yarn

yarn add @daraja/client

Quick Start

import { DarajaClient } from '@daraja/client';

const client = new DarajaClient({
  businessShortcode: '123456',
  consumerKey: 'consumerKey',
  consumerSecret: 'consumerSecret',
  lnmPasskey: 'lnmPasskey',
  scopes: ['lipa-na-mpesa-online'],
});

client
  .lipaNaMpesaOnlinePayment({
    accountReference: 'CompanyXLTD',
    amount: 1,
    callbackURL: 'http://mydomain.com/lnmCallback',
    partyA: '254701234567',
    transactionDescription: 'Payment of X',
    transactionType: 'CustomerPayBillOnline',
  })
  .then((res) => {
    // SUCCESS
    // do something with the response
  })
  .catch((err) => {
    // FAIL
    // handle the error
  });

// you can also use the async-await syntax to perform a similar operation

const transact = async () => {
  try {
    const response = await client.lipaNaMpesaOnlinePayment({
      accountReference: 'CompanyXLTD',
      amount: 1,
      callbackURL: 'http://mydomain.com/lnmCallback',
      partyA: '254701234567',
      transactionDescription: 'Payment of X',
      transactionType: 'CustomerPayBillOnline',
    });
    // do something with the response
  } catch (error) {
    // handle the error
  }
};

transact()

API Reference

Daraja Client's full documentation is online at Daraja Client documentation.

Features

  • Lipa na Mpesa Online Payment

Roadmap

  • Lipa na Mpesa Online Query
  • C2B Register URLs
  • C2B Simulate Transaction
  • B2C Payment
  • Transaction Status Query
  • Account Balance Query
  • Transaction Reversal

Tech Stack

NodeJS, TypeScript

License

MIT

Contributing

Contributions are always welcome!

See CONTRIBUTING.md for ways to get started.

Please adhere to this project's Code of Conduct.

Feedback

If you have any feedback, please reach out to me at austinewuncler@gmail.com

Readme

Keywords

Package Sidebar

Install

npm i @daraja/client

Weekly Downloads

0

Version

0.0.8

License

MIT

Unpacked Size

33.5 kB

Total Files

37

Last publish

Collaborators

  • austinewuncler