In-App Purchase
Purchase products and retrieve product information through the native App Store / Google Play in-app purchase flow. Supports both consumable and non-consumable product types.
Access: startiapp.InAppPurchase
For a step-by-step guide to setting up in-app purchases — see Setup In-App Purchases.
Methods
purchaseProduct(productId, purchaseType): Promise<InAppPurchaseResponse<InAppPurchaseProductResponse>>
Initiates a native purchase flow for the specified product. The returned promise resolves after the user completes or cancels the transaction.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| productId | string | Yes | The product identifier as configured in App Store Connect or Google Play Console. |
| purchaseType | InApPurchasePurchaseType | Yes | Whether the product is "consumable" or "nonconsumable". |
Returns: Promise<InAppPurchaseResponse<InAppPurchaseProductResponse>> —A response object indicating success (with a transaction identifier) or failure (with an error message).
Example:
const result = await startiapp.InAppPurchase.purchaseProduct(
"com.example.premium",
"nonconsumable"
);
if (result.success) {
console.log("Transaction ID:", result.value.transactionIdentifier);
} else {
console.error("Purchase failed:", result.errorMessage);
}getProduct(productId, purchaseType): Promise<InAppPurchaseResponse<InAppPurchaseGetProductResponse>>
Retrieves product metadata (name, description, localized price) from the store without initiating a purchase.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| productId | string | Yes | The product identifier as configured in App Store Connect or Google Play Console. |
| purchaseType | InApPurchasePurchaseType | Yes | Whether the product is "consumable" or "nonconsumable". |
Returns: Promise<InAppPurchaseResponse<InAppPurchaseGetProductResponse>> —A response object containing product details on success, or an error message on failure.
Example:
const result = await startiapp.InAppPurchase.getProduct(
"com.example.premium",
"nonconsumable"
);
if (result.success) {
console.log(`${result.value.name} - ${result.value.localizedPrice}`);
} else {
console.error("Failed to load product:", result.errorMessage);
}Types
InApPurchasePurchaseType
Union type specifying the kind of in-app purchase product.
type InApPurchasePurchaseType = "nonconsumable" | "consumable";| Value | Description |
|---|---|
"nonconsumable" | A one-time purchase that does not expire (e.g., unlock a feature). |
"consumable" | A purchase that can be bought multiple times (e.g., in-game currency). |
InAppPurchaseResponse<T>
Discriminated union returned by all purchase methods. Check the success field to determine which shape you have.
type InAppPurchaseResponse<T> =
| { success: true; value: T }
| { success: false; errorMessage: string };InAppPurchaseProductResponse
Payload returned on a successful purchaseProduct call.
type InAppPurchaseProductResponse = {
/** Unique identifier for the completed transaction. */
transactionIdentifier: string;
};InAppPurchaseGetProductResponse
Payload returned on a successful getProduct call.
type InAppPurchaseGetProductResponse = {
/** Display name of the product. */
name: string;
/** Product description. */
description: string;
/** Price formatted for the user's locale (e.g., "$4.99"). */
localizedPrice: string;
/** ISO 4217 currency code (e.g., "USD", "EUR"). */
currencyCode: string;
};External Purchase
Manage Apple's External Purchase Custom Link entitlement (StoreKit external purchase API). This module lets you check eligibility, retrieve purchase tokens, display the mandatory Apple disclosure notice, and redirect the user to an external purchase page.
Location
Access the device GPS, track location changes in real time, and set up geofences that trigger events when the user enters or exits a region.