An in-app purchase looks simple: the user taps a button, the store charges them, the app unlocks access. In reality there are many states in between: renewals, failed charges, grace periods, refunds, plan changes, family sharing. If only the client decides who gets paid content, sooner or later you will have either users who pay and do not get access, or users who keep using the product for free after a refund.
This article covers the architecture of server-side purchase validation for StoreKit 2 and Google Play Billing: what data comes from the client, which APIs to call, how to process notifications and how to build a single entitlement model. Choosing a monetization model is a product question we covered separately; here it is engineering only.
Why client-only validation does not work
- The client does not see events outside the app. Refunds, cancellations in system settings and failed charges happen while the app is closed.
- Access must be cross-platform. A user who bought on iPhone and signs in on Android or the web needs entitlements decided by the backend.
- Modified clients. Local checks can be bypassed on rooted Android or jailbroken iOS devices.
- Revenue analytics. Trial conversion, churn and refunds can only be counted reliably on the server.
Architecture: three data flows
A robust setup has three independent channels that together keep server state aligned with store state:
- Client → backend after a purchase: the app sends the transaction ID (Apple) or purchaseToken (Google); the backend verifies it with the store API and records entitlements.
- Store → backend via server notifications: App Store Server Notifications V2 and Google Play Real-time developer notifications (RTDN). This is the primary source of state changes.
- Backend → store on a schedule: periodic reconciliation of active subscriptions through server APIs to compensate for missed notifications.
Apple: StoreKit 2 and the App Store Server API
In StoreKit 2 every transaction is a signed JWS (JSON Web Signature) with Apple's certificate chain. The client receives an already verified Transaction, and the backend can verify the signature itself or fetch current data through the App Store Server API. Apple has deprecated the old verifyReceipt endpoint, so new integrations should be built without it.
Key endpoints
- Get Transaction Info — details of a specific transaction by transactionId;
- Get All Subscription Statuses — current status of every subscription in a group: active, expired, in billing retry, in grace period, revoked;
- Get Transaction History — the user's full transaction history, useful for rebuilding state;
- Look Up Order ID — lookup by the order number from the receipt a user forwards to support.
Requests are signed with a JWT using a key created in App Store Connect. Apple provides the official App Store Server Library for Java, Python, Node.js and Swift, which handles signature verification and request building. We recommend it over hand-rolling certificate chain validation.
appAccountToken
At purchase time you can pass an appAccountToken — a UUID linking the transaction to an account in your system. It comes back in every transaction and notification, so the backend knows who owns the purchase even when a notification arrives before the client's request.
App Store Server Notifications V2
Apple sends a POST to your URL with a signedPayload field. Main types: SUBSCRIBED, DID_RENEW, DID_FAIL_TO_RENEW (with a GRACE_PERIOD subtype), EXPIRED, GRACE_PERIOD_EXPIRED, DID_CHANGE_RENEWAL_STATUS, DID_CHANGE_RENEWAL_PREF, REFUND, REVOKE (loss of access through Family Sharing), OFFER_REDEEMED. If your server does not return HTTP 200, the App Store retries several times over the following days, but you should not rely on that alone.
Google: Play Billing Library and the Play Developer API
On Android, after a purchase the Play Billing Library returns a Purchase object with a purchaseToken. The token is the main identifier the backend verifies through the Google Play Developer API.
Verification and acknowledgement
- For subscriptions use purchases.subscriptionsv2.get: it returns subscriptionState (ACTIVE, IN_GRACE_PERIOD, ON_HOLD, PAUSED, CANCELED, EXPIRED, PENDING) and lineItems with expiry times.
- For one-time purchases use purchases.products.get.
- Every purchase must be acknowledged within 3 days, or Google automatically refunds and revokes it. Acknowledge from the backend after entitlements are recorded, not from the client.
- For consumables, consume after granting the item — it both acknowledges and allows repurchase.
Real-time developer notifications
Google delivers notifications through Cloud Pub/Sub. A message carries only the event type and purchaseToken, not the full state, so for every notification the backend calls subscriptionsv2.get and updates its records. Main types: SUBSCRIPTION_PURCHASED, SUBSCRIPTION_RENEWED, SUBSCRIPTION_IN_GRACE_PERIOD, SUBSCRIPTION_ON_HOLD, SUBSCRIPTION_RECOVERED, SUBSCRIPTION_CANCELED, SUBSCRIPTION_EXPIRED, SUBSCRIPTION_REVOKED. You should also poll the Voided Purchases API to learn about refunds and chargebacks.
Google also raises the minimum supported Play Billing Library version for new apps and updates every year, so plan library upgrades as regularly as you plan target API level bumps.
A single entitlement model
The best approach is not to keep "Apple status" and "Google status" separately in business logic but to normalize both into one entitlement entity. This is how we map states:
| Normalized state | Apple | Access | |
|---|---|---|---|
| active | status = 1 (Active) | SUBSCRIPTION_STATE_ACTIVE | Yes |
| active_canceled | Active, autoRenewStatus = 0 | SUBSCRIPTION_STATE_CANCELED, expiry in the future | Yes, until the paid period ends |
| grace_period | status = 4 (Billing Grace Period) | SUBSCRIPTION_STATE_IN_GRACE_PERIOD | Yes, with a payment banner |
| billing_retry / on_hold | status = 3 (Billing Retry) | SUBSCRIPTION_STATE_ON_HOLD | No; prompt to update payment method |
| paused | — | SUBSCRIPTION_STATE_PAUSED | No |
| expired | status = 2 (Expired) | SUBSCRIPTION_STATE_EXPIRED | No |
| revoked | status = 5 (Revoked), REFUND | SUBSCRIPTION_REVOKED, voided purchase | No, immediately |
The entitlements table on the backend typically holds: user_id, product_id, store, original_transaction_id or purchase_token, state, expires_at, auto_renew, environment (sandbox/production), last_verified_at. The client only asks "what am I entitled to", never for store details.
Step-by-step implementation
- Configure products and subscription groups in App Store Connect and Play Console with matching access-level identifiers.
- Generate an App Store Server API key and a service account for the Play Developer API with minimal permissions.
- Connect App Store Server Notifications V2 (separately for sandbox and production) and a Pub/Sub topic for RTDN.
- Build a verification endpoint: the client sends transactionId or purchaseToken, the backend checks it via the API, records the entitlement and, for Google, acknowledges.
- Notification handlers must be idempotent: the same notification can arrive twice or out of order. Store notificationUUID or messageId and compare event timestamps.
- Add a daily reconciliation of subscriptions expiring within 48 hours and all those in grace period or billing retry.
- Test in sandbox: accelerated renewals, failed payments, refunds, plan changes. Xcode has StoreKit Testing with local configuration; Google has license testers and test cards.
Typical mistakes
- Granting access because the client reported "purchase succeeded", with no server check.
- Not acknowledging Google purchases and getting automatic refunds after 3 days.
- Mixing sandbox and production: test transactions land in production analytics or vice versa.
- Cutting access right after a failed charge, ignoring the grace period.
- Not handling REFUND and REVOKE — the user gets their money back and keeps access.
- No Restore Purchases button and no way to recover state after reinstalling.
Billing readiness checklist
- The backend decides entitlements; the client only displays them.
- App Store Server API and subscriptionsv2 are used, not deprecated endpoints.
- appAccountToken and obfuscatedAccountId link purchases to accounts.
- Notifications V2 and RTDN are connected; handlers are idempotent.
- Google purchases are acknowledged from the backend within 3 days.
- Daily reconciliation and Voided Purchases API polling are in place.
- Grace period is enabled in both consoles and reflected in the logic.
- Renewal, failed payment, refund, upgrade and downgrade are tested.
- Monitoring: an alert fires if no notifications have arrived for several hours.
Sources: Apple: StoreKit; Apple: App Store Server API; Apple: App Store Server Notifications; Android: Integrate Google Play Billing with your server backend; Android: Integrate the Google Play Billing Library; Android: Real-time developer notifications reference.



