Hooks
queryInAppPurchases()
Query owned one-time Google Play purchases from the Expo SDK.
Purpose
queryInAppPurchases() returns one-time Google Play purchases that the user currently owns in the PURCHASED state. Use it on Android to find consumable purchases that still need to be granted, then call consume() after granting the benefit. Calling this method on iOS rejects because it is Android-only.
Signature
Hooks API:
const { queryInAppPurchases } = useSuperwall()
const purchases = await queryInAppPurchases()Compat API:
import Superwall from "expo-superwall/compat"
const superwall = await Superwall.configure({ apiKey: "YOUR_API_KEY" })
const purchases = await superwall.queryInAppPurchases()Returns
Each result contains the Google Play purchase details:
Prop
Type
Usage
Use an idempotent grant operation keyed by purchaseToken so a purchase is not granted twice if the app retries recovery. Consume the token after the grant succeeds. Only consume products your app treats as consumables.
import { Button, Platform } from "react-native"
import { useSuperwall } from "expo-superwall"
function RecoverPurchases() {
const { queryInAppPurchases, consume } = useSuperwall()
const recover = async () => {
if (Platform.OS !== "android") return
const purchases = await queryInAppPurchases()
for (const purchase of purchases) {
if (!purchase.productIds.includes("coins_100")) continue
await grantCoinsOnce({
purchaseToken: purchase.purchaseToken,
count: 100 * purchase.quantity,
})
await consume(purchase.purchaseToken)
}
}
return <Button title="Recover purchases" onPress={recover} />
}Related
- Consumable Products - Set up and recover consumable purchases.
consume()- Consume a Google Play purchase token after granting its benefit.useSuperwall- Hook access to SDK actions.
How is this guide?