In-App Purchases in Flutter: Why Server-Side Verification Is a Must

Setting up in-app purchases in Flutter looks easy at first: the in_app_purchase package lists the products, the user pays, and a "purchased" event lands in the app. That's also exactly where most mistakes begin. Taking that event and unlocking the premium feature directly is like trusting a slip of paper that says "paid" without checking the register.

Why you can't trust the client

The app runs on the user's device, and the user owns that device. On a rooted or jailbroken device, there are tools that generate fake purchase responses. Until it's verified, a "payment completed" message from the client is nothing more than a claim. That's why the real decision on a purchase result has to be made on the server.

The right flow: send the receipt to the server

When a purchase completes, the PurchaseDetails object carries the verification data provided by the store (verificationData). The app sends this data to your own server, and the server checks it against the store's official verification API. The flow roughly looks like this:

  • The app receives the purchase event and sends the verification data to the backend.
  • The backend sends a request to the Play Developer API for Google Play, and to the App Store Server API for Apple.
  • If the store's response is valid, the backend writes the user's entitlement to the database.
  • Only after the backend confirms does the app call completePurchase and unlock the feature.
The app sends the verification data to the backend, the backend queries the store, the entitlement is written to the database, and the feature is unlocked after confirmation.
The source of truth for the feature is the record on the server, not a flag on the device.

The source of truth for the feature is now the record on the server, not a flag on the device. Even if the user deletes and reinstalls the app or signs in from another device, their entitlement is read from the server.

What to watch for on the server side

Verification isn't just a matter of "is the receipt valid?" Resubmitting the same receipt with a different account is a classic abuse technique. So store the transaction ID (for example, the order ID issued by the store) in the database with a unique index, and reject any receipt that has already been used. Also check that the product ID matches the product you expect and that the receipt belongs to your app.

On the Laravel side, keep this logic in a separate service class instead of burying it in the controller: an interface that wraps the calls to the store can be swapped for a fake implementation during testing. Also set a clear rule for when the store is unreachable: in that case the purchase stays "pending" and is retried later by a queued job. Leaving a user stranded after their money has been taken is a worse outcome than letting fraud slip through.

Subscriptions and refunds: state changes over time

For one-time products, verification happens once. With subscriptions, though, the state keeps changing: they renew, get canceled, fail to charge, or get refunded. The client can't learn about all of these changes in time. Use the stores' server notifications: Real-time Developer Notifications on Google's side and App Store Server Notifications on Apple's side. The backend receives these notifications and updates the user's entitlement. Don't trust the notification itself, either; confirm the incoming event through the store's API.

A short setup checklist

Before taking the purchase flow live, check the following: Are all feature-unlock decisions made on the server? Is the transaction ID unique? Are pending and interrupted purchases reprocessed when the app launches? Is there a restore button? For one-time permanent products in particular, a restore option not only lets users get their entitlement back on a new device but is also part of what store reviewers expect.

Four questions to ask before taking the purchase flow live: server-side decisions, unique transaction IDs, processing pending purchases, and restore.
Restore is also part of store review expectations.

Testing. Since the purchase flow can't be tested with real money, use both stores' test environments: license test accounts on Google Play, and sandbox users on Apple's side. In addition, write a fake implementation of the backend verification service; that way you can run edge cases like a failed receipt, a resubmitted receipt, or a store timeout as automated tests on every change. In a money-related flow like purchasing, discovering an edge case in production is the most expensive way to find it. One more warning: don't put the credentials for store verification calls (the Google service account key, Apple's API key) inside the app; keep them only on the server, in environment variables or in a secrets manager. Every key embedded in an app ends up in the hands of anyone who unpacks the package.

If you want to add purchases or subscriptions to your app the secure way, reach out through our contact page. We've been building this flow with Flutter and Laravel for years, and we design it correctly from the start, verification and notification layers included.