Cài đặt & Cấu hình
Cài đặt
- Node.js
- Java
- C#
- PHP
npm install @tingee/sdk-node
# hoặc
yarn add @tingee/sdk-node
# hoặc
pnpm add @tingee/sdk-node
Yêu cầu: Node.js ≥ 18
Maven
<dependency>
<groupId>vn.tingee</groupId>
<artifactId>sdk-java</artifactId>
<version>0.1.0-beta</version>
</dependency>
Gradle
implementation 'vn.tingee:sdk-java:0.1.0-beta'
Yêu cầu: Java ≥ 17
dotnet add package Tingee.Sdk
hoặc qua NuGet Package Manager:
Install-Package Tingee.Sdk
Yêu cầu: .NET 8+
composer require tingee/sdk-php
Yêu cầu: PHP ≥ 8.0
Cấu hình Client
- Node.js
- Java
- C#
- PHP
import { TingeeClient } from '@tingee/sdk-node';
const client = new TingeeClient({
secretKey: process.env.TINGEE_SECRET_KEY!,
clientId: process.env.TINGEE_CLIENT_ID!,
environment: 'production', // 'uat' | 'production'
timeout: 90000, // ms, mặc định 90000
// baseUrl: 'https://custom-url.example.com', // ghi đè environment
});
| Tùy chọn | Kiểu | Mặc định | Mô tả |
|---|---|---|---|
secretKey | string | — | Bắt buộc. Secret key từ Tingee Dashboard |
clientId | string | — | Bắt buộc. Client ID từ Tingee Dashboard |
environment | 'uat' | 'production' | 'production' | Môi trường API |
baseUrl | string | — | Ghi đè URL (bỏ qua environment) |
timeout | number | 90000 | Timeout (ms) |
import vn.tingee.sdk.TingeeClient;
import vn.tingee.sdk.client.TingeeEnvironment;
TingeeClient client = TingeeClient.builder(
System.getenv("TINGEE_SECRET_KEY"),
System.getenv("TINGEE_CLIENT_ID"))
.environment(TingeeEnvironment.PRODUCTION) // UAT | PRODUCTION
.timeout(90000) // ms, mặc định 90000
// .baseUrl("https://custom-url.example.com") // ghi đè environment
.build();
| Tham số | Kiểu | Mặc định | Mô tả |
|---|---|---|---|
secretKey | String | — | Bắt buộc. Secret key từ Tingee Dashboard |
clientId | String | — | Bắt buộc. Client ID từ Tingee Dashboard |
environment | TingeeEnvironment | PRODUCTION | UAT | PRODUCTION |
baseUrl | String | — | Ghi đè URL (bỏ qua environment) |
timeout | int | 90000 | Timeout (ms) |
using Tingee.Sdk.Client;
var client = new TingeeClient(new TingeeClientOptions
{
SecretKey = Environment.GetEnvironmentVariable("TINGEE_SECRET_KEY")!,
ClientId = Environment.GetEnvironmentVariable("TINGEE_CLIENT_ID")!,
Environment = TingeeEnvironment.Production, // Uat | Production
// BaseUrl = "https://custom-url.example.com", // ghi đè Environment
});
| Thuộc tính | Kiểu | Mặc định | Mô tả |
|---|---|---|---|
SecretKey | string | — | Bắt buộc. Secret key từ Tingee Dashboard |
ClientId | string | — | Bắt buộc. Client ID từ Tingee Dashboard |
Environment | TingeeEnvironment | Production | Uat | Production |
BaseUrl | string? | — | Ghi đè URL (bỏ qua Environment) |
TimeoutMilliseconds | int | 90000 | Timeout (ms) |
<?php
require_once 'vendor/autoload.php';
use Tingee\Sdk\TingeeClient;
$client = new TingeeClient(
secretKey: $_ENV['TINGEE_SECRET_KEY'],
clientId: $_ENV['TINGEE_CLIENT_ID'],
environment: 'prod', // 'prod' | 'uat'
timeout: 90, // giây, mặc định 90
// baseUrl: 'https://custom-url.example.com', // ghi đè environment
);
| Tham số | Kiểu | Mặc định | Mô tả |
|---|---|---|---|
secretKey | string | — | Bắt buộc. Secret key từ Tingee Dashboard |
clientId | string | — | Bắt buộc. Client ID từ Tingee Dashboard |
environment | string | 'prod' | 'prod' | 'uat' |
timeout | int | 90 | Timeout (giây) |
baseUrl | string|null | — | Ghi đè URL (bỏ qua environment) |
Bảo mật quan trọng
secretKey chỉ được dùng phía server. Không nhúng vào frontend, mobile app hay bất kỳ môi trường client-side nào.
Tích hợp Framework
- Node.js (NestJS)
- Java (Spring Boot)
- C# (ASP.NET Core)
- PHP (Laravel)
// tingee.module.ts
import { Module, Global } from '@nestjs/common';
import { TingeeClient } from '@tingee/sdk-node';
@Global()
@Module({
providers: [
{
provide: TingeeClient,
useFactory: () => new TingeeClient({
secretKey: process.env.TINGEE_SECRET_KEY!,
clientId: process.env.TINGEE_CLIENT_ID!,
}),
},
],
exports: [TingeeClient],
})
export class TingeeModule {}
@Configuration
public class TingeeConfig {
@Bean
public TingeeClient tingeeClient(
@Value("${tingee.secret-key}") String secretKey,
@Value("${tingee.client-id}") String clientId) {
return TingeeClient.builder(secretKey, clientId)
.environment(TingeeEnvironment.PRODUCTION)
.build();
}
}
# application.yml
tingee:
secret-key: ${TINGEE_SECRET_KEY}
client-id: ${TINGEE_CLIENT_ID}
// Program.cs
builder.Services.AddSingleton(new TingeeClientOptions
{
SecretKey = builder.Configuration["Tingee:SecretKey"]!,
ClientId = builder.Configuration["Tingee:ClientId"]!,
Environment = TingeeEnvironment.Production,
});
builder.Services.AddSingleton<TingeeClient>();
// appsettings.json
{
"Tingee": {
"SecretKey": "your-secret-key",
"ClientId": "your-client-id"
}
}
// AppServiceProvider.php
use Tingee\Sdk\TingeeClient;
public function register(): void
{
$this->app->singleton(TingeeClient::class, fn () => new TingeeClient(
secretKey: config('services.tingee.secret_key'),
clientId: config('services.tingee.client_id'),
environment: config('services.tingee.environment', 'prod'),
));
}
// config/services.php
'tingee' => [
'secret_key' => env('TINGEE_SECRET_KEY'),
'client_id' => env('TINGEE_CLIENT_ID'),
'environment' => env('TINGEE_ENV', 'prod'),
],