React Native · APIs and utilities
In-app purchases
Purchase API.
Import
Purchases
modulePurchase API. Flow: get products → purchase → deliver the content (preferably verify the token on your server) → finish with finish. An unfinished transaction is refunded after 3 days on Android, and comes back on every launch on iOS.
| Name | Type | Description |
|---|---|---|
canMakePayments | () => boolean | Whether the device allows purchases (parental controls etc.). |
getProducts | (ids: readonly string[]) => Promise<Product[]> | Store products (by App Store Connect / Play Console ids). Ones not found are not in the list. |
purchase | (productId: string, options?: PurchaseOptions) => Promise<Purchase> | Purchases. On success deliver the content and call Purchases.finish. |
finish | (purchase: Purchase, { consume }?: { consume?: boolean; }) => Promise<void> | Finishes a transaction. consume: true makes a consumable product (coins, lives…) purchasable again; do not pass it for subscriptions and permanent products. |
getActive | () => Promise<Purchase[]> | Owned products and active subscriptions (including unfinished transactions). |
restore | () => Promise<Purchase[]> | Restores purchases (syncs with the store on iOS; for a "Restore purchases" button). |
manageSubscriptions | (productId?: string) => Promise<void> | Subscription management screen (a sheet on iOS, Play Store on Android). |
addUpdateListener | (listener: (purchase: Purchase) => void) => () => void | Transactions completed outside the app: payments awaiting approval, renewals, refunds, purchases from another device. Listen as soon as the app opens. |
useProducts
functionLoads products.
useActivePurchases
functionOwned products; updated with update events and refresh. onPurchase gives a newly arrived transaction (completed outside the app): deliver the content and finish it.
ProductType
typeProduct type. iOS knows the type; on Android one-time products are oneTime (you tell whether it is consumable with consume when finishing).
ProductPeriod
interfacePeriod.
| Name | Type | Description |
|---|---|---|
unit | "day" | "week" | "month" | "year" | Unit. |
value | number | Number of units. |
SubscriptionOffer
interfaceA subscription offer.
| Name | Type | Description |
|---|---|---|
id | string | null | iOS promotional id / Android offer or base plan id; null for an introductory offer. |
token? | string | Android: offer token to pass when purchasing. |
basePlanId? | string | Android: base plan. |
tags? | string[] | Android: offer tags. |
price? | string | iOS: formatted price. |
priceAmount? | number | iOS: price as a number. |
period? | ProductPeriod | iOS: period and count, payment mode. |
periodCount? | number | iOS: number of periods. |
paymentMode? | "freeTrial" | "payAsYouGo" | "payUpFront" | iOS: payment mode. |
phases? | { price: string; priceAmount: number; currency: string; period: ProductPeriod; cycles: number; recurring: boolean; }[] | Android: pricing phases (trial → discount → regular). |
Product
interfaceA store product.
| Name | Type | Description |
|---|---|---|
id | string | Product id in the store. |
type | ProductType | Product type. |
title | string | Name in the store. |
description | string | Description in the store. |
price | string | Formatted price ("$4.99"). |
priceAmount | number | Price as a number. |
currency | string | Currency code (ISO 4217). |
subscription? | { period: ProductPeriod | null; /** iOS subscription group. */ groupId?: string; /** iOS introductory offer (trial). */ introductoryOffer?: SubscriptionOffer | null; offers: SubscriptionOffer[]; } | Subscription details; only for subscriptions. |
Purchase
interfaceA purchase / transaction.
| Name | Type | Description |
|---|---|---|
id | string | iOS transaction id / Android order id. |
productId | string | Purchased product id. |
date | number | Purchase time (ms, epoch). |
state | "purchased" | "pending" | "pending" while payment is awaited (e.g. parental approval). |
token | string | For server verification: iOS JWS (jwsRepresentation), Android purchaseToken. On Android it is also used when finishing. |
quantity | number | Quantity. |
originalId? | string | iOS: the original transaction (the same across renewals). |
expirationDate? | number | null | iOS subscription expiry (ms). |
revoked? | boolean | iOS: refunded. |
environment? | string | iOS: Sandbox, Production, Xcode. |
appAccountToken? | string | null | iOS: account token given at purchase. |
productIds? | string[] | Android. |
acknowledged? | boolean | Android: whether the purchase is acknowledged. |
autoRenewing? | boolean | Android: whether the subscription renews automatically. |
signature? | string | Android: purchase signature (for server verification). |
originalJson? | string | Android: raw purchase JSON (for server verification). |
PurchaseOptions
interfaceOptions of Purchases.purchase.
| Name | Type | Description |
|---|---|---|
offerToken? | string | Android subscription offer (product.subscription.offers[i].token); the base plan if omitted. |
appAccountToken? | string | iOS: matching with the user account (UUID). |
accountId? | string | Android: obfuscated account id (for comparison). |
profileId? | string | Android: obfuscated profile id. |
quantity? | number | iOS: quantity. |
Error codes: E_CANCELLED (the user cancelled), E_PENDING (awaiting approval/payment; the result arrives with the update event), E_ALREADY_OWNED, E_NOT_FOUND, E_UNAVAILABLE (no store, or Google Play Billing is unavailable), E_NETWORK, E_UNVERIFIED, E_PURCHASE.