Use this page with AI
Copy this into your coding assistant and add your request.
Read https://openiap.dev/docs/apis/get-available-purchases and https://openiap.dev/llms.txt. Follow the reading instructions, detailed reference, and linked guides relevant to my task before making changes.
Inspect my existing project and reuse its framework and conventions. Ask me for missing product decisions. Implement the requested behavior and run the applicable checks.
Show the working result, the commands and actual test results, and any remaining limitations. Keep your explanation brief.
My request: [describe what customers should be able to do]getAvailablePurchases
Get the user's purchases held by the store — owned non-consumables, active subscriptions, and any pending transactions not yet finished.
iOS: onlyIncludeActiveItemsIOS: true reads Transaction.currentEntitlements (active non-consumables and live subscriptions); false iterates Transaction.all, the full StoreKit 2 history including refunded and revoked entries. The default differs by layer; see Parameters. Apple docs. Android: Calls BillingClient.queryPurchasesAsync for both INAPP and SUBS and merges. Only returns purchases still owned by the user. Google docs.
Signature
func getAvailablePurchases(_ options: PurchaseOptions?) async throws -> [Purchase]Parameters#
Pass an optional PurchaseOptions:
alsoPublishToEventListenerIOS(optional,boolean, defaultfalse) — iOS. Publish verified purchases onpurchaseUpdatedListener, including when another entry fails verification. See Failure semantics.onlyIncludeActiveItemsIOS(optional,boolean; defaulttruein React Native, Expo, Flutter, and MAUI,falsein Swift, KMP, and Godot) — iOS.trueusesTransaction.currentEntitlements(active only);falseusesTransaction.all. Pass it explicitly when the difference matters.includeSuspendedAndroid(optional,boolean, defaultfalse) — Android (Billing 8.1+). Include suspended subscriptions in the result. Suspended entries (isSuspendedAndroid === true) should NOT grant entitlements — direct the user to the subscription center to resolve payment first.
Returns#
Promise<Purchase[]> — owned/available purchases held by the store.
Failure semantics#
In SDK APIs that surface failures and in Godot's result-bearing API, an empty purchase list is an authoritative store result: the store query completed and found no purchases. Native transaction verification, serialization, or bridge decoding failures reject the whole query (or return success = false) with an error such as billing-response-json-parse-error; OpenIAP does not return a partial list.
On iOS, set alsoPublishToEventListenerIOS: true to recover individually verified purchases through purchaseUpdatedListener even when another transaction fails verification. Unverified transactions are never published, and the query still rejects. Reconcile each delivered purchase with your verifier before granting access or finishing it. Keep the listener attached: callbacks can arrive after the query rejects. The default option remains false.
Godot keeps get_available_purchases() for compatibility, so that array-only method still maps a failure to an empty array. Code that restores purchases, grants entitlements, or clears cached ownership must call get_available_purchases_result() and check success before using purchases. Never revoke or clear entitlements after a failed query.
Example
let purchases = try await OpenIapModule.shared.getAvailablePurchases(nil)See: Purchase