Skip to content

Module: iap

Table of contents

Functions

Functions

consumePurchaseAsync

consumePurchaseAsync(token): Promise<void>

Consumes a specific purchase belonging to the current player. Before provisioning a product's effects to the player, the game should request the consumption of the purchased product. Once the purchase is successfully consumed, the game should immediately provide the player with the effects of their purchase. This will remove the purchase from the player's available purchases inventory and reset its availability in the catalog.

Example

Wortal.iap.consumePurchaseAsync('abc123');

Parameters

Name Type Description
token string The purchase token of the purchase that should be consumed.

Returns

Promise<void>

Promise that resolves when the purchase is successfully consumed. Otherwise, it rejects.

Throws

  • NOT_SUPPORTED
  • CLIENT_UNSUPPORTED_OPERATION
  • PAYMENTS_NOT_INITIALIZED
  • INVALID_PARAM
  • NETWORK_FAILURE

getCatalogAsync

getCatalogAsync(): Promise<Product[]>

Gets the catalog of available products the player can purchase.

Example

Wortal.iap.getCatalogAsync()
 .then(products => console.log(products));

Returns

Promise<Product[]>

Promise that resolves with an array of products available to the player. Returns an empty array if purchases are not supported in the player's region.

Throws

  • NOT_SUPPORTED
  • CLIENT_UNSUPPORTED_OPERATION
  • PAYMENTS_NOT_INITIALIZED
  • NETWORK_FAILURE

getPurchasesAsync

getPurchasesAsync(): Promise<Purchase[]>

Fetches all the player's unconsumed purchases. The game should fetch the current player's purchases as soon as the client indicates that it is ready to perform payments-related operations, i.e. at game start. The game can then process and consume any purchases that are waiting to be consumed.

Example

Wortal.iap.getPurchasesAsync()
 .then(purchases => console.log(purchases));

Returns

Promise<Purchase[]>

Promise that resolves with an array of purchases that the player has made for the game.

Throws

  • NOT_SUPPORTED
  • CLIENT_UNSUPPORTED_OPERATION
  • PAYMENTS_NOT_INITIALIZED
  • NETWORK_FAILURE

isEnabled

isEnabled(): boolean

Checks whether IAP is enabled in this session.

Example

const canShowShop = Wortal.iap.isEnabled();
shopButton.visible = canShowShop;

Returns

boolean

True if IAP is available to the user. False if IAP is not supported on the current platform, the player's device, or the IAP service failed to load properly.


makePurchaseAsync

makePurchaseAsync(purchase): Promise<Purchase>

Begins the purchase flow for a specific product.

Example

Wortal.iap.makePurchaseAsync({
    productID: 'my_product_123',
}).then(purchase => console.log(purchase));

Parameters

Name Type Description
purchase PurchaseConfig The purchase's configuration details.

Returns

Promise<Purchase>

Promise that resolves when the product is successfully purchased by the player. Otherwise, it rejects.

Throws

  • NOT_SUPPORTED
  • CLIENT_UNSUPPORTED_OPERATION
  • PAYMENTS_NOT_INITIALIZED
  • INVALID_PARAM
  • NETWORK_FAILURE
  • INVALID_OPERATION
  • USER_INPUT