Entitlements and credits
How AppCore turns verified purchases, trials and manual grants into feature access and credit balances, and how to meter usage safely with reserve and capture.
On this page
An entitlement answers one question on the server: may this user use this feature right now? A credit balance answers how many units of something the user can still spend. Both are computed from grants and credit lots in your app's database. Client claims never change them.
Building blocks
| Concept | What it is |
|---|---|
| Catalog product | Something you sell or give, for example pro_monthly or credits_100. It is edited as a draft and then published. Published versions are immutable. |
| Native mapping | Links a store SKU (provider + product ID + base plan + offer) to a catalog product. It is unique per app environment. A purchase of an unmapped SKU is refused with 404 PRODUCT_NOT_MAPPED. |
| Plan version | The benefits a product grants: features and credit allowances. plan_key is the catalog product ID, or free for the plan every user gets. Users keep the plan version they bought (grandfathering). |
| Grant | One source of access to one entitlement key, with a validity window. Sources are purchase, trial, manual and free. |
| Credit lot | A batch of units from one source (a purchase, a period allowance, a manual adjustment) with an optional expiry. |
| Reservation | Units held for an in-flight operation, later captured or released. |
Draft saves increment version. Send the last version you read as expected_version. A stale write gets 409 STALE_VERSION instead of overwriting another operator's change.
From purchase to access
flowchart LR
P["Store purchase<br/>(on device)"] --> V["POST /v1/commerce/purchases/verify<br/>server verifies with Apple/Google"]
V --> F["Verified purchase recorded<br/>+ outbox event (one batch)"]
F --> G["Entitlements applies it<br/>grant + credit lot (idempotent)"]
G --> S["GET /v1/entitlements/me<br/>EntitlementSnapshot"]
W["Store webhook<br/>(renewal, refund, expiry)"] --> FCommerce applies every committed purchase change to entitlements, and the same change also travels as an event. Applying it is idempotent, so duplicates, restores and webhook retries produce one grant and one credit lot. A subscription renewal extends the same grant and awards one allowance per billing period. Details are in Stores as merchant of record.
The entitlement snapshot
GET /v1/entitlements/me returns an EntitlementSnapshot:
{
"scope": { "tenant_id": "ten_…", "app_id": "app_…", "environment_id": "production" },
"user_id": "usr_…",
"snapshot_version": "…",
"generated_at": "2026-11-30T10:00:00Z",
"cache_valid_until": "2026-11-30T10:05:00Z",
"features": [
{ "key": "pro", "allowed": true, "valid_until": "2026-12-30T10:00:00Z", "reason": "purchase", "value": true }
],
"balances": [
{ "key": "ai_credits", "available_units": "40", "reserved_units": "10" }
]
}- Access is evaluated with server time. An expiry takes effect at its timestamp even if no background job has run.
reasonis one offree,purchase,trial,manual,grace,expired,blocked. A blocked user getsallowed: falsewith reasonblocked.cache_valid_untilis at most 5 minutes ahead, or the earliest grant end if sooner. Cache the snapshot for display until then. Refresh it after a purchase, a restore or app resume.- Unit counts are non-negative integer strings.
Credits: reserve, then capture or release
Metered features (AI generations, downloads, minutes) use a two-step ledger so a crash or retry can never double-charge or overdraw:
- Reserve:
POST /v1/entitlements/reservationswithentitlement_key,units, a uniqueoperation_id, andrequested_ttl_seconds(1–3600). Units come from lots in order of earliest expiry first. Lots that never expire are used last. The request either reserves everything or fails. Concurrent reserves never overdraw. - Do the work.
- Finalize:
POST /v1/entitlements/reservations/{id}withoutcome: "capture"(optionallyactual_units≤ reserved) oroutcome: "release". Unused units go back to their lots. Capture emitsentitlements.usage.captured.v1.
Rules:
- The same
operation_idreturns the original reservation. Reusing it with different content is a409. - Capturing more than was reserved is a
422 CAPTURE_EXCEEDS_RESERVATION. Capturing after the reservation expired is a409 RESERVATION_EXPIRED. Reservations that are never finalized expire, and their units return automatically. - Who may call: a consumer session may reserve for its own user. A body
user_idthat differs from the session user gets403. Only a service capability may finalize, and a service caller must name the user in the body. In practice, put metering in your backend: it reserves, does the work and captures. Never let the mobile app capture. - The ledger is append-only. Balances are never stored in a cache.
Allowances
A plan can award recurring units:
billing_period: one lot per verified renewal.calendar_month: one lot per UTC calendar month, created the first time the user checks or reserves in that month. Concurrent requests award it once. It never extends past the verified subscription period end.once: awarded once per subscription lineage.
Warning
Not yet enabled: carrying unused allowance over to the next period (carryover: true is rejected with 422 CARRYOVER_UNSUPPORTED) and month boundaries in a per-plan time zone (months are UTC today).
Refunds and reversals
When the store refunds or revokes a purchase:
- the grant ends;
- the unspent units of that purchase's lot are reversed, and an in-flight reservation is clawed back when it is released;
- units already consumed are recorded as
unrecovered_units. The balance never goes negative and AppCore never charges the user again; - a partial consumable refund reverses only the refunded quantity. Duplicate refund events do nothing.
A reversal that arrives before the verification event grants nothing. The current purchase facts are re-read each time.
Manual grants and support
Operators with the right permission can grant an entitlement manually (POST /v1/entitlements/grants). A manual grant needs a reason of 10–500 characters, an approval_ref, and a valid_until in the future, at most 366 days ahead. Only manual grants can be revoked manually. Purchase-backed grants change only through store events. Manual grants never create revenue or purchase records. Every action is audited and shows on the user's support timeline.
Note
Manual credit adjustment (POST /v1/entitlements/credits/adjust, compensating ledger entries capped at 10,000 units per adjustment) and product retirement are written but have not yet passed the integrated test run.
Warning
Not yet enabled: family/group sharing (R2, not started); store catalog sync and drift detection; cross-app bundles (not part of this release).
What this means for your app
- Gate premium features with the snapshot from
GET /v1/entitlements/me(or your backend's check), not with a local "isPro" flag set after a purchase dialog. - Show prices from the store SDK on the device. The paywall read model (
GET /v1/catalog/export) carries product and plan metadata but deliberately no prices. - Refresh the snapshot after purchase, restore and resume. Respect
cache_valid_until. - Put credit metering in your backend with a stable
operation_idper user action, so retries are safe. - Design for refunds: consumed credits are not clawed back from the user, so price consumables accordingly.