npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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

  1. Installation
  2. Configuration
  3. Usage
  4. API Functions
  5. Error Handling

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!