Copy this into your coding assistant and add your request.
Read https://openiap.dev/docs/getting-started 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]
Add purchases to your existing app with the OpenIAP SDK for your framework. Customers can buy products, restore purchases, and use the features they paid for.
Connect, load products, listen for results, then request a purchase. The examples below outline that flow; add your backend verification and access logic. Read Features → Purchase for a full walkthrough with verification, error handling, and consumable/non-consumable nuances.
swift
import OpenIap
let store = OpenIapModule.shared
// 1. Open the store connection on app start.
let connected = try await store.initConnection()
precondition(connected, "Store connection failed")
// 2. Fetch products by SKU.
let products = try await store.fetchProducts(
ProductRequest(skus: ["com.app.premium"], type: .inApp)
)
// 3. Listen for purchase results — requestPurchase is event-based.
// Keep this token alive for as long as purchases should be observed.
let purchaseSubscription = store.purchaseUpdatedListener { purchase in
Task {
// Verify on your backend, grant entitlement, then finish.
do {
try await store.finishTransaction(
purchase: purchase,
isConsumable: false
)
} catch {
print("Failed to finish transaction: \(error)")
}
}
}
// On app shutdown:
// store.removeListener(purchaseSubscription)
// 4. Initiate a purchase.
try await store.requestPurchase(
RequestPurchaseProps(
request: .purchase(RequestPurchasePropsByPlatforms(
apple: RequestPurchaseIosProps(sku: "com.app.premium")
)),
type: .inApp
)
)
Features — task-oriented walkthroughs, not reference. Each page covers a real flow end-to-end (Purchase, Subscription, Refund, Validation, Offer Code Redemption, …) with verification, edge cases, and platform notes. Open a Features page when you're shipping a flow, not just calling a function.
APIs — flat reference, one page per function (initConnection, fetchProducts, requestPurchase, …). Cross-platform symbols live at the root; iOS- and Android-only symbols are grouped under iOS Specific / Android Specific. Open a function page when you need its exact signature, params, and a copy-pasteable example.
Types — flat reference, one page per type (Product, Purchase, RequestPurchaseProps, …). Same iOS / Android grouping as APIs. Field tables auto-link to related types so you can chase a shape without leaving the docs.
Events & Errors — listener patterns and the unified PurchaseError codes that every SDK normalizes to.
Validation — server-side verification (your own backend or IAPKit — open source under MIT, with hosted validation and analytics free at kit.openiap.dev or self-host from packages/kit)
API Reference — every function with cross-platform signatures