Hooks

purchase() / products()

Initiate a standalone purchase and fetch store product details outside of a paywall.

Purpose

purchase() initiates a purchase for a given product identifier without presenting a paywall. If the product isn't found or the native purchase fails, it resolves with a { type: "failed", error } result instead of rejecting. products() fetches store product details (price, trial info, localized strings) for an array of product identifiers, matching the native StoreProduct.toJson() shape on both iOS and Android. Results follow the requested identifier order, and unknown identifiers are omitted.

When using a custom PurchaseController, calling purchase() triggers a double round-trip between JS and native (JS → native → JS → native). The native SDK calls the purchase controller's purchaseFromAppStore or purchaseFromGooglePlay method, which must then call didPurchase() back to the native module. This is an inherent limitation of the bridge architecture.

Signature

Hook usage:

const { purchase, products } = useSuperwall()

await purchase(product: string | ProductResponse): Promise<PurchaseResultResponse>
await products(productIds: string[]): Promise<ProductResponse[]>

Compat API usage:

import Superwall from "expo-superwall/compat"

await Superwall.purchase(product: string | ProductResponse | StoreProduct): Promise<PurchaseResultResponse>
await Superwall.products(productIds: string[]): Promise<ProductResponse[]>

Since v1.9.0, purchase() also takes a product returned by products(), or a compat StoreProduct. On Android, a product object is bought with its own base plan and offer (its fullIdentifier). The compat Superwall.purchase() and Superwall.products() now wait for configure to finish instead of failing when called early.

Parameters

Prop

Type

Returns / State

PurchaseResultResponse

Prop

Type

ProductResponse

Prop

Type

Since v1.9.0, products also have attributes and customTransactionId, plus the iOS-only introductoryDiscount, discounts, billingPlanType, isBillingPlanAvailable and entitlements, and the Android-only productType, storeFrontCountryCode and isCustomProduct. See ProductResponse for each field.

Usage

import { useSuperwall } from "expo-superwall"

function CoinShop() {
  const { purchase, products } = useSuperwall()

  const loadPrices = async () => {
    const items = await products(["coins_100", "coins_500"])
    items.forEach((p) => console.log(p.productIdentifier, p.localizedPrice))
  }

  const buyCoins = async () => {
    // Pass the identifier, or a product returned by products()
    const result = await purchase("coins_100")
    if (result.type === "purchased") {
      await grantCoins(100)
    } else if (result.type === "failed") {
      console.error("Purchase failed:", result.error)
    }
  }

  return (
    <>
      <Button title="Load prices" onPress={loadPrices} />
      <Button title="Buy 100 coins" onPress={buyCoins} />
    </>
  )
}
  • useSuperwall - Hook access to the main Expo SDK store.
  • Consumable Products - Set up consumable products for Superwall paywalls.
  • consume() - Consume a Google Play purchase token after granting a consumable benefit.

How is this guide?

On this page