0.1.1 • Published 1 year ago

@iamshabell/waafipay-sdk v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

WaafiPay SDK Guide

This is a TypeScript version of this previous waafipay-sdk-node package.

If you’re new to TypeScript, checkout this handy cheatsheet

Installing

To install waafi-pay-sdk, use:

npm intall waafi-pay-sdk # or yarn add waafi-pay-sdk

There are two methods available in this sdk is apiPurchase and creditAccount. In order to use this methods, you need to have api credentials from waafi pay(API KEY,API USER ID,MERCHANT KEY).

Api Purchase

This method is for Getting Money From Customers. You will need to pass the customer's information, including phone number, amount, currency, description.

An example of Api Purchasing with express:

...
import { WaafiAPI } from "waafi-pay-sdk";

const app: Express = express();
const port = 3001;

const waafipay = new WaafiAPI(
  "API_KEY",
  "API_USER_ID",
  "MERCHANT_KEY",
  true, //--> isTestMode -> true is production : false is test
  );


app.post("/purchase", async (req: Request, res: Response, next) => {
  try {
    const { accountNo, amount, currency, description } = req.body;

    const result = await waafipay.apiPurchase({
      accountNo: accountNo,
      amount: amount,
      currency: currency,
      description: description,
    });

    console.log("result: " + JSON.stringify(result));
    res.status(200).json(JSON.stringify(result));
  } catch (e) {
    console.log(e);

    res.status(400).send(e);
  }
});

...

And here is an example of the request body:

{
    "accountNo": "2526XXXXXX", //-> customer's phone number
    "amount": 1,
    "currency": "USD", //-> optional, default is USD. It also takes (SLSH)
    "description": "test"
}

When it is success, it will return this:

{
    "schemaVersion": "1.0",
    "timestamp": "2022-2-22 22:22:22.22",
    "requestId": "45231213",
    "sessionId": null,
    "responseCode": "2001",
    "errorCode": "0",
    "responseMsg": "RCS_SUCCESS",
    "params": {
        "issuerApprovalCode": "",
        "accountNo": "2526*********",
        "accountType": "MWALLET_ACCOUNT",
        "accountholder": "",
        "state": "APPROVED",
        "merchantCharges": "111",
        "customerCharges": "0.0",
        "referenceId": "455656",
        "transactionId": "465656",
        "accountExpDate": "",
        "issuerTransactionId": "23156231",
        "txAmount": "0"
    }
}

If everything gone through success, responseCode will be 2001. If there are other problems:

User Aborted(canceled):

  • responseCode: 5206
  • responseMsg: "RCS_TRAN_FAILED_AT_ISSUER_SYSTEM (STATE: rejected, ERRCODE: 4004 - User Aborted, TransactionId: 465656)"

User Insufficient:

  • responseCode: 5206
  • responseMsg: "RCS_TRAN_FAILED_AT_ISSUER_SYSTEM (STATE: declined, ERRCODE: 8001 - Hadhaagaagu kuguma filna. Hadhaagaagu waa {SENDERBALANCE}, TransactionId: 465656)"

Credit Account

This method is for when you want to withdraw your money from Waafi to your account. Your account is either regular account or merchant account

An example of Crediting to Account :

...
app.post("/credit", async (req: Request, res: Response, next) => {
  try {
    const { accountNo, accountName, amount, currency, description, accountType } = req.body;

    const response = await waafipay.creditAccount({
      accountNo: accountNo,
      accountHolder: accountName,
      amount: amount,
      currency: currency,
      description: description,
      accountType: accountType,
    });

    console.log("response: " + JSON.stringify(response));
    res.status(200).json(JSON.stringify(response));
  } catch (e) {
    console.log(e);

    res.status(400).send(e);
  }
});
...

And here is an example of the body:

{
    "accountNo": "2526XXXXXX", //-> reciever's phone number
    "accountName": "GEEDI", // -> reciever's name,
    "accountType": "CUSTOMER", // -> recievers account type, it als could be (MERCHANT)
    "amount": 1,
    "currency": "USD", //-> optional, default is USD. It also takes (SLSH)
    "description": "test"
}

When it is success, it will return this:

{
    "schemaVersion": "1.0",
    "timestamp": "2022-2-22 22:22:22.22",
    "requestId": "45231213",
    "sessionId": null,
    "responseCode": "2001",
    "errorCode": "0",
    "responseMsg": "RCS_SUCCESS",
    "params": {
        "issuerApprovalCode": "",
        "accountNo": "2526*********",
        "accountType": "MWALLET_ACCOUNT",
        "accountholder": "GEEDI",
        "state": "APPROVED",
        "merchantCharges": "111",
        "customerCharges": "0.0",
        "referenceId": "455656",
        "transactionId": "465656",
        "accountExpDate": "",
        "issuerTransactionId": "23156231",
        "txAmount": "0"
    }
}

If everything gone through success, responseCode will be 2001. If there are other problems:

Your Account(Waafi) has insufficient money:

  • responseCode: 50333
  • responseMsg: "RCS_ACC_INSUFFICIENT_BALANCE"

Support

This packages will be open source, feel free to contribute.