Once your Flutter app has successfully called
var res = await InAppPurchase.instance
.buyNonConsumable(purchaseParam: purchaseParam);
print(res); // true
the next step is to verify and manage that subscription on your backend. Here’s a typical end-to-end flow:
-
Client → Your Backend
• As soon as the purchase succeeds, grab the platform-specific receipt/token from PurchaseDetails:
– Android: purchaseDetails.verificationData.serverVerificationData (a purchaseToken)
– iOS: purchaseDetails.verificationData.serverVerificationData (a Base64 receipt)
• Send that data, plus your internal user ID or auth token, to your own server via HTTPS.
-
Backend Verifies with Google/Apple
• Android (Google Play)
– Call Google Play Developer API:
GET https://androidpublisher.googleapis.com/androidpublisher/v3/applications/{packageName}/purchases/subscriptions/{subscriptionId}/tokens/{token}
– You’ll need a service account JSON, proper OAuth2 scopes (https://www.googleapis.com/auth/androidpublisher).
• iOS (App Store)
– POST the Base64 receipt to Apple’s verify endpoint:
https://buy.itunes.apple.com/verifyReceipt (or sandbox URL during testing)
– In the JSON body include your shared secret and the receipt-data.
-
Parse the Response
• Check status codes (0 = valid for Apple).
• Pull out fields like expiry_time_millis (Android) or latest_receipt_info[0].expires_date_ms (iOS).
• Make sure it hasn’t expired, and auto-renew status is what you expect.
-
Persist in Your Database
Save a record for the user, e.g.:
• userId
• productId (subscription SKU)
• purchaseToken / receipt
• purchaseDate / expiryDate
• autoRenewStatus / cancellationDate (if any)
-
Send Confirmation Back to Client
Return a JSON response such as:
{
"success": true,
"expiresAt": "2024-07-12T15:04:05Z"
}
On the Flutter side you can now update your UI, unlock premium features, etc.
-
Handle Renewals & Cancellations
• Google Real-time Developer Notifications (RTDN)
– Subscribe to Cloud Pub/Sub to get messages on renewals, cancellations, so you can update your DB.
• Apple Server-to-Server Notifications
– Apple can POST to your webhook URL with events like DID_RENEW, CANCEL, etc.
-
Client-side “Refresh”
Periodically (or on app launch) call your backend /subscription/status to get the latest expiry and access-flags. Don’t trust the local cached state alone.
— — — — —
Example Node.js (Express) snippet for verifying an Android subscription:
// Node.js + googleapis
const {google} = require('googleapis');
const androidpublisher = google.androidpublisher('v3');
async function verifySubscription(packageName, subscriptionId, token) {
const auth = new google.auth.GoogleAuth({
keyFile: 'path/to/service-account.json',
scopes: ['https://www.googleapis.com/auth/androidpublisher']
});
const client = await auth.getClient();
const res = await androidpublisher.purchases.subscriptions.get({
auth: client,
packageName,
subscriptionId,
token
});
return res.data; // check res.data.expiryTimeMillis, etc.
}
Example iOS receipt verification (Node.js + fetch):
const fetch = require('node-fetch');
async function verifyIOSReceipt(receiptData) {
const res = await fetch('https://buy.itunes.apple.com/verifyReceipt', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
'receipt-data': receiptData,
'password': 'YOUR_SHARED_SECRET'
})
});
const json = await res.json();
return json; // check json.status == 0, then json.latest_receipt_info
}
Key Takeaways
• Always verify purchases on your server (never trust the client alone).
• Store and manage expiry/renewal/cancellation in your own DB.
• Hook up Google RTDN / Apple Server Notifications to stay in sync.
• Expose a secure endpoint for the app to fetch the user’s current subscription state.
Let me know if you need more details on any of those steps or if you’re using a specific backend stack (Node, Python, Firebase Functions, etc.)!