1.0.1 • Published 9 months ago

@gat-solutions/top-up v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

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);
FieldsDescription
emailEmail này được bên thứ 3 cung cấp
passwordPassword đượ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);
FieldsDescription
fromTừ ngày theo format (YYYY/MM/DD)
toĐến ngày theo format (YYYY/MM/DD)
typeLoạ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);
FieldsDescription
referenceIdMã 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);
FieldsDescription
phonenumberSố điện thoại cần nạp tiền
priceMệnh giá
requestIdMã user tự tạo và truyền lên (recommend dùng uuid)
callbackurlURL để ViHAT bắn webhook về
sandboxMô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);
FieldsDescription
networkMã nhà mạng
priceMệnh giá
sandboxMôi trường: Sandbox hoặc Production

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

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

9 months ago

1.0.0

9 months ago