node-wipay
TypeScript icon, indicating that this package has built-in type declarations

0.3.6 • Public • Published

Node WiPay

This is a Node Wrapper for the WiPay Caribbean V1 API written in TypeScript.

Getting Started

Installation

This package is available on the Node Package Manager and be installed with the following commands:

npm install node-wipay
yarn add node-wipay

Basic Use

To use this package you must import it using the CommonJs or Es6 Module import statement.

import * as WiPay from 'node-wipay'
const WiPayAuth = require('node-wipay').WiPayAuth;

Creating an Auth instance

const auth = WiPayAuth({
    AccountNumber: Number,
    API_Key: String,
});

Testing in Sandbox Mode

auth.LiveMode = false;

Making Voucher API Call.

const handler = new WiPayVoucher(auth);
handler.check(voucher:String)
    .then((result:WiPayVoucherResponse) => {
        console.log(result);
    })
    .catch((error:WiPayVoucherResponse) => {
        console.log(error);
    });

WiPayAuth

This class is designed as a singleton object in order to create an immutable and fault-tolerant instance of the required WiPay configuration information.

WiPayAuthConfig

This configuration interface defines the required configuration information for a WiPay authentication instance to be sucessful.

interface WiPayAuthConfig {
    AccountNumber: Number,
    API_Key: String,
}

Using this format you can initialise an authorisation object by doing the following:

const config;
const wipay_auth = WiPayAuth.getInstance(config:WiPayAuthConfig);
wipay_auth.LiveMode = false or true; // LiveMode is true by default

It is important to note that the _config of the WiPayAuth is immutable and cannot be modified, although the LiveMode:Boolean can be toggled for Live and Sandbox. Also as a Singleton object, the typical class constructor is private to prevent unwanted duplication.

Voucher API

The WiPayVoucher functions returns a Promise<WiPayVoucherResponse>. The structure of the response is as follows.

interface WiPayVoucherResponse {
    status: String,
    msg: String,
    trxn_id?: String,
    value?: Number,
}

Before any calls can be made to the object, it needs to be initialised witha valid authorisation object.

const handler = new WiPayVoucher(auth:WiPayAuth);

Check

handler.check(voucher:String)
    .then((result:WiPayVoucherResponse) => {
        console.log(result);
    })
    .catch((error:WiPayVoucherResponse) => {
        console.log(error);
    });

Pay

handler.pay(voucher:String, total:Number, details?:String)
    .then((result:WiPayVoucher) => {
        console.log(`Transaction ID is ${result.trxn_id}`);
    })
    .catch((error:WiPayVoucherResponse) => {
        console.log(`Payment failed due to: [${error.msg}]`);
    })

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.3.61latest

Version History

VersionDownloads (Last 7 Days)Published
0.3.61
0.3.5-40
0.3.5-30
0.3.5-20
0.3.5-10
0.3.50
0.3.4-20
0.3.40
0.3.3-30
0.3.3-20
0.3.3-10
0.3.30
0.3.2-40
0.3.2-30
0.3.2-20
0.3.20
0.3.10
0.3.00
0.2.3-20
0.2.3-10
0.2.30
0.2.2-30
0.2.2-20
0.2.2-10
0.2.20
0.2.10
0.2.00
0.1.1-20
0.1.1-10
0.1.10
0.1.00

Package Sidebar

Install

npm i node-wipay

Weekly Downloads

1

Version

0.3.6

License

ISC

Unpacked Size

34.2 kB

Total Files

22

Last publish

Collaborators

  • matabeitt