topuplive
v0.1.2
Published
topuplive api
Downloads
198
Readme
TOPUPLIVE API Client
This project is a TypeScript-based API client for interacting with the TOPUPLIVE platform. It provides functions for account management, product inquiries, order creation, and exchange rate queries. The client uses AES encryption for secure data transmission.
Table of Contents
Installation
To install the necessary packages, run:
npm install
Configuration
Before using the API functions, you must set up the configuration with your credentials.
Set Configuration
import TOPUPLIVE from "./src";
TOPUPLIVE.setConfig({
secretId: "your_secret_id",
secretKey: "your_secret_key",
HOST: "http://your-host-url.com",
logger: true, // Optional: Enable logging for debugging
});
Usage
After setting up the configuration, you can use the various functions provided by the client to interact with the TOPUPLIVE API.
API Functions
Account
fetchAccount
Fetches the account details of the user.
Request Parameters: None
Response Type:
interface AccountData { currency: string; balance: number; frozen: number; total_recharge: number; total_withdraw: number; total_income: number; total_expend: number; }
Example:
const account = await TOPUPLIVE.account.fetchAccount(); console.log(account);
Product
fetchProductList
Fetches a paginated list of available products.
Request Parameters:
interface ProductListRequest { page?: number | string; // Default is 1 }
Response Type:
ProductData[]
Example:
const productList = await TOPUPLIVE.product.fetchProductList("1"); console.log(productList);
fetchCategory
Fetches a specific product category.
Request Parameters:
interface CategoryRequest { order_no: string; // Required, example: "10031001" }
Response Type:
interface CategoryData { [categoryId: string]: string; // Category ID to name mapping }
Example:
const category = await TOPUPLIVE.product.fetchCategory("10031001"); console.log(category);
fetchDetails
Fetches detailed information for a specific product.
Request Parameters:
interface ProductDetailsRequest { product_id: string; // Required }
Response Type:
interface ProductDetailsData { product_id: string; product_name: string; description: string; price: string; currency: string; additional_details: object; // Depending on product type }
Example:
const productDetails = await TOPUPLIVE.product.fetchDetails("10031001"); console.log(productDetails);
Order
fetchOrderVerification
Verifies recharge information before creating an order.
Request Parameters:
interface OrderVerificationRequestParams { product_id: string; charge_account: string; // Optional parameters: charge_password?: string; charge_game?: string; charge_region?: string; charge_server?: string; charge_type?: string; role_name?: string; buyer_ip?: string; }
Response Type:
interface OrderVerificationData { result: string; user_id?: string; user_name?: string; user_image?: string; }
Example:
const verification = await TOPUPLIVE.order.fetchOrderVerification({ product_id: "10000587", charge_account: "user_account", }); console.log(verification);
createOrder
Creates an order for a product.
- Request Parameters:
| Field | Type | Required | Description | | ------------------ | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | timestamp | int | Yes | Timestamp, example: 1603872737 | | product_id | string | Yes | Product ID | | buy_num | string | Yes | Purchase quantity | | charge_account | string | No | Recharge account (provided according to the product template) | | charge_password | string | No | Recharge password (provided according to the product template) | | charge_game | string | No | Recharge game (provided according to the product template) | | charge_region | string | No | Recharge region (provided according to the product template) | | charge_server | string | No | Recharge server (provided according to the product template) | | charge_type | string | No | Recharge type (provided according to the product template) | | role_name | string | No | Role name (provided according to the product template) | | contact_phone | string | No | Contact phone number | | contact_qq | string | No | Contact QQ number | | buyer_ip | string | No | Buyer's IP address | | user_order_id | string | Yes | User order ID | | user_notify_url | string | No | User callback URL | | order_max_amount | string | No | Maximum order cost amount. Used for cost control. If omitted or set to 0, verification is skipped. If greater than 0, the API will check if this value is greater than or equal to the purchase amount. | | order_max_currency | string | No | Maximum order cost currency. Used in conjunction with the order_max_amount field, e.g., USD. |
Request Parameters:
interface CreateOrderRequestParams { product_id: string; buy_num: string; user_order_id: string; charge_account?: string; contact_phone?: string; buyer_ip?: string; order_max_amount?: string; order_max_currency?: string; }
Response Type:
interface OrderData { order_id: string; product_name: string; status: string; description: string; created_at: string; account?: Record<string, any>; cards?: Array<{ card_no: string; card_pwd: string; card_deadline: string }>; }
Example:
const order = await TOPUPLIVE.order.createOrder({ product_id: "10000587", buy_num: "1", user_order_id: "unique_order_12345", }); console.log(order);
fetchOrderDetails
Fetches details of an existing order.
Request Parameters:
interface OrderDetailsRequestParams { order_id?: string; user_order_id?: string; }
Response Type:
OrderData
Example:
const orderDetails = await TOPUPLIVE.order.fetchOrderDetails({ order_id: "og630874c7c364f", }); console.log(orderDetails);
fetchOrderList
Fetches a paginated list of orders for a specified time period.
Request Parameters:
interface OrderListRequestParams { start_time: string; end_time: string; per_page?: string; page?: string; status_code?: string; // Optional: 1 for processing, 2 for success, 3 for failure }
Response Type:
interface OrderListData { current_page: number; data: OrderData[]; total: number; }
Example:
const orderList = await TOPUPLIVE.order.fetchOrderList({ start_time: "2023-10-01", end_time: "2023-10-31", status_code: "2", }); console.log(orderList);
fetchOrderVoucher
Fetches vouchers related to a specific order.
Request Parameters:
interface OrderVoucherRequestParams { order_id?: string; user_order_id?: string; }
Response Type:
string[]
(Array of voucher URLs)Example:
const orderVoucher = await TOPUPLIVE.order.fetchOrderVoucher({ user_order_id: "unique_order_12345", }); console.log(orderVoucher);
Exchange
fetchExchangeRates
Fetches the current exchange rates used by the platform.
Request Parameters: None
Response Type:
interface ExchangeRatesData { updated_at: string; cny_rate: { [currencyCode: string]: string; // Exchange rates by currency code }; }
Example:
const exchangeRates = await TOPUPLIVE.exchange.fetchExchangeRates(); console.log(exchangeRates);
Error Handling
Each function returns an ApiResponse
with the following structure:
interface ApiResponse<T = any> {
success: boolean;
data: T | null;
}
success
:true
if the request was successful,false
otherwise.data
: Contains the response data if successful;null
if there was an error.
In case of an error, check the success
property before accessing data
.
This README.md
provides an overview of each function, its parameters, and expected responses. Adjust examples as needed for your specific use case. Happy coding!