Copy this into your coding assistant and add your request.
Read https://openiap.dev/docs/features/validation 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]
Check each purchase with a trusted verifier before you grant access; local StoreKit or Play Billing state alone can be faked. Pick the verifier that fits your app. In the framework SDKs, the purchase flow (createPurchaseFlow; create_purchase_flow in Godot, CreatePurchaseFlow in MAUI) then confirms, finishes, and recovers purchases for you. With the native Swift and Kotlin packages, call the verifier yourself and finish the purchase after you grant access.
Your app
Verify with
Call
Has its own backend that owns user accounts
Your backend. It checks with the store itself or calls any Commerce Protocol provider.
createPurchaseFlow with a confirmWithBackend function that calls your server
Has no backend
A verification service called from the app: IAPKit through the SDK, or any Commerce Protocol provider with its verification credential.
For IAPKit, createPurchaseFlow with confirmWithIapkit, or verifyPurchaseWithProvider for one call. For another provider, a confirmWithBackend function that calls its verifyPurchase
Sells on the App Store only, with no backend or service
StoreKit on the device. Weaker: a patched app can skip it.
createPurchaseFlow with confirmOnDeviceIOS
Is a paid download
StoreKit AppTransaction on iOS; on Android, your backend decodes the Play Integrity token
The framework SDKs' purchase flow listens for purchases, confirms each one, finishes it once access is granted, recovers unfinished purchases, and reports each outcome. Without a backend of your own, pass confirmWithIapkit with your publishable key, or confirmOnDeviceIOS for App Store purchases StoreKit verified on the device, and credit consumables in its grant callback, which runs before the purchase is consumed. See the purchase flow guide on the IAPKit site.
When your own backend owns user accounts, pass confirmWithBackend. It receives the purchase and whether it is consumable, then returns its confirmation. Answer entitled once access is granted, crediting a consumable first, verification_delayed for an answer that may still change, and invalid only for a settled rejection, which iOS then finishes. A confirmer that throws or times out leaves the purchase unfinished, and the next delivery or recovery confirms it again.
Your backend may check with the store itself or call any verification service. Before reporting a valid verdict, it must bind the store-verified evidence to the intended store and provider, the expected product, and an allowed environment. Use the adapter's documented product mapping, such as a subscription term to its parent SKU. Choose allowed stores, providers, and environments from trusted backend configuration; client-supplied values are not proof. Missing or mismatched evidence must throw, leaving the purchase unfinished for investigation and retry. In the example below, myVerifier.verify performs these checks before returning valid and maps store SKUs back to the app's product IDs. The callback also checks that the returned evidence belongs to this purchase. This production example accepts only Production receipts; the backend must enforce the same policy. The other tabs show the server call itself, for a purchase flow's confirm function or for the native packages, which finish the purchase after you grant access.
swift
import OpenIAP
// yourBackend is your authenticated client; your server checks the JWS.
// Throws on network errors: an error is not an invalid purchase.
func verifyOnServer(_ purchase: PurchaseIOS) async throws -> Bool {
let verdict = try await yourBackend.verifyApplePurchase(
productId: purchase.productId,
jws: purchase.purchaseToken ?? ""
)
// Fail closed: require the store-verified product id.
return verdict.isValid && verdict.productId == purchase.productId
}
Verify a purchase through IAPKit's own verification API, the only provider this call supports. To use another provider, call its Commerce Protocol verifyPurchase. Pass the evidence for the store that sold the purchase, and require the returned store-verified productId to match the product you expected; isValid alone is not enough.
Configure the key
Use an openiap-kit_pk_ publishable key, never an openiap-kit_sk_ secret key. Pass it as apiKey, or let Expo and React Native read it from config: Expo from the config plugin option iapkitApiKey, React Native from IAPKitAPIKey in Info.plist and <meta-data android:name="dev.iapkit.API_KEY" android:value="openiap-kit_pk_…" /> in AndroidManifest.xml.
Example
The local purchase ID is the expected value, never a fallback when verification omits the ID.
For Amazon, send that expected value as iapkit.amazon.expectedProductId. Amazon App Tester receipts also require enabling Allow Amazon App Tester / RVS Cloud Sandbox in the IAPKit project before passing sandbox: true. Handled Amazon results report exactly 'Sandbox' or 'Production' in environment; require the value expected by the build.
Amazon Live App Testing (LAT) uses real RVS with sandbox: false, but a valid test receipt reports Sandbox. With confirmWithIapkit, set amazon.expectedEnvironment: 'Sandbox' in the LAT build. Leave it unset for production. This option checks the returned verdict; it never changes the RVS endpoint or travels in the verification request. Rebuild without the Sandbox setting before submitting to production; promoting the LAT binary unchanged would reject real purchases after payment. Missing or mismatched final environments do not grant access or finish the purchase.
swift
import OpenIAP
// Throws on network errors: an error is not an invalid purchase.
func verifyWithIapkit(_ purchase: PurchaseIOS) async throws -> Bool {
let result = try await OpenIapModule.shared.verifyPurchaseWithProvider(
VerifyPurchaseWithProviderProps(
iapkit: RequestVerifyPurchaseWithIapkitProps(
apiKey: "openiap-kit_pk_<your-publishable-key>",
apple: RequestVerifyPurchaseWithIapkitAppleProps(
jws: purchase.purchaseToken ?? ""
)
),
provider: .iapkit
)
)
// Fail closed: require the store-verified product id.
guard let verified = result.iapkit else { return false }
return verified.isValid && verified.productId == purchase.productId
}
Optional product client payload
Set iapkit.includeClientPayload to true to request the product's public IAPKit payload. The default is false. IAPKit returns clientPayload only when Apple or Google verifies the receipt as valid, the store supplies the product ID, and the matching IAPKit product is currently present, not removed, and has a payload. Invalid receipts, absent or removed products, missing payloads, Horizon, and Amazon responses omit the field. A retained payload becomes eligible again after store sync re-pulls its matching product.
This is request/response retrieval, not an APNs or FCM push. To fetch rules when the app opens without verifying a new purchase, use the React Native or Expo kitApi product methods, or MAUI's KitApiClient, as described in Product client payloads.
State contract
Only entitled, pending-acknowledgment, and ready-to-consume make isValid true, but they are not interchangeable across stores or product types. Use the platform-aware flow under Error handling, and see the canonical IapkitPurchaseState reference for every state.
The Commerce Protocol is an open server API built so verification providers, paywall and data services, and your own backend can work together through one contract. Any provider that implements it can verify purchases for your backend, and so can your own server. Choose by what a provider supports, not by name: compare capability descriptors for the stores and profiles you need.
IAPKit is one of these providers: open source (MIT), managed by OpenIAP, and hosted at kit.openiap.dev or self-hosted from packages/kit. It is also the service the SDKs' verifyPurchaseWithProvider and confirmWithIapkit call directly. What that call needs:
Store credentials (the App Store key, the Google service account) stay in the IAPKit project; the app ships only a publishable key.
It covers the App Store, Google Play, Amazon Appstore (Fire OS and Vega OS, through the iapkit.amazon payload), and Meta Horizon.
The result reports one state (entitled, pending, canceled, expired, inauthentic, and others). SDK string values are kebab-case (pending-acknowledgment); IAPKit's REST API spells the same states in upper snake case (PENDING_ACKNOWLEDGMENT).
Verify a purchase on the device with explicit platform options. The current API accepts apple, google, or horizon; it does not accept a Purchase object or a server URL.
let result = try await OpenIapModule.shared.verifyPurchase(
VerifyPurchaseProps(
apple: VerifyPurchaseAppleOptions(sku: purchase.productId)
)
)
if case let .verifyPurchaseResultIos(iosResult) = result,
iosResult.isValid {
await grantEntitlement(purchase.productId)
}
This example targets App Store and Google Play builds. Fire OS and Vega OS builds must select the amazon verification branch; their consumables use ready-to-consume like Apple.
ts
import { Platform } from 'react-native';
try {
// App Store / Google Play only; route Fire OS and Vega OS through Amazon.
const isApple = Platform.OS === 'ios';
// Resolve this from your app-owned catalog, never from the harmonized state.
const isConsumable = isConsumableProduct(purchase.productId);
const token = purchase.purchaseToken ?? '';
const result = await verifyPurchaseWithProvider({
provider: 'iapkit',
iapkit: {
apiKey: 'your-key',
...(isApple
? { apple: { jws: token } }
: { google: { purchaseToken: token } }),
},
});
const verified = result.iapkit;
const verifiedProductId = verified?.productId;
const productMatches =
verifiedProductId != null && verifiedProductId === purchase.productId;
const stateAllowsFulfillment = isConsumable
? isApple
? verified?.state === 'ready-to-consume'
: verified?.state === 'ready-to-consume' ||
verified?.state === 'entitled' ||
verified?.state === 'pending-acknowledgment'
: verified?.state === 'entitled' ||
(!isApple && verified?.state === 'pending-acknowledgment');
if (
verified?.isValid === true &&
productMatches &&
stateAllowsFulfillment
) {
if (isConsumable) {
// Persist idempotent delivery before consuming so it cannot be lost.
await deliverConsumable(verifiedProductId);
await finishTransaction({ purchase, isConsumable: true });
} else {
await grantEntitlement(verifiedProductId);
await finishTransaction({ purchase, isConsumable: false });
}
} else {
// IAPKit completed the check but did not verify this entitlement.
// Do not grant or finish this purchase.
recordRejectedVerification(purchase, verified);
}
} catch (error) {
// A network/server error is not proof that the purchase is invalid.
console.error('Verification failed:', error);
// Keep only access established by an earlier successful verification.
// Do not grant this purchase or finish it; retry verification later.
preservePreviouslyVerifiedEntitlements();
scheduleVerificationRetry(purchase);
}