const iapToken = await Koji.iap.getToken();
Manages in-app purchase transactions on the frontend of your Koji app.
Generates an IAP token for the current user that can be used to resolve receipts on the backend.
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.
Promise<String>, Short-lived IAP token for the current user.
const iapToken = await Koji.iap.getToken();
Source: frontend/iap/index.ts#L43
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).
|
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.
Promise<Purchase>, Results of the in-app purchase transaction.
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
Results of an in-app purchase transaction.
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.
Optional information to add to a {@doclink core-backend-iap#IapReceipt | transaction receipt} for a given in-app purchase.
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.