# @iamshabell/waafipay-sdk

> This is a TypeScript version of this previous [waafipay-sdk-node](https://www.npmjs.com/package/waafipay-sdk-node) package.

Latest version **0.1.1** (published 2022-12-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @iamshabell/waafipay-sdk
pnpm add @iamshabell/waafipay-sdk
yarn add @iamshabell/waafipay-sdk
bun add @iamshabell/waafipay-sdk
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2022-12-11 |
| First published | 2022-12-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 1 |
| Unpacked size | 78.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Mubarak Shabel |
| Maintainers | iamshabell |
| Keywords | waafipay, Waafi Pay SDK, Waafi API, Waafi |

## Links

- npm: https://www.npmjs.com/package/@iamshabell/waafipay-sdk
- Repository: https://github.com/iamshabell/waafi-pay-sdk
- Homepage: https://github.com/iamshabell/waafi-pay-sdk#readme
- Issues: https://github.com/iamshabell/waafi-pay-sdk/issues
- npm.io page: https://npm.io/package/@iamshabell/waafipay-sdk

## Dependencies (1)

- [got](https://npm.io/package/got.md) 11.8.5

## Recent versions

- 0.1.1 (latest) — 2022-12-11

## README

# WaafiPay SDK Guide

This is a TypeScript version of this previous [waafipay-sdk-node](https://www.npmjs.com/package/waafipay-sdk-node) package.

> If you’re new to TypeScript, checkout [this handy cheatsheet](https://devhints.io/typescript)

## Installing

To install waafi-pay-sdk, use:

```bash
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:

```typescript
...
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:

```javascript
{
    "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:

```javascript
{
    "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 :

```typescript
...
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:

```javascript
{
    "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:

```javascript
{
    "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.

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