Architecture — the server is the source of truth
Two layers, one identity (app_user_id = the account’s immutable user.id, the same id push uses):
- On device — the RevenueCat SDK makes purchases and gives an instant, offline copy of the user’s entitlements (fast UI gating).
- On the server — RevenueCat posts a webhook for every purchase/renewal/cancellation. The
API stores the result in the
entitlementstable. This is what server-enforced features trust; the device’s copy is only ever a cache of it.
Everything is off until configured, exactly like OneSignal/Sentry: no keys ⇒ the webhook
401s, the paywall hides,
requireEntitlement denies. The kit builds and runs unchanged.entitlements row
per (user, entitlement). “Active” is derived, never stored: expires_at is NULL (lifetime) or
in the future. There is no consumable/credit ledger — deliberately out of scope.
Activation — env only
Client (shipwide_app, .env)
API (
shipwide_api, .env)
Product ids never appear in code — the paywall lists whatever packages your current RevenueCat
offering holds. The entitlement id is
pro on both sides: VITE_REVENUECAT_ENTITLEMENT_ID in the
app and DEFAULT_ENTITLEMENT_ID in shipwide_api/src/config/constants.ts on the server. Beyond
that one id, the server stores whatever entitlement ids RevenueCat sends, so extra tiers need no
server change. Keep pro and you never edit code — only env plus the dashboard checklist below.
Dashboard checklist (the part env can’t do)
Store IAP inherently needs dashboard setup — true of every IAP integration, not just this kit. The kit’s promise is no code changes, not “no setup”.1
RevenueCat
Create a project; add an app per platform you sell on (Apple, Google, Web). Copy each public
SDK key → the three
VITE_ vars; a secret key → REVENUECAT_SECRET_KEY.2
Stores
App Store Connect + Google Play Console — create the subscription products and the
non-consumable (one-time) products for lifetime unlocks, agreements/banking, a subscription
group, license testers.
3
Web billing engine
For the web/Tauri build, connect a RevenueCat web engine: Web Billing (Stripe-backed) or
Paddle (a Merchant of Record handling global sales tax/VAT, available where Stripe isn’t).
The client (
@revenuecat/purchases-js) is the same either way — the engine is a dashboard
choice; follow RevenueCat’s guide for the one you pick.4
Entitlement, offering, webhook
Create an entitlement
pro and an offering; attach the store products. Set the webhook URL to
https://<your-api>/v1/subscriptions/webhook with the Authorization value equal to
REVENUECAT_WEBHOOK_AUTH.Server & client surface
Server module:shipwide_api/src/modules/subscriptions/.
The webhook is idempotent (a Redis key per event id drops RevenueCat’s retries) and
order-safe (an older event never overwrites newer state). Gate any server route with the
exported
requireEntitlement(entitlementId) preHandler. It is a module-local factory, not a shared
decorator, so the whole feature stays removable. Admins read a user’s entitlements at
GET /v1/admin/users/:id/entitlements, shown on the account’s detail page in the admin panel.
On the client (paths under shipwide_app/src/):
useRevenueCat()(composables/) — one wrapper, three providers chosen per platform: native (@revenuecat/purchases-capacitor), web/Tauri (@revenuecat/purchases-js) and mock. The SDKs are dynamically imported, so an unconfigured build loads neither.useSubscriptionStore()—isPro,inBillingRetry(premium, but a payment failed),has(id).RevenueCatInitializer.vue(mounted inApp.vue) — configures on boot, mirrors auth (logIn/logOut), seeds the store from the SDK, then reconciles withGET /me. The latest auth change wins: a sign-out cancels the sign-in’s sync still in flight, so a previous account’s entitlements never land after it.- Reference UI —
views/pages/subscription/Subscription.vue(paywall + manage in one, opened from Settings) andPremiumExample.vueat/subscription/premium-example(client + server gating).
useProGate() (composables/useProGate.ts) gates any action in the UI. It offers
two checks: ensurePro() for a Pro-only action and ensureUnderLimit(count, limit) for a
free-tier cap. Each takes an optional { title, message } and returns true to proceed.
Otherwise it shows an upsell alert (See plans → /subscription) and returns false. The pure
check behind it, withinFreeLimit() (helpers/proGate.ts), is unit-tested. There’s an example in
Offline-first data.
When the server refuses an action with 402 (its requireEntitlement check), call
presentUpsell({ title?, message? }) from the same composable: it shows the same alert no matter
what the client believes — a stale entitlement or a not-yet-loaded store never turns a refused
save into a silent no-op.
The gate fails open: until the subscription store has loaded, every user passes, so a
paying user is never blocked on a cold start. That includes the whole time billing is
unconfigured. It gates the UI only; enforce paid limits on the server with
requireEntitlement.Granting a free period
An operator can give any account the premium entitlement (pro by default) for free — a
goodwill gesture, a reviewer, a beta tester — and take it back:
- Where: Admin → Accounts → open the account → its Subscription card → grant a free period, or revoke a grant.
- How it works: the grant is made through RevenueCat as a promotional entitlement, so the
user’s devices see it like a purchase, and it lands in the
entitlementstable with the storepromotional.requireEntitlementandisProtreat it like any paid entitlement. - Needs
REVENUECAT_SECRET_KEYin the API env. Every grant and revoke is written to the admin audit log.
Mock mode — develop with no account
Sandbox testing checklist
The full money flow only runs against real Apple/Google and Stripe/Paddle accounts — their rule, not the kit’s. Once the dashboards are set up:- Mark your QA account as a test account (Admin → Accounts → open the account → Mark as test account), so it’s easy to filter out of real customers.
- iOS: sign into a StoreKit sandbox tester and buy a plan. The paywall flips to the manage
view, and
GET /v1/subscriptions/meshows the entitlement active. - Android: a license tester; same checks.
- Web: buy through your engine’s sandbox (Stripe test card
4242 4242 4242 4242, or Paddle’s sandbox); same checks. - Cancel in the store → the webhook turns
will_renewoff; access continues untilexpires_at. - Trigger a billing issue → the manage view shows the payment-problem banner.
- Restore purchases on a fresh install brings the entitlement back.
- Call
GET /v1/subscriptions/premium-examplewith and without the entitlement —402vs200.
Platform notes & compliance
- Compliance: Apple and Google require digital subscriptions to be sold through their IAP inside their apps. Web billing (Web Billing/Stripe or Paddle) is for the web build only; the iOS/Android builds must not surface a web purchase path — RevenueCat routes per platform automatically.
- Compatibility: the kit is on Capacitor 8, so the native SDK is pinned to
@revenuecat/purchases-capacitor13.x, which requires Capacitor 8. The web SDK (@revenuecat/purchases-js) is independent of Capacitor and versioned separately. - Tauri desktop runs the web build in a webview, so it uses the web provider’s embedded
checkout. Where a webview limits that checkout, open a RevenueCat Web Purchase Link in the
system browser instead; the user returns to the app through the kit’s deep links
(
shipwide_app/src/services/deepLinks.ts).