ctx.purchases
Sell things inside your app for Fave1 credits — coins, yarn, a theme, a power-up. You name the item; Fave1 holds the price, shows the confirm, takes the credits, and keeps a receipt you deliver against.
Not open to your app yet
items(), buy(), pending(), finish() — rejects with not-yet (in a DEV build items() can instead come back empty, pending() answers [] — nothing was bought — and finish() rejects with not-found), until we open in-app purchases to developers with an item table in the console and your share of the sale. This page is the contract that day keeps, so you can plan your app around it now.Until then, check for it and fold the shop: items() rejecting with not-yet means there’s nothing to sell yet.
Calls
await ctx.purchases.items(); // → { items: PurchaseItem[], balance: number | null } await ctx.purchases.buy(itemId); // → PurchaseReceipt — after they press Fave1's Buy await ctx.purchases.finish(id); // → 'done' | 'returned' — after you delivered await ctx.purchases.pending(); // → PurchaseReceipt[] paid, not finished
{
id: '7b0e2c4a-…', // the receipt — store it next to what you deliver
item: 'coins-500', // your item id
name: '500 coins', // Fave1's name for it
qty: 500, // how many to put in
credits: 299, // what they paid (1 credit = $0.01)
}The price is ours, not your code’s
Your code only ever says an item id. The item’s name, amount and price live on Fave1’s side, so nothing on the page — your bundle, the site, an extension — can change what someone pays. buy() shows a confirm line in your panel; the Buy button in it is Fave1’s own, in a frame your code can’t reach, with Fave1’s name and price on it. Nobody can press it for them, and it only counts a real tap that was on screen.
Every buy asks — there’s no “remember this”. The line says what it costs, how many credits they have (in app mode, or on a site your app is allowed on), and that it can’t be turned back into credits once it’s in.
buy() rejects with credits, with err.balance and err.needed. The first time in a session we also show Get credits ourselves — after that it’s up to you to say it.Deliver, then finish
Credits leave the moment they press Buy. The thing they bought arrives when you put it in — so the receipt goes into the same write as the thing. That one write is what makes it safe to try again: if the receipt id is already there, it was delivered.
type Wallet = { coins: number; receipts: string[] }; async function deliver(ctx: Ctx, r: PurchaseReceipt): Promise<boolean> { const w = ((await ctx.storage.get('wallet')) as Wallet | undefined) ?? { coins: 0, receipts: [] }; if (!w.receipts.includes(r.id)) { w.coins += r.qty; w.receipts = [...w.receipts, r.id].slice(-20); await ctx.storage.set('wallet', w); // coins and receipt, one write } return (await ctx.purchases.finish(r.id)) === 'done'; } async function buyCoins(ctx: Ctx) { try { const r = await ctx.purchases.buy('coins-500'); await deliver(ctx, r); ctx.ui.render([ctx.ui.text(`+${r.qty} coins`)]); } catch (err) { const e = err as Fave1Error; if (e.code === 'cancelled') return; // they said Not now if (e.code === 'credits') return showShort(e.needed, e.balance); // Fave1 showed Get credits the first time only // The answer may have been lost on the way back — the credits could be gone. Settle what's paid: for (const r of await ctx.purchases.pending().catch(() => [])) await deliver(ctx, r); } }
When something stops halfway
A tab closes between Buy and your write, the network drops the answer, the storage write fails — the receipt stays pending and the credits stay taken. Call pending() when your app opens (app mode is a good place) and run each one through the same deliver(): the receipt id in your storage tells you whether to add the thing or just finish.
async function settle(ctx: Ctx) { if (!ctx.can('storage')) return; const due = await ctx.purchases.pending().catch(() => []); for (const r of due) await deliver(ctx, r); }
Unfinished receipts don’t wait forever. After 7 days without finish(), Fave1 gives the credits back and closes the receipt — finish() then answers 'returned'. If you had delivered after all, take the thing back out; they have their credits.
What it guarantees — and what it doesn’t
Fave1 guarantees the money side: the price you set is the price paid, a buy happens only on their tap, a receipt is paid exactly once, and a receipt you never finish is refunded. What you deliver lives in their storage, and their storage is theirs — someone determined can change their own coin count with the browser’s developer tools, just like any app that runs in a browser.
Rules for selling
- Say what it is and what it does before they tap — then deliver exactly that. The item’s name is Fave1’s; the reason to want it is yours, next to the button.
- Deliver everything they paid for. Interrupted buys too — that’s what
pending()is for. Don’t take a delivered item back unlessfinish()said'returned'. - No chance. No loot boxes, no random draws — what they buy is decided before they tap.
- No pressure. No countdowns or scarcity that isn’t real, and nothing that stops working unless they keep paying.
- Never aim a sale at a child.
- Only through ctx.purchases. No card details, payments or Fave1 credits asked for any other way, and no offer to turn items back into money or credits.
These are in the Developer Agreement § 8. Breaking them can get credits returned to people, the item taken off sale, or the app hidden.
Limits
Errors
err.declined), or the panel closednothingerr.balance · err.needed)nothing · then a linestorage isn’t in your manifest, or they switched it offfold the shopfinish() argument that isn’t a receipt idfix itOne permission: storage
Purchases come with storage — you deliver into ctx.storage, so you already declare it. No new sentence for people to read: the confirm line is where they say yes, every time. On a site that hasn’t allowed your app yet, pending() and finish() ask once, like ctx.storage — and can reject with cancelled.