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. 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.
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(productId: string): Promise<PurchaseResultResponse>
await products(productIds: string[]): Promise<ProductResponse[]>Compat API usage:
import Superwall from "expo-superwall/compat"
await Superwall.purchase(productId: string): Promise<PurchaseResultResponse>
await Superwall.products(productIds: string[]): Promise<ProductResponse[]>Parameters
Prop
Type
Returns / State
PurchaseResultResponse
Prop
Type
ProductResponse
Prop
Type
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 () => {
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} />
</>
)
}Related
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?