starti.app
How-to Guides

Set Up In-App Purchases

Offer in-app purchases for consumable and non-consumable products on iOS and Android

Set Up In-App Purchases

Use the SDK to offer in-app purchases for consumable and non-consumable products on iOS and Android.

Prerequisites

  • The starti.app SDK is installed and initialized
  • Products are configured in App Store Connect and/or Google Play Console
  • Product IDs match between the store and your code

Get product details

Fetch a product's name, description, and localized price before displaying it to the user:

const result = await startiapp.InAppPurchase.getProduct(
  "com.example.premium",
  "nonconsumable",
);

if (result.success) {
  console.log("Name:", result.value.name);
  console.log("Price:", result.value.localizedPrice);
  console.log("Currency:", result.value.currencyCode);
  console.log("Description:", result.value.description);
} else {
  console.error("Error:", result.errorMessage);
}

Purchase a product

const result = await startiapp.InAppPurchase.purchaseProduct(
  "com.example.premium",
  "nonconsumable",
);

if (result.success) {
  console.log("Transaction ID:", result.value.transactionIdentifier);
  // Validate the transaction on your backend
} else {
  console.error("Purchase failed:", result.errorMessage);
}

Purchase types

TypeDescription
"nonconsumable"Bought once, permanent (e.g., premium upgrade, remove ads)
"consumable"Can be purchased multiple times (e.g., coins, credits)

Complete example

await startiapp.initialize();

const productId = "com.example.premium";

// Show product info
const product = await startiapp.InAppPurchase.getProduct(productId, "nonconsumable");
if (product.success) {
  document.getElementById("price").textContent = product.value.localizedPrice;
}

// Handle purchase
document.getElementById("buy-btn").addEventListener("click", async () => {
  const result = await startiapp.InAppPurchase.purchaseProduct(
    productId,
    "nonconsumable",
  );

  if (result.success) {
    // Send transaction ID to your backend for validation
    await fetch("/api/validate-purchase", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        transactionId: result.value.transactionIdentifier,
        productId,
      }),
    });
  }
});

Always validate purchases on your backend. Do not trust client-side purchase results alone.

See also

On this page