Skip to main content
Version: Next

Bắt đầu nhanh

Hướng dẫn này giúp bạn thực hiện API call đầu tiên với Tingee SDK chỉ trong vài phút.

Yêu cầu trước khi bắt đầu
  • Đã cài đặt SDK cho ngôn ngữ của bạn
  • clientIdsecretKey từ Tingee Dashboard

1. Khởi tạo Client

import { TingeeClient, isSuccessResponse, isErrorResponse } from '@tingee/sdk-node';

const client = new TingeeClient({
secretKey: process.env.TINGEE_SECRET_KEY!,
clientId: process.env.TINGEE_CLIENT_ID!,
environment: 'uat', // dùng 'uat' khi test, 'production' khi go-live
});

2. Gọi API đầu tiên

Ví dụ: Lấy danh sách Merchant.

const result = await client.merchant.getPaging({
maxResultCount: 10,
skipCount: 0,
});

if (isSuccessResponse(result)) {
console.log('Danh sách merchants:');
result.data.items.forEach(m => console.log(` - ${m.name}`));
} else {
console.error(`Lỗi ${result.code}: ${result.message}`);
}

3. Xử lý Response

SDK trả về TingeeApiResponse cho mọi API call:

{
"code": "00",
"message": "Success",
"data": { ... }
}
SDK không tự throw exception

Khi code !== '00', SDK không throw exception. Bạn cần kiểm tra code hoặc dùng helper:

import { isSuccessResponse, isErrorResponse } from '@tingee/sdk-node';

if (isSuccessResponse(result)) {
// code === '00' → xử lý result.data
} else if (isErrorResponse(result)) {
// code !== '00' → xử lý lỗi
console.error(`${result.code}: ${result.message}`);
}

4. Thêm ví dụ

Danh sách ngân hàng hỗ trợ

const banks = await client.bank.getBanks();
if (isSuccessResponse(banks)) {
banks.data.forEach(b => console.log(`${b.shortName} (BIN: ${b.bin})`));
}
const deepLink = await client.deepLink.generate({
vaAccountNumber: '123456789',
amount: 150000,
orderId: 'ORD-001',
description: 'Thanh toán đơn hàng ORD-001',
});
if (isSuccessResponse(deepLink)) {
console.log('Deep Link:', deepLink.data);
}

Bước tiếp theo