Apple In-App Purchase Server Verification in Node.js
How to verify Apple in-app purchases on a Node.js server with the App Store Server Library: decode signed transactions, handle server notifications and keep subscription state correct.
If your iOS app sells subscriptions, Apple will expect in-app purchase, and your business should expect in app purchase server verification. The app saying "purchase succeeded" is not proof. Your server needs to confirm the transaction came from Apple, belongs to your app and still grants access, then record that entitlement where every client can see it.
I implemented this in Node.js for Client Mitra, where subscriptions are sold through Razorpay on the web and Apple in-app purchase on iOS. Here is the flow, the code shape and the edge cases that matter.
TL;DR
Send the signed transaction from the app to your server. Verify it with Apple's official App Store Server Library, check the bundle ID, product and expiry, and save the entitlement against the account. Subscribe to App Store Server Notifications V2 so renewals, refunds and expirations update automatically. Let clients read plan status from your API, never from local purchase state.
key takeaways
- In app purchase server verification means your backend, not the app, decides whether a purchase is real and what the user is entitled to.
- Apple's App Store Server Library for Node verifies signed transactions and notifications against Apple's certificate chain.
- App Store Server Notifications keep renewals, refunds and expirations in sync without waiting for the user to open the app.
- Store one subscription state per account so web payments and Apple purchases enable the same features.
How Apple purchase verification works today
With StoreKit 2, each transaction is a JWS: a signed payload containing fields like transactionId, originalTransactionId, productId, bundleId, purchaseDate, expiresDate and environment. Your server verifies the signature chain back to Apple's root certificate, then trusts the decoded fields.
The older verifyReceipt endpoint is deprecated. Apple's App Store Server API documentation covers the replacement, and the official @apple/app-store-server-library package for Node handles signature verification and API calls.
The pieces you need
| Piece | Where it comes from | Used for |
|---|---|---|
| Apple root certificates | Apple PKI site | Verifying signed data |
In-app purchase key (.p8), key ID, issuer ID |
App Store Connect | Calling the App Store Server API |
| Bundle ID and app Apple ID | App Store Connect | Binding verification to your app |
| Notification URL | Your server | Receiving renewals, refunds, expirations |
Verifying a transaction in Node.js
The app completes the purchase and sends the signed transaction to an authenticated endpoint such as POST /api/billing/apple/verify. The server code looks roughly like this.
import { SignedDataVerifier, Environment } from '@apple/app-store-server-library';
const verifier = new SignedDataVerifier(
appleRootCerts, // array of Buffers loaded at startup
true, // enable online revocation checks
Environment.PRODUCTION, // or SANDBOX for test builds
process.env.APPLE_BUNDLE_ID,
Number(process.env.APPLE_APP_ID)
);
const tx = await verifier.verifyAndDecodeTransaction(signedTransaction);
After decoding, apply your own business checks before granting anything.
- Confirm
tx.bundleIdmatches your app andtx.productIdis a product you sell. - Check
tx.expiresDateis in the future andtx.revocationDateis not set. - Look up
tx.originalTransactionId; if it is already linked to a different account, reject or flag it. - Upsert a subscription record:
provider: "apple",originalTransactionId,productId,expiresAt,status. - Map the product to your internal plan and update the account's entitlement.
- Return the new plan status to the app.
Handle sandbox and production
TestFlight and review builds use the sandbox. A common pattern is to try production verification first and fall back to a sandbox verifier when the environment field says so. Store the environment on every record so test purchases never upgrade real accounts or count in reporting.
Use appAccountToken
When starting a purchase, the app can pass an appAccountToken (a UUID you generate per account). It comes back inside the signed transaction, which makes linking purchases to the right account much more reliable than matching by device.
Keeping subscriptions in sync with notifications
Verification at purchase time is only half the job. Subscriptions renew, fail billing, get refunded and expire while the app is closed. App Store Server Notifications V2 tell your server about each event.
Configure the production and sandbox URLs in App Store Connect, then on each request verify the payload with verifier.verifyAndDecodeNotification(signedPayload). The decoded notification includes a notificationType and a signed transaction you verify the same way.
| Notification type | What to do |
|---|---|
SUBSCRIBED |
Create or activate the subscription |
DID_RENEW |
Extend expiresAt |
DID_FAIL_TO_RENEW |
Mark billing issue, keep grace period if enabled |
EXPIRED |
Downgrade the account to the free plan |
REFUND |
Revoke access and log the refund |
DID_CHANGE_RENEWAL_STATUS |
Record whether auto-renew is on |
Make the handler idempotent by storing each notificationUUID, and respond with a 200 quickly. Also run a daily job that rechecks subscriptions near expiry using the App Store Server API, in case a notification was missed.
How I built this in practice
Client Mitra is a solo build: a multi-tenant CRM for Indian photography studios, with a Next.js web app, Node/Express API and MongoDB. It ships native Android and iOS apps through one Flutter wrapper around the web app. The full story is in the Client Mitra case study.
On the web, subscriptions run through Razorpay. On iOS, App Store review required an in-app purchase paywall, native Sign in with Apple and server-side verification. I implemented verification with @apple/app-store-server-library in the Node backend, so the Flutter shell only passes the signed transaction to the API and waits for the updated plan.
The key design decision was one subscription state per business, regardless of where it was bought. Plan-gated features read that state from the API on web and in the app, so a studio that pays through Apple sees the same features on the web dashboard. The backend already runs node-cron for reminders, which makes it a natural home for a scheduled recheck job like the one described above.
Common mistakes
- Enabling paid features based on the app's local purchase result without server verification.
- Building new code on the deprecated
verifyReceiptendpoint. - Not configuring server notifications, so refunds and expirations never downgrade the account.
- Ignoring the sandbox environment, letting test purchases look like real revenue.
- Linking purchases by device instead of by account, which breaks on reinstall or a new phone.
- Keeping separate plan logic for web and iOS instead of one server-owned entitlement.
keep reading
FAQ
Why do I need server-side verification for in-app purchases?+
A purchase result reported by the app can be faked or replayed on a modified device. Verifying the signed transaction on your server confirms it came from Apple, belongs to your app and is still valid before you grant access to anything.
Is Apple's verifyReceipt endpoint still the right approach?+
Apple has deprecated the old verifyReceipt flow in favor of signed transactions and the App Store Server API. New builds should verify JWS transactions, for example with the official App Store Server Library.
How do I handle subscription renewals and refunds?+
Configure App Store Server Notifications V2 to call an endpoint on your server. Verify each signed notification, then update the subscription's expiry, status or revocation in your database based on the notification type.
Can one subscription work across web and iOS?+
Yes, if your server owns the entitlement. Record purchases from both Apple and your web payment provider against the same account or business, and have every client ask your API what plan is active.
Devang Gandhi
AI & full stack developer at Passdn, building CRMs, SaaS, AI agents and Flutter apps for clients in the US, UK, Australia, UAE and India. More about me