In‑app purchases (IAP)
FRVR.iap abstracts over Google Play, Facebook Instant, Apple iAP, and other channel billing backends. You describe a catalog once; each channel maps your product IDs onto its own store.
Declare a catalog
Section titled “Declare a catalog”- The key (
COINS_100) is what your code uses. storeIdis what the current channel’s store calls the product.labelis a human name you can show in UI if you don’t already have one.
Read the catalog
Section titled “Read the catalog”After FRVR.init() and the first bootstrap tick, the catalog is ready:
Price/currency come from the underlying store. Use them — don’t hard‑code prices.
Purchase
Section titled “Purchase”Error types:
| Error | Meaning |
|---|---|
IAPPurchaseErrorCancelledByUser | User closed the sheet. Not an error you show. |
IAPPurchaseErrorAlreadyOwned | Durable already owned by this account. |
IAPPurchaseErrorUnknownProduct | Wrong product ID. |
IAPError | Generic fallback. Inspect .code. |
Consumables vs. durables
Section titled “Consumables vs. durables”Consumables (coins, gems) are bought over and over. After you grant the content, consume the purchase so the store frees the user to buy again:
Durables (ad removal, character skins) are never consumed. To re‑grant them on a new device:
Recovering from crashes
Section titled “Recovering from crashes”If your app crashed between purchase and content delivery, the store keeps the receipt in a pending state. On every startup:
This closes the loop even if the user force‑killed the app mid‑purchase.
Try it live
Section titled “Try it live”dev channel ships a mock catalog and a fake purchase flow. Try buy → consume → restore.
IAP: catalog, purchase, consume, restore
API summary
Section titled “API summary”| Method | Purpose |
|---|---|
isReady() / onReady(cb) | Provider readiness. |
getCatalog() | All products keyed by your catalog IDs. |
getProductById(id) | One product, including store price. |
purchase(id, meta?) | Start checkout. Resolves with a purchase receipt. |
consumePurchase(purchase) | Mark a consumable as delivered. |
restorePurchases() | Re‑emit durables owned by the user. |
getUnconsumedPurchases() | Unfinished consumables — call at startup to recover. |
errors.* | Error classes to instanceof‑check. |