starti.app
API Reference

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:

ParameterTypeRequiredDescription
productIdstringYesThe product identifier as configured in App Store Connect or Google Play Console.
purchaseTypeInApPurchasePurchaseTypeYesWhether 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:

ParameterTypeRequiredDescription
productIdstringYesThe product identifier as configured in App Store Connect or Google Play Console.
purchaseTypeInApPurchasePurchaseTypeYesWhether 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";
ValueDescription
"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;
};

On this page