How to Verify VPN App Subscriptions on Your Backend

24 Nov 2026 By ST Muntaha
How to Verify VPN App Subscriptions on Your Backend

Your VPN app sells subscriptions through the App Store and Google Play, and your servers must answer one question: should this account’s credentials work right now? The app cannot answer honestly, because a modified app can claim anything.

To verify in app subscriptions on your backend, tie every purchase to your own account ID, check it with Apple’s and Google’s server APIs, treat store notifications as a prompt to check again, and keep one idempotent record that decides VPN access. This guide gives eight steps, a state to action table and a reconcile job. Try everything in Apple’s sandbox and with Google test purchases first. Where billing sits in the whole system is covered in our six components of a VPN app.

Before You Start

Facts are as of 31 October 2026, from the sources listed at the end.

  • Apple: an In App Purchase key from App Store Connect (the Admin role creates it) with its key ID and issuer ID, your bundle ID, Apple’s root certificates from Apple PKI, and an HTTPS URL on TLS 1.2 or later with version 2 notifications selected. We use Apple’s Python library (tag v3.1.2) as the reference.
  • Google: a Google Cloud project with Pub/Sub, a topic, and credentials with the androidpublisher scope for the Google Play Developer API.
  • Your side: a stable internal account ID, a plan table (product ID to duration and device limit) and a panel API that can set an expiry and disable users.

Step 1: Attach Your Own Account ID to Every Purchase

Do this. Generate an opaque ID per account and pass it into the purchase flow.

On Apple, make it a UUID and set it as the app account token, using StoreKit’s appAccountToken(_:) purchase option. Apple returns the same UUID in the transaction and renewal information. On Google, call setObfuscatedAccountId on BillingFlowParams.Builder. The API returns it as externalAccountIdentifiers.obfuscatedExternalAccountId.

Google’s API reference limits the value to 64 characters, recommends encryption or a one way hash, and warns that purchases are blocked if it holds personal data such as a cleartext email. A random ID you map yourself avoids the question.

Why. The purchase now carries a link your server can check without trusting the app. Google also uses the ID to spot irregular activity.

You know it worked when a sandbox purchase shows your UUID in the decoded transaction, or your ID in the Google response.

It usually fails when the user buys before signing in, or buys outside your app. For Apple, call Set App Account Token (PUT /inApps/v1/transactions/{originalTransactionId}/appAccountToken) after sign in. For a Google resubscribe made in the Play subscriptions center, read outOfAppPurchaseContext, then pass externalAccountIds when you acknowledge.

Step 2: Verify In App Subscriptions on Your Backend

Do this. Have the app send a claim, never a verdict: Apple’s transaction ID or signed transaction, or Google’s purchase token. Your server checks it with the store.

# Sketch adapted from Apple's Python library README (v3.1.2). Use Environment.SANDBOX while testing.
verifier = SignedDataVerifier(root_certificates, True, Environment.PRODUCTION,
                              "com.example.vpn", app_apple_id)
tx = verifier.verify_and_decode_transaction(signed_transaction)
# Read tx.appAccountToken, tx.originalTransactionId,
# tx.expiresDate and tx.revocationDate from the verified object.

For Google, call the Developer API with the token:

GET https://androidpublisher.googleapis.com/androidpublisher/v3/applications/{packageName}/purchases/subscriptionsv2/tokens/{token}

Apple also offers Get All Subscription Statuses, GET /inApps/v1/subscriptions/{transactionId}, on api.storekit.apple.com (sandbox: api.storekit-sandbox.apple.com). The library signs requests for you.

Why. Google’s billing security guidance says client code can be modified, so verification belongs on a backend you control. The Apple library checks the certificate chain, the bundle ID and the environment.

You know it worked when the account in the store data matches the account that is signed in, and Google’s subscriptionState is not SUBSCRIPTION_STATE_PENDING.

It usually fails when sandbox data reaches a production verifier (INVALID_ENVIRONMENT), the bundle ID differs (INVALID_APP_IDENTIFIER), or you forgot that production needs the app’s Apple ID. Key every record on originalTransactionId or purchaseToken. If Google returns linkedPurchaseToken, retire the old token’s entitlement, as Google’s guidance says, so one purchase never entitles two users.

Step 3: Acknowledge on Google, or Revoke What Fails

Do this. After you grant access to a new Google purchase, acknowledge it from your backend:

POST https://androidpublisher.googleapis.com/androidpublisher/v3/applications/{packageName}/purchases/subscriptions/{subscriptionId}/tokens/{token}:acknowledge

The reference says subscriptionId has not been required since 21 May 2025, so check what your client library expects. Renewals need no acknowledgement. If verification fails, do not acknowledge. Revoke instead with purchases.subscriptionsv2.revoke and a revocationContext of fullRefund.

Why. An unacknowledged new purchase is refunded automatically after three days, per Google’s lifecycle page and security guidance. Prepaid plans shorter than one week get half the plan duration.

You know it worked when acknowledgementState reads ACKNOWLEDGEMENT_STATE_ACKNOWLEDGED.

It usually fails when the acknowledgement lives only in the app. A user who never reopens the app is refunded.

Step 4: Receive Store Notifications

Do this. Both stores announce state changes. Neither announcement is the whole truth.

Apple. Enter the HTTPS URL in App Store Connect and choose version 2. The body holds a signedPayload. Decode it with the library’s verify_and_decode_notification, then read notificationType, subtype, notificationUUID and data. If you filter by IP, Apple documents the subnet 17.0.0.0/8. Call Request a Test Notification (POST /inApps/v1/notifications/test) to check the path.

Reply with HTTP 200 to 206 to succeed. A 40x or 50x makes the App Store retry five times, at 1, 12, 24, 48 and 72 hours after the previous attempt. Apple’s response page says retries happen only in production. Sandbox sends once.

Google. Create a Pub/Sub topic, give [email protected] the Pub/Sub Publisher role, then enter the topic in Play Console and press Send Test Message. Google’s reference says to base64 decode data into a DeveloperNotification. A subscription message carries notificationType and purchaseToken. It says only that state changed, so call purchases.subscriptionsv2.get for the rest. Skip repeats by checking messageId.

It usually fails when your handler does slow work before replying. Store the raw event under a unique key (notificationUUID or messageId), reply, then process it in a worker. Neither page we read promises delivery order, so do not rely on it.

Step 5: Keep an Idempotent Entitlement Record

Do this. Keep one row per store purchase, with a unique key. The worker reads the current store state, then sets the row. It never adds days.

Field Apple Google Play
Unique key originalTransactionId plus environment purchaseToken
Account appAccountToken externalAccountIdentifiers.obfuscatedExternalAccountId
Product productId lineItems[].productId
Paid until expiresDate (milliseconds) lineItems[].expiryTime
State status 1 to 5 subscriptionState
Event ID notificationUUID messageId
Event time signedDate eventTimeMillis

Why. Duplicate and late events then change nothing. An account can hold several rows (one per store purchase), and access follows the latest paid until date, or Apple’s gracePeriodExpiresDate during a Billing Grace Period. Google advises keying on purchaseToken, not orderId, which some purchases lack.

You know it worked when replaying the same event twice leaves the row unchanged. Our privacy policy guide covers what to disclose about purchase data you keep.

Step 6: Map Store State to VPN Access

Do this. Convert each verified state into one of four actions. Keep means access on and expiry set from the store. Keep with notice adds a prompt to fix payment. Suspend means disable the user but keep the record. Revoke means disable now and delete or rotate the credential.

Store state Apple Google Play Action Panel call
Active, renewing status 1; SUBSCRIBED, DID_RENEW SUBSCRIPTION_STATE_ACTIVE Keep Enable, set expiry
Canceled, not yet expired DID_CHANGE_RENEWAL_STATUS with AUTO_RENEW_DISABLED; expiresDate ahead SUBSCRIPTION_STATE_CANCELED; use expiryTime for access Keep until the paid until date None
Grace period status 4; DID_FAIL_TO_RENEW with GRACE_PERIOD; ends at gracePeriodExpiresDate SUBSCRIPTION_STATE_IN_GRACE_PERIOD; retries continue, user keeps benefits Keep with notice Stay enabled; set expiry to Apple’s gracePeriodExpiresDate or Google’s expiryTime
Billing retry or account hold status 3; DID_FAIL_TO_RENEW with no subtype, or GRACE_PERIOD_EXPIRED SUBSCRIPTION_STATE_ON_HOLD; block access Suspend Disable; enable on DID_RENEW with BILLING_RECOVERY or SUBSCRIPTION_RECOVERED
Paused None SUBSCRIPTION_STATE_PAUSED; resume time in pausedStateContext.autoResumeTime Suspend Disable; enable on recovery
Pending payment None SUBSCRIPTION_STATE_PENDING Do not grant None
Expired status 2; EXPIRED SUBSCRIPTION_STATE_EXPIRED Suspend Disable; delete after your retention period
Refunded or revoked status 5; REFUND; revocationDate set; REVOKE for Family Sharing RTDN type SUBSCRIPTION_REVOKED (the resource then reads SUBSCRIPTION_STATE_EXPIRED, so record the notification type); Voided Purchases API Revoke Disable, then delete or rotate the credential
Refund reversed REFUND_REVERSED Not listed Check again Enable if active

The Suspend versus Revoke split is our design recommendation, not a store rule. Apple and Google define the states and say when a user keeps or loses access. Whether you keep a disabled record or delete or rotate the credential is your choice. State definitions come from Apple’s notification types, the library’s Status enum, Google’s discovery document and its lifecycle page.

As of 31 October 2026, Apple’s article “Reducing Involuntary Subscriber Churn” says a Billing Grace Period you enable in App Store Connect lasts 3 or 6 days on weekly plans and 3, 16 or 28 days on longer ones, with full service meanwhile. Billing retry can run up to 60 days. Without a grace period, Apple does not say to keep access during retry, so suspending is our reading.

Step 7: Apply the Action to Your Panel

Do this. Make panel calls idempotent: set expiry, set enabled, set limits from your plan table. Never increment. Record a panel_state and retry failures from a queue.

As one example, the 3x-ui source at v3.11.0 exposes client routes that accept a Bearer API token:

POST /panel/api/clients/update/{email}   (client object: enable, expiryTime, limitIp)
POST /panel/api/clients/del/{email}
Authorization: Bearer <API token>

Prepend your panel’s web base path. Admin scope tokens pass every route check in the source, so keep yours on the backend. Panel APIs change between versions, so check yours. The source calls limitIp an IP limit, so map your device limit to what your panel enforces. We did not confirm whether an update merges or replaces, so on a test panel read the client, change one field, send the whole object and read it back. Our 3x-ui install guide covers securing the panel and its tokens.

You know it worked when a suspended test user fails to connect and a restored one connects, without touching the panel by hand.

It usually fails when the database commit succeeds and the panel call does not. The retry queue exists for that gap.

Step 8: Run a Reconcile Job

Do this. Run a daily job that asks the stores for the truth.

  • Apple: call Get All Subscription Statuses for records near expiry or unchecked for days. Call Get Notification History (POST /inApps/v1/notifications/history) to replay events your server missed.
  • Google: call purchases.subscriptionsv2.get for the same records. Call voidedpurchases.list with type set to 1 so subscriptions appear. Its startTime cannot be older than 30 days, so run at least that often. Renewal orders share one purchaseToken, so match on orderId and read the subscription again before revoking.
  • Both: list panel users who are enabled without an active entitlement, and the reverse. Fix them and alert when the count is not zero.

You know it worked when a notification you skipped on purpose in sandbox is corrected on the next run.

It usually fails when you query too fast. The Apple library lists a rate limit error, so spread the calls and back off.

What About Web Checkout and Alternative Billing?

Leave this out of the first version. Apple’s App Review Guidelines say unlocking features such as subscriptions requires In App Purchase, with storefront specific exceptions in 3.1.1(a) and 3.1.3. Google Play’s Payments policy has region and program rules too. A purchase made off store sends no store subscription notification, so you would need a third source of entitlement. This is not legal advice, so read both policies on the day you build. Pricing and trials are covered in our guide to monetizing a VPN app.

FAQ

Do I need notifications if I verify at purchase?

Yes. Verification at purchase only proves the first payment. Renewals, failed payments and refunds happen later, and notifications plus a reconcile job are how you hear about them.

Can I trust the receipt or token the app sends?

No, treat it as a claim. Check it with Apple’s or Google’s server API, compare the account link from Step 1 to the signed in user, and only then grant access.

Should I keep VPN access during a billing problem?

Keep it during Apple’s Billing Grace Period and Google’s grace period, because both stores treat the user as still entitled. Suspend on Google’s account hold, and, in our reading, on Apple’s billing retry without a grace period.

Does a renewal need to be acknowledged on Google?

No. Google requires acknowledgement of new purchases, within three days (less for prepaid plans under a week). Renewals need none.

Takeaway

To verify in app subscriptions on your backend, let the store decide what was paid and let your record decide what the tunnel allows. Verified state in, idempotent panel change out, and a reconcile job for everything in between.

Wiring App Store and Google Play subscriptions to your admin panel and servers? DigitalD.tech builds the admin panel, the billing and subscription flow, and the servers behind custom VPN apps. Tell us your stack on the contact page, and we’ll tell you what we’d do in your position.

Last checked against Apple’s App Store Server Notifications and App Store Server API pages, Apple’s subscriber churn article and App Review Guidelines, Apple’s Python server library on GitHub (v3.1.2), Google Play’s real time developer notifications reference, getting ready, subscription lifecycle and billing security pages, Google’s Payments policy page, the Google Play Developer API discovery document (revision 20261026), and the 3x-ui repository (v3.11.0) on 31 October 2026.