@gat-solutions/top-up
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Introduction

Đây là một thư viện hỗ trợ gọi API TopUp từ bên thứ 3 (Hiện tại là ViHAT). Thư viện bao gồm 1 service gọi API đi kèm những định nghĩa type dành cho typescript.

Installation

$ npm i @gat-solutions/top-up

Usage

Khởi tạo service

import { TopUpService } from '@gat-solutions/top-up';

const email = 'email@gmail.com';
const password = 'veryStringPassword';

const topUpService = new TopUpService(email, password);
Fields Description
email Email này được bên thứ 3 cung cấp
password Password được cung cấp kèm theo email

Login

const topUpService = new TopUpService(email, password);

const data = await topUpService.login();

Dữ liệu trả về

{
    "resultCode": "100",
    "data": {
        "token": "MYAWH3P-CE3MWPD-H2F7SVW-91GGHGF",
        "expiry": "2023-08-30T03:46:01.000Z"
    }
}

Get Balance

const topUpService = new TopUpService(email, password);

const data = await topUpService.getBalance();

Dữ liệu trả về

{
    "resultCode": 100,
    "message": "Success",
    "data": {
        "email": "email@gmail.com",
        "balance": 40000
    }
}

Get all transactions

const topUpService = new TopUpService(email, password);

const dto: GetAllTransactionDto = {
    from: "2023/01/01",
    to: "2023/12/31",
    type: TransactionType.TOP_UP
};

const data = await topUpService.getAllTransactions(dto);
Fields Description
from Từ ngày theo format (YYYY/MM/DD)
to Đến ngày theo format (YYYY/MM/DD)
type Loại giao dịch: TopUp hoặc CardCode (Mua card)

Dữ liệu trả về

{
    "resultCode": 100,
    "message": "Thành công",
    "data": {
        "logs": [
            {
                "_id": "xxxxxxxxxxxxxxx",
                "requestid": "xxxxxxxxxxxxxxx",
                "typeid": 1,
                "phonenumber": "xxxxxxxxxxxxxxx",
                "requestip": "xxx.xxx.xxx.xx",
                "price": 10000,
                "referenceid": "xxxxxxxxxxxxxxx",
                "result": "true",
                "createDate": "2023-08-28T02:56:25.801Z"
            }
        ]
    }
}

Get detail a transaction

const topUpService = new TopUpService(email, password);

const dto: GetDetailTransactionDto = {
    referenceId: "xxxxxxxxx"
};

const data = await topUpService.getDetailTransaction(dto);
Fields Description
referenceId Mã mà user truyền lên khi user thực hiện giao dịch

Dữ liệu trả về

{
    "resultCode": 100,
    "message": "Success",
    "logs": [
        {
            "referenceId": "xxxxxxxxx",
            "result": 0
        }
    ]
}

Top Up (nạp tiền điện thoại)

const topUpService = new TopUpService(email, password);

const dto: TopUpDto = {
    phonenumber: "0xxxxxxxxx",
    price: 10000,
    requestId: "random",
    callbackurl: "http://localhost:3000",
    sandbox: Env.SANDBOX
};

const data = await topUpService.topUp(dto);
Fields Description
phonenumber Số điện thoại cần nạp tiền
price Mệnh giá
requestId Mã user tự tạo và truyền lên (recommend dùng uuid)
callbackurl URL để ViHAT bắn webhook về
sandbox Môi trường: Sandbox hoặc Production

Dữ liệu trả về (Sandbox):

{
    "resultCode": 200,
    "message": "Test OK",
    "userid": "64db55440dcdb000307a1a73"
}

Buy Card (nạp tiền điện thoại)

const topUpService = new TopUpService(email, password);

const dto: BuyCardDto ={
    network: CardNetwork.VINAPHONE,
    price: 10000,
    sandbox: Env.SANDBOX
};

const data = await topUpService.buyCard(dto);
Fields Description
network Mã nhà mạng
price Mệnh giá
sandbox Môi trường: Sandbox hoặc Production

Dữ liệu trả về (Sandbox):

{
    "resultCode": 200,
    "message": "Test OK"
}

Readme

Keywords

none

Package Sidebar

Install

npm i @gat-solutions/top-up

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

17.7 kB

Total Files

14

Last publish

Collaborators

  • huygiale
  • dotranminhchu
  • duyanhit
  • thaivlinh