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
  }
})

Error codes

Error code

Sub error code

Error message

13000

--

Environment check failed - Connection to Apple/Google Store failed

13001

--

Environment check failed - Timeout

13002

--

Environment check failed - Device not supported

13003

--

Environment check failed - Device not supported

13013

--

IAP Payment - FAILED

13014

--

When checking the consumption order, the server returns an incorrect order status

30001

--

IAP Payment - CANCEL

30002

--

IAP Payment - PENDING

30003

--

User actively closes the panel

30004

--

Users repeatedly click on products, and third parties repeatedly call JSB

20000

--

Network issue

20012

Check consumption list, API network failure

20013

Check balance, API network failure

20014

Failed to obtain the recommended gear due to API network failure

20015

Consumed beans, API network failed

20021

Check subscription list, API network failure

20022

Unsubscribe, API network failure

50000

--

System Error

50001

Tier info error

50002

Failed to pull up the panel

50004

Check order timeout

50007

Server returned a status code error

Other

--

Server error


Was this document helpful?
TikTok for Developers