Start typing to search...

IAP

Manages in-app purchase transactions on the frontend of your Koji app.

Methods

.getToken(promptAuth)

Generates an IAP token for the current user that can be used to resolve receipts on the backend.

Parameters

  • promptAuth - Boolean, If true, logged-out users will be prompted to sign in. This is useful for restoring purchases when a user may be logged out (e.g., purchased a product inside TikTok webview, and then later visited the same app via Safari and is no longer logged in), but should only be used when actively requested by a user (e.g., a "Restore Purchases" button). Otherwise, this should be left false to get the token passively.

Returns

Promise<String>, Short-lived IAP token for the current user.

Example

const iapToken = await Koji.iap.getToken();

Source: frontend/iap/index.ts#L43

.startPurchase(sku, purchaseOptions, customAttributes)

Prompts the user to purchase a product from the Koji app. Products are defined in the entitlements file and registered or updated when the project is deployed.

Note
If your IAP product is defined with the captureOnPurchase key set to false, the transaction is held in a pending state until you manually invoke {@doclink core-backend-iap#captureTransaction | Iap.captureTransaction} on the backend of your Koji app. Funds are not available in the seller’s account until the transaction is captured. If you do not capture the transaction before the captureExpiryPeriod, the transaction is automatically reversed and the buyer is refunded. This period can be specified in the product definition from 0 to 7 days (default is 0).

Parameters

  • sku - String, Identifier for the product to purchase.

  • purchaseOptions - PurchaseOptions, Optional information to add to a {@doclink core-backend-iap#IapReceipt | transaction receipt} for a given in-app purchase.

  • customAttributes - [index: string]: any, Optional key-value pairs to add to the receipt. These attribute values can be referenced or updated by resolving receipts on the backend of the Koji app.

Returns

Promise<Purchase>, Results of the in-app purchase transaction.

Example

const purchase = await Koji.iap.startPurchase(sku);

// with optional parameters
const purchase = await Koji.iap.startPurchase(sku, { customMessage: 'Your credit is now available' }, { isConsumed: false });

Source: frontend/iap/index.ts#L80

Interfaces

Purchase

Results of an in-app purchase transaction.

Properties

  • iapToken - String, Short-lived IAP token for the current user. See [[getToken]].

  • receiptId - String (Optional), Unique identifier for the receipt, if the purchase was successful, or `undefined`, if not.

  • success - Boolean, Indicates whether the purchase was successful.

PurchaseOptions

Optional information to add to a {@doclink core-backend-iap#IapReceipt | transaction receipt} for a given in-app purchase.

Properties

  • amount - Number (Optional), Amount of the purchase, in cents.

  • customMessage - String (Optional), Custom message associated with the purchase. This value is stored as a custom attribute on the transaction receipt.