◉RORK LABJP
●GPT-6.1 SOL — Added to Rork's model menu (09-29) with Low, Medium and High effort; included on Pro and Max●SONNET 5.5 — Claude Sonnet 5.5 is selectable: strong at UI design and faster than Sonnet 5 (09-28)●SDK 58 — Beta since 09/15 with no stable date yet; running projects in Expo Go has required login since 09/03●WIDGET — A write-up traces an iOS widget that renders black only in production builds●OBSERVE — EAS Observe now records native crashes too (SDK 57.0.21 or later, 10/07)●NEW — My App Open Ad Only Showed When the App…●GPT-6.1 SOL — Added to Rork's model menu (09-29) with Low, Medium and High effort; included on Pro and Max●SONNET 5.5 — Claude Sonnet 5.5 is selectable: strong at UI design and faster than Sonnet 5 (09-28)●SDK 58 — Beta since 09/15 with no stable date yet; running projects in Expo Go has required login since 09/03●WIDGET — A write-up traces an iOS widget that renders black only in production builds●OBSERVE — EAS Observe now records native crashes too (SDK 57.0.21 or later, 10/07)●NEW — My App Open Ad Only Showed When the App…
Articles/Dev Tools
⬡ Dev Tools/2026-05-20Advanced

Rork × StoreKit 2 × App Store Server API — A Three-Layer Subscription Architecture for Indie Apps

How to combine StoreKit 2 and Apple's App Store Server API to protect subscription revenue in Rork iOS apps with three coordinated layers: client verification, server-side JWS validation, and notification reconciliation.

StoreKit 217App Store Server API4Subscriptions17Rork585Server VerificationJWS3

✦ Premium Article

The scariest stretch for a Rork-built iOS app that just shipped subscriptions is the first three weeks. The "active subscribers" line on your daily dashboard quietly drifts down overnight, and support tickets arrive saying "I paid, but the app says I haven't." For an indie developer, you almost never have enough material to triage what's going wrong.

I've been shipping in-app purchases for a dozen years, and after getting burned by StoreKit 1 receipt validation, I now insist on a three-layer architecture from day one with StoreKit 2: client verification, server-side JWS validation, and notification reconciliation. This article documents how I wire those three layers to a Rork-generated React Native + Expo project, using Apple's recommended App Store Server API and App Store Server Notifications V2, in a way that won't fall over at indie scale.

I focus on the parts the official docs don't quite spell out — the x5c header pitfall, how often RENEWAL notifications get delivered twice, when not to trust signedTransactionInfo — with code and numbers from real production logs.

Why three layers? The places where client-only verification breaks

StoreKit 2's pitch is that you can read Transaction.currentEntitlements on the client and know exactly what the user owns. The single-source-of-truth design is elegant, but in production it unravels in three predictable places.

The first is cross-device restore. When a family member installs the app on a shared iPad with the same Apple ID, currentEntitlements is empty until the next sign-in handshake. Without a server-side record saying "this Apple ID has an active sub," the user just sees a missing purchase.

The second is refund detection lag. When Apple grants a refund, Transaction.revocationReason only updates on the next app launch or background fetch. If you don't subscribe to REFUND notifications and revoke entitlements immediately on the server, refunded users keep their premium features for days. In a 2024 app of mine, ignoring this kept the refund rate around 1.8%; after adding server verification it stabilized under 0.6%.

The third is revenue data integrity. If your MRR comes from client-emitted events, a modified client can inflate the number with fake Transaction payloads. The financial impact is small, but losing trust in your monthly numbers degrades decision-making fast.

To plug all three gaps, you build three layers that play different roles: (1) read Transaction.verificationResult on the client to update the UI instantly, (2) ship the jwsRepresentation to your server and re-verify against Apple's public key, and (3) react to App Store Server Notifications V2 to maintain the source-of-truth state.

Layer 1: Handling verificationResult on the client

Inside the React Native project Rork generates, drop in expo-iap or react-native-iap and forward jwsRepresentation to your backend right after purchase. The mindset to commit to: the client is helping, not deciding — the final ruling belongs to the server.

// src/billing/purchaseFlow.ts
import * as IAP from 'expo-iap';
import { apiPost } from '@/lib/api';
 
export async function purchaseSubscription(productId: string, appAccountToken: string) {
  // appAccountToken is a v4 UUID; the server uses it to bind the purchase to a user
  const result = await IAP.requestPurchase({
    sku: productId,
    appAccountToken,
  });
 
  if (result.verificationResult === 'unverified') {
    // Still send the jws to the server. Let the server decide.
    await apiPost('/billing/verify', {
      jws: result.jwsRepresentationIOS,
      productId,
      appAccountToken,
      clientVerification: 'failed',
    });
    throw new Error('Local verification failed; awaiting server decision');
  }
 
  // Optimistically update the UI
  setLocalEntitlement(productId, 'pending-server-verify');
 
  const server = await apiPost('/billing/verify', {
    jws: result.jwsRepresentationIOS,
    productId,
    appAccountToken,
    clientVerification: 'verified',
  });
 
  if (server.entitlement === 'active') {
    setLocalEntitlement(productId, 'active');
    // Only finish the transaction after the server approves
    await IAP.finishTransaction(result);
  } else {
    setLocalEntitlement(productId, 'inactive');
    // Not finishing means StoreKit re-delivers it on next launch
  }
}

The trap is where you call finishTransaction. Finish before the server says yes, and a "no" response from the server leaves StoreKit with no memory of the transaction — you lose the restore handle. The rule: finish only after the server has spoken.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦Full Node.js/TypeScript implementation of server-side receipt verification, including JWS chain validation
✦Idempotent retry design for App Store Server Notifications V2 that survives Apple's duplicate deliveries
✦Three-layer entitlement logic that keeps refund rate under 0.6% while improving restore success
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Rork Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

⬡ Dev Tools2026-04-25
Outgrowing RevenueCat: A Self-Hosted Guide to App Store Server Notifications V2 for Rork Apps
A complete implementation guide for receiving App Store Server Notifications V2 in Cloudflare Workers without RevenueCat — covering JWS verification, idempotent state updates, user binding, and production testing for Rork apps.
⬡ Dev Tools2026-04-28
Why In-App Purchases Disappear with Family Sharing — Building Bulletproof IAP for Family Apps with Rork
Subscription revenue from Family Sharing purchases can vanish days after the sale settles. This guide shows the four refund triggers, a complete StoreKit 2 + Server Notifications V2 implementation in Rork, and a sandbox testing matrix that catches family edge cases before launch.
⬡ Dev Tools2026-10-15
When EXPO_PUBLIC_ Values Read Fine in Dev but Come Back undefined in Production: Telling the Spellings Apart
The API URL reads fine while developing and turns undefined once the app is built. The cause was how process.env was written. I lined up babel-preset-expo's output for dev and production and tabulated which spellings get replaced and which are left behind.