In-app purchases
Sell things inside your app without a payment processor, a card form or a refund desk. You define products; the user confirms and pays on an OpenMarkets page; your app reads back what they hold.
The model
Three things, all named by your app. OpenMarkets does not know what any of them mean.
- Entitlements — strings a user either holds or does not:
unlimited,pro. A purchase grants them; a full refund revokes them. - Units — named counters your app spends from:
calendar,ai_runs. A purchase adds to them; your app spends them. - Products — a price plus what it grants. Defined per app in the publisher console (Apps → your app → Products). A
one_timeproduct is bought once and must grant at least one entitlement — holding it is how “already owned” is known. Arepeatableproduct can be bought any number of times: packs of units, tips. Prices run from $0.50 to $500, in USD.
Worked example: a printable-calendar app
The first calendar is free. After that it is $1 per calendar, or $5 for unlimited. Two products:
| Code | Type | Price | Grants |
|---|---|---|---|
| calendar_1 | repeatable | $1.00 | { calendar: 1 } |
| unlimited | one_time | $5.00 | entitlement unlimited |
“First one free” is your own logic — OpenMarkets never sees it. When the user wants another calendar, check the entitlement, then try to spend a unit, and offer the products only when both come up short:
import { createOpenMarketsAuth, createOpenMarketsStore } from '@openmarketsai/app-sdk'
const auth = createOpenMarketsAuth({ clientId: 'calendar-app', redirectUri: location.origin + '/' })
const store = createOpenMarketsStore(auth)
// On every page load: finishes a redirect-mode purchase return (?om_order=…).
await store.handleReturn()
async function makeCalendar(calendarId: string) {
if (!alreadyMadeOne()) return render(calendarId) // first one free — your rule
if (await store.has('unlimited')) return render(calendarId)
// Idempotent: the same key never spends twice, so a retry is safe. Key it on
// the thing being made — never a fresh random value per attempt.
const spent = await store.spend('calendar', 1, `calendar:${calendarId}`)
if (spent.status !== 'insufficient') return render(calendarId)
// Out of calendars — show the two options. The user confirms on OpenMarkets.
showUpsell({
one: () => store.purchase('calendar_1', { returnUrl: location.href }),
unlimited: () => store.purchase('unlimited', { returnUrl: location.href }),
})
}
How a purchase happens
app.openmarkets.ai/pay/:order_id- Your app starts a checkout for a product. That creates an order and returns a URL on OpenMarkets. Nothing is charged.
- The user opens it (popup or redirect), signs in if needed, sees your app, the product, the price and what it grants — all from OpenMarkets' records, never from your request — and pays or cancels.
- Afterwards they return to your
return_urlwith?om_order=<id>appended (a popup just closes). Read the order, or the user's holdings, to see the result. - An unpaid order expires after an hour.
SDK
@openmarketsai/app-sdk 0.8.0createOpenMarketsStore(auth) wraps the REST calls below with the signed-in user's key from Sign in with OpenMarkets.
| Method | Does |
|---|---|
| products() | What this app sells to this user, with owned on one-time products. |
| purchase(code, { returnUrl, clientReference?, popup? }) | Starts a checkout and sends the user to the pay page. |
| handleReturn() | Call on page load — resolves a redirect-mode return carrying om_order. |
| order(id) | One of this app's orders for this user. |
| entitlements() | Everything the user holds in this app: entitlements and unit balances. |
| has(code) | Does the user hold this entitlement? |
| units(unit) | The user's balance of one unit. |
| spend(unit, amount, idempotencyKey) | Spend units. Resolves { status: 'spent' | 'replayed' | 'insufficient', balance } — a short balance is a result, not an exception. The key is required. |
REST reference
X-API-Key: the user's install keyEvery call uses the key your app received for this user when they installed it. Every key belongs to exactly one user, so no user id is ever passed — each call reads or writes that user's holdings in your app.
/flow/v1/apps/store/productsThe products this app sells. A live key sees approved products only; a test key sees every active product.
{
"data": {
"environment": "live",
"products": [
{ "code": "unlimited", "name": "Unlimited calendars", "description": null,
"type": "one_time", "price_cents": 500, "currency": "USD",
"grants_entitlements": ["unlimited"], "grants_units": {}, "owned": false },
{ "code": "calendar_1", "name": "One calendar", "description": null,
"type": "repeatable", "price_cents": 100, "currency": "USD",
"grants_entitlements": [], "grants_units": { "calendar": 1 }, "owned": false }
]
}
}
/flow/v1/apps/store/checkoutStart a purchase. Returns the order and the OpenMarkets URL to send the user to. Charges nothing.
// Request body
{ "product": "unlimited", "return_url": "https://calendar.example.com/print", "client_reference": "cart_42" }
// 201
{
"data": {
"order_id": "…",
"url": "https://app.openmarkets.ai/pay/…",
"status": "pending",
"environment": "live",
"product": "unlimited",
"amount_cents": 500,
"currency": "USD",
"grants_entitlements": ["unlimited"],
"grants_units": {},
"client_reference": "cart_42",
"created_at": "…",
"paid_at": null,
"refunded_at": null,
"expires_at": "…"
}
}
| Body field | Required | Description |
|---|---|---|
| product | yes | The product's code. |
| return_url | yes | Where the user lands afterwards. Must be https (http only on localhost) and on the origin of one of your registered redirect URIs. |
| client_reference | no | Your own reference (≤ 255 chars), echoed back on the order. Never interpreted. |
/flow/v1/apps/store/orders/:order_idOne of this app's orders for this user. Status is pending, paid, refunded, canceled or expired. Anyone else's order is a 404.
/flow/v1/apps/store/entitlementsWhat this user holds in this app. Holdings belong to the user and the app, not the install — uninstalling and reinstalling keeps what was bought.
{
"data": {
"environment": "live",
"entitlements": [{ "code": "unlimited", "granted_at": "2026-09-29T14:02:11.000Z", "order_id": "…" }],
"units": { "calendar": 2 }
}
}
/flow/v1/apps/store/spendSpend units. Idempotent on idempotency_key (required, ≤ 128 chars): a retry with the same key is applied once and reports replayed: true. Refused, never clamped, when the balance is short.
// Request body
{ "unit": "calendar", "amount": 1, "idempotency_key": "calendar:2026-10" }
// 200
{ "data": { "unit": "calendar", "spent": 1, "balance": 1, "replayed": false } }
// 402
{ "error": { "code": "insufficient_units", "message": "Not enough \"calendar\" — balance is 0",
"details": { "unit": "calendar", "balance": 0, "requested": 1 } } }
Errors
| Status | Code | When |
|---|---|---|
| 402 | insufficient_units | A spend asked for more than the balance. details carries unit, balance, requested. |
| 409 | already_owned | A checkout for a one-time product the user already holds. |
| 409 | product_not_approved | A live key tried to sell a product that has not passed review. Test installs can still buy it. |
| 400 | billing_disabled | Live payments are not switched on yet. Use a test install. |
| 400 | invalid_return_url | Not https, or not on a registered redirect-URI origin. |
| 404 | product_not_found | No active product with that code in this app. |
Test mode
- A test install — your draft app, installed by you or an invited tester — buys through exactly the same path, and the order completes with no charge. The pay page says so.
- Test holdings are separate. A live key never sees what a test install bought, and the reverse.
- A new product works in test mode at once. Selling it for real money needs a review. Changing its price or what it grants sends it back to review; a name or description change does not.
See Test mode for how test credentials work generally.
Refunds and your share
- Refunds are handled by OpenMarkets. A full refund revokes the entitlements that order granted and takes back its units — as far as they are unspent; spent units are absorbed, never driven negative.
- Your share of each live sale is 75%, accruing to your workspace after a 30-day hold. Payouts are issued manually today.