Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

azampay

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

azampay

Azampay NodeJs SDK to help you interact with Azampay API

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

NODEJS AZAMPAY SDK

AzamPay NodeJs SDK to help you easily and seamlessly integrate with Azampay APIs.

Table of Contents

  1. Installations
  2. Use
    2.1 Get Token
    2.2 Bank Checkout
    2.3 Mno Checkout
    2.4 Disbursement
    2.5 Name Lookup
    2.6 Transaction Status
    2.7 Post Checkout
    2.7 Payment Partners

Installation and Use

From terminal in the root directory of your project, run


npm i azampay


Use

ES6 Import

import azampay from 'azampay'

Module Require

const azampay = require('azampay').default

  • The import or require from azampay package exports two properties.

    1. getToken method that is used to retrieve access token from Azam Pay
    2. instance a class that can be used or extended to add functionalities to the azampay package

Get Token

Requirement Definition

PropertyDescriptionTypeRequired
envEnum: SANDBOX | LIVE. Azampay environment. Default SANDBOXString[ ]
clientIdIt will be the client id generated during application registration.String[x]
appNameIt will be the name of application.String[x]
clientSecretIt will be the secret key generated during application registration.String[x]
apiKeyAzam Pay API key given as token in the settings page.String[x]

Request Payload


{
  "env": "string",
  "clientId": "string",
  "appName": "string",
  "clientSecret": "string",
  "apiKey": "string",
}

Request Method


const token = await azampay.getToken(payload);

Response

If successful, the response will be of type TokenResponse or ErrorResponse


{
  data: { accessToken: string; expire: string };
  success: boolean;
  message: string;
  code: string | number;
  statusCode: number;
  bankCheckout: (
    payload: BankCheckout,
    options: RequestOptions
  ) => Promise<CheckoutResponse>;

  mnoCheckout: (
    payload: MnoCheckout,
    options: RequestOptions
  ) => Promise<CheckoutResponse>;

  postCheckout: (
    payload: PostCheckOut,
    options: RequestOptions
  ) => Promise<PostCheckOutInterface>;

  disburse: (
    payload: Disburse,
    options: RequestOptions
  ) => Promise<DisburseResponse>;

  transactionStatus: (
    payload: TransactionStatus,
    options: RequestOptions
  ) => Promise<TransactionStatusResponse>;

  nameLookup: (
    payload: NameLookup,
    options: RequestOptions
  ) => Promise<NameLookupResponse>;
}

Response Definition

PropertyDescriptionType
dataAzam Pay respnse with access token and expire timeObject
successA true boolean value indicating that the request was successfullBoolean
messageResponse messageString
codeResponse code.Number | String
statusCodeResponse Http Status code. Possibly 200 or 201Number
bankCheckoutA method to initiate a Bank checkout with Azam Pay.Method
mnoCheckoutA method to initiate MNO checkout with Azam Pay.Method
disburseA method used to lookup the name associated with a bank account or Mobile Money accountMethod
transactionStatusA method used to retrieve the status of a disbursement transaction made through AzamPay.Method
nameLookupA method used to lookup the name associated with a bank account or Mobile Money account.Method

Bank Checkout

Initiating a bank checkout, we can use two methods, one from the token results method and the other from the Azam Pay instance exported from the azampay package.

Bank checkout method takes two arguments, the first with the request payload for Azam Pay bank checkout and second is optional with additional options.

Request Payload


{

  amount: string;
  currencyCode: string;
  merchantAccountNumber: string;
  merchantMobileNumber: string;
  merchantName?: string | null;
  otp: string;
  provider: 'CRDB' | 'NMB' |
  referenceId: string;
  additionalProperties?: Record<string, unknown> | null;
}

  1. Request Payload Definition
PropertyDefinitionType
amountThis is amount that will be charged from the given account.String
currencyCodeCode of currencyString
merchantAccountNumberThis is the account number/MSISDN that consumer will provide. The amount will be deducted from this.String
merchantMobileNumberMobile numberString
merchantNameNullable consumer name.String
otpOne time passwordString
providerEnum: CRDB | NMB BankProvider.String
referenceIdThis id belongs to the calling application. Maximum Allowed length for this field is 128 ascii characters.String
additionaPropertiesThis is additional JSON data that calling application can provide. This is optional.Object
  1. Request Options Definition
  • These are optional if you use the method from the response in getToken otherwise mandatory if using the instance and the options were not passed during instantiation.

Method

Request from Token Response

await token.bankCheckout(payload, options)

Request from Instance

const instance = new azampay.instance({accessToken: token.data.accessToken,apiKey: 'YOUR API KEY'})
await instance.bankCheckout(payload, options)

Response

{
  transactionId: string,
  message: string,
  succcess: true
}

NB: Every response has a success property denoting whether the request was successful or not and if it wasn't, the response will be of type Error Response


MNO Checkout

For request method explanation, refer to Bank Checkout's explanation.

  1. Request Payload Definition
PropertyDefinitionType
amountThis is amount that will be charged from the given account.String
currencyCodeCode of currencyString
accountNumberThis is the account number/MSISDN that consumer will provide. The amount will be deducted from this account.String
providerEnum: Airtel | Tigo | Halopesa | Azampesa | Mpesa.String
externalIdThis id belongs to the calling application. Maximum Allowed length for this field is 128 ascii characters.String
additionaPropertiesThis is additional JSON data that calling application can provide. This is optional.Object

{
  accountNumber: string;
  amount: string;
  currency: string;
  externalId: string;
  provider: 'Airtel' | 'Tigo' | 'Halopesa' | 'Azampesa' | 'Mpesa' | string;
  additionalProperties?: Record<string, unknown> | null;
}

Method

Request from Token Response

await token.mnoCheckout(payload, options)

Request from Instance

const instance = new azampay.instance({accessToken: token.data.accessToken,apiKey: 'YOUR API KEY'})
await instance.mnoCheckout(payload, options)

Response The response is the same as the Bank Checkout's


Disbursement

This method allows for the transfer of money from other countries to Tanzania. It requires the authorization token generated above, passed as a header in the request. The request should also contain details of the source, destination, and transfer details. Additionally, the request can include an external reference ID and remarks.

This method takes two arguments, mandatory payload and the other optional options as explained in Bank Checkout

Payload


{
  source: Source;
  destination: Destination;
  transferDetails: TransferDetails;
  externalReferenceId: string;
  remarks: string;
}

PropertyDescriptionType
sourceContains information about the source account.Object
destinationContains information about the destination account.Object
transferDetailsContains information about the transfer.Object
externalReferenceIdAn external reference ID to track the transaction.String
remarksAny remarks to be included with the transaction.String

Method

Request from Token Response

await token.disburse(payload, options)

Request from Instance

const instance = new azampay.instance({accessToken: token.data.accessToken,apiKey: 'YOUR API KEY'})
await instance.disburse(payload, options)

Response


{
  data: string;
  message: string;
  success: boolean;
  statusCode: number;
}

Description

PropertyDescriptionType
dataA string containing the status of the transaction.String
messageA string containing a human-readable message describing the response.String
successA boolean indicating whether the request was successful or not.Boolean
statusCodeAn integer indicating the status code of the response.Number

Name Lookup

This method is used to lookup the name associated with a bank account or Mobile Money account.

This method takes two arguments, mandatory payload and the other optional options as explained in Bank Checkout

Payload


{
  bankName: string;
  accountNumber: string;
}

Description

PropertyDescriptionType
bankNameBank name or Mobile Money name associated with the account.String
accountNumberBank account number or Mobile Money number.String

Method

Request from Token Response

await token.nameLookup(payload, options)

Request from Instance

const instance = new azampay.instance({accessToken: token.data.accessToken,apiKey: 'YOUR API KEY'})
await instance.nameLookup(payload, options)

Response


{
  name: string;
  message: string;
  success: boolean;
  accountNumber: string;
  bankName: string;
}

Description

PropertyDescriptionType
bankNameBank name or Mobile Money name associated with the account.String
accountNumberBank account number or Mobile Money number.String
nameName associated with the account.String
messageA brief description of the response status.String
successA boolean value indicating if the request was successful or not.Boolean

Transaction Status

This method allows you to retrieve the status of a disbursement transaction made through AzamPay. This method takes two arguments, mandatory payload and the other optional options as explained in Bank Checkout

Payload


{
  reference: string;
  bankName: string;
}

Description

PropertyDescriptionType
referenceThe transaction ID you received when making the disbursement request.String
bankNameThe name of the mobile network operator (MNO) you used to make the disbursement request.String

Method

Request from Token Response

await token.transactionStatus(payload, options)

Request from Instance

const instance = new azampay.instance({accessToken: token.data.accessToken,apiKey: 'YOUR API KEY'})
await instance.transactionStatus(payload, options)

Response

PropertyDescriptionType
dataA string containing the status of the transaction.String
messageA string containing a human-readable message describing the response.String
successA boolean indicating whether the request was successful or not.Boolean
statusCodeAn integer indicating the status code of the response.Number

Post Checkout

For this post request, send all params that are mentioned below to this end point.

This end point will respond back with the URL of your payments. Merchant Application can open this url in a new window to continue with the checkout process of the transaction


Payload


{
  appName: string;
  clientId: string;
  vendorId: string;
  language: string;
  currency: string;
  externalId: string;
  requestOrigin: string;
  redirectFailURL: string;
  redirectSuccessURL: string;
  vendorName: string;
  amount: string;
  cart: Cart;
}

Description

PropertyDescriptionType
amountThis is amount that will be charged from the given account.String
appNameThis is the application name.String
cartShoping cart with multiple item.Object
clientIdClient id is unique id for identify client.String
externalId30 charecters long unique string.String
languageLanguage code for transalate the application.String
redirectFailURLURL that you want to redirected to at transaction failure.String
redirectSuccessURLURL that you want to redirected to at transaction success.String
requestOriginURL which the request is being originated.String
vendorIdUnique id for validate vendor.String
vendorNameName of vendor.String

Response

This returns a success boolean property indicating whether the operation was successful or not and a data string


{
  data: string
  success: boolean;
  [key: string]: unknown;
}


Payment Partners

This method will return the registered partners of the provided merchant

This method takes optional options argument as explained in Bank Checkout

Method

Request from Token Response

await token.partners(options)

Request from Instance

const instance = new azampay.instance({accessToken: token.data.accessToken,apiKey: 'YOUR API KEY'})
await instance.partners(options)

Response

{
  success: boolean;
  partners: Partners[];
}

Description

PropertyDescriptionType
successA boolean value indicating if the request was successful or not.Boolean
partnersAn array of payment partners.Array

Partners

PropertyDescriptionType
currencyCurrency code that will convert amount into specific currency formatString
logoUrlPayment Partner logo URLString
partnerNameName of the payment partner e.g (Azampesa, Airtel, Halopesa, Tigopesa, vodacom)String
paymentPartnerIdUnique id for payment partnerString
paymentVendorIdUnique id for payment vendorString
providerProvider enum value e.g (airtel=2, tigo=3, halopesa=4, azampesa=5, Mpesa=10)String
vendorNameName of vendorString

Request Options


{
  apiKey: string;
  accessToken: string;
  env: 'LIVE' | 'SANDBOX';
}


Source or Destination

Payload

 {
  countryCode: string;
  fullName: string;
  bankName: string;
  accountNumber: string;
  currency: string;
}

Description

PropertyDescriptionType
countryCodeCountry / Destination codeString
fullNameSource / Destination account full nameString
bankNameSource / Destination account bank nameString
accountNumberSource / Destination account account numberString
currencySource / Destination account currencyString

Transfer Details

Payload


 {
  type: string;
  amount: number;
  date: string;
}

Description

PropertyDescriptionType
typeTransfer typeString
amountTransfer amountString
dateTransfer dateString

Error Response


{

  success: boolean;
  message: string;
  code: string  | number;
  statusCode: number;
}

Property Definition

PropertyDescriptionType
successA false boolean value indicating that the request was not successfull.Boolean
messageError messageString
codeError codeNumber | String
statusCodeError Http Status codeNumber

Developed and Maintained with ❤️ at Flexcode Labs

Keywords

FAQs

Package last updated on 07 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc