TikTok for Developers

Docs

In-App Purchases

These APIs manage the user's TikTok token (Beans) balance and initiate payment processes for in-app purchases (IAP).

API

Description

Key parameter

Context

checkBalance(opts)

Views the user's current token balance and determines if they have sufficient funds for a specific purchase amount.

amount, type: "BEANS"

Returns a boolean is_sufficient.


recharge(opts)

Initiates the platform's recharge process, allowing the user to purchase more tokens (Beans) within the game.

tier_id (The ID of the coin package)


Launches the native TikTok payment flow for buying tokens.

pay(opts)

Initiates the payment process for a specific game item using the user's existing token balance.

trade_order_id(payment order number)

The trade_order_id is generated by your backend server, but the payment itself is handled by this client API.

.navigateToBalance(opts)

Jumps the user directly to their TikTok user Balance details page (e.g., to view transaction history or current token count).

type: "BEANS"


Provides navigation utility for the user.

.checkBalance(opts)

Views the user's current token balance and determines if they have sufficient funds for a specific purchase amount.

Parameters

  • Amount: Queried amount
type Amount = number;
  • Type: Token type, currently only BEANS
type BalanceType = 'BEANS';
  • Success: Execute a successful return
type SuccessHandler = (result: {
  is_sufficient: boolean;
}) => void;
  • Fail: Return the failed execution
type FailHandler = (result: {
  error: {
    error_code: number;
    error_msg: string;
    error_extra: Record<string, unknown>;
  }
}) => void;
  • Complete : Callback of execution completion (including success and failure)
type CompleteHandler = () => void;

Example

TTMinis.game.checkBalance({
  amount: 50,
  type: "BEANS",
  success: (result) => {
    // Do something with the result
    let is_sufficient = result.is_sufficient;
  },
  error: (error) => {
  // Do something with the error
  }  
})

.recharge(opts)

Initiates the platform's recharge process, allowing the user to purchase more tokens (Beans) within the game.

Parameters

  • tier_id: coin package ID
  • Success : Execute a successful return
type SuccessHandler = ()= void;
  • Fail: Return the failed execution
type FailHandler = (result: {
  error: {
    error_code: number;
    error_msg: string;
    error_extra: Record<string, unknown>;
  }
}) => void;
  • Complete: Execute the completed return
type CompleteHandler = ()= void;

Example

TTMinis.game.recharge({
  tier_id: "{your_tier_id}"
  success: () => {
  // Do something when success criteria are met
  },
  fail: (error) => {
  // Do something when recharge failed
  },
  complete: () => {
  // Do something when recharge is completed
  }
})

.pay(opts)

Initiates the payment process for a specific game item using the user's existing token (Beans) balance.

Parameters

  • trade_order_id: Payment order number
  • Success: Perform successful callbacks
type SuccessHandler = ()= void;
  • Fail: Execute failed callback
type FailHandler = (result: {
  error: {
    error_code: number;
    error_msg: string;
    error_extra: Record<string, unknown>;
  }
}) => void;
  • Complete: Execute the completed callback
  • type CompleteHandler = ()= void;

Example

TTMinis.game.pay({
  trade_order_id: "{your_trade_order_id}",
  success: () => {
  // Do something when success criteria are met
  },
  fail: (error) => {
  // Do something when payment failed
  },
  complete: () => {
  // Do something when payment is completed
  }
})

.navigateToBalance(opts)

Jumps the user directly to their TikTok user Balance details page (to view transaction history or current token count).

Parameters

  • Type: Token type, currently only BEANS
type BalanceType = 'BEANS';
  • Success: Execute a successful return
type SuccessHandler = ()= void;
  • Fail: Return the failed execution
type FailHandler = (result: {
  error: {
    error_code: number;
    error_msg: string;
    error_extra: Record<string, unknown>;
  }
}) => void;
  • Complete: Execute the completed return
type CompleteHandler = ()= void;

Example

TTMinis.game.navigateToBalance({
  type: "BEANS",
  success: () => {
  // Do something when success criteria are met
  },
  fail: (error) => {
  // Do something when action failed
  },
  complete: () => {
  // Do something when action is completed
  }
})


TikTok for Developers