Home Flutter How to Build Subscription and Credit-Based Billing for Flutter AI Apps

How to Build Subscription and Credit-Based Billing for Flutter AI Apps

14
0

Implement App Store and Google Play purchases in Flutter, verify renewals on the backend, and charge for AI usage without granting or spending credits twice.

A user buys a 100-credit pack, closes the app before the confirmation screen appears, and opens it again on another device. The purchase update and a server notification arrive close together. Meanwhile, the user starts an AI generation. The system has to answer three questions: did the purchase clear, have those 100 credits already been granted, and has the generation already reserved its share?

Flutter handles the purchase interface and displays the result. The backend needs three separate records to answer those questions reliably: verified store transactions, subscription entitlements, and a credit ledger. A verified transaction proves what the store recorded. An entitlement determines which features the account can access. The ledger records how much usage the account can fund.

1. Separate the subscription from the credits it includes

A subscription can unlock premium models or higher limits and grant a recurring usage allowance. A consumable credit pack adds usage under its own terms. Store the two as separate credit lots, even if the paywall also shows a combined balance. That makes it possible to explain why an allowance changed at renewal while purchased credits stayed in the account.

RecordWhat it tracks
Store transactionStore, environment, product ID, verified purchase identifier, and owning account
Subscription entitlementPlan, status, access period, and subscription chain
Credit lotSource, original grant, remaining units, and any applicable expiry
Ledger entryGrant, reservation, spend, release, expiry, or refund adjustment
AI jobStable request ID, quoted credit cost, reservation, and final result

Price AI actions in units users can understand. A Flutter image app might charge 2 credits for a standard image and 10 for a premium image. Those are illustrative prices. To set real prices, measure cost by model, input size, output size, and retry rate. Provider pricing can distinguish input, cached input, and output, so one credit per request can make a short response and a long generation look equivalent while costing very different amounts to serve.

2. Map the Flutter paywall to each store’s billing rules

For digital features and AI credits sold in the app, start with Apple In-App Purchase and Google Play Billing. Check the rules for each storefront before adding an alternative checkout or external purchase link. Google’s payments policy also limits in-app virtual currency to the app or game title for which it was purchased.

Apple’s generative AI exception matters for credit packs. Apple’s general rule is that credits purchased through In-App Purchase may not expire. Qualifying generative AI apps can request an entitlement for expiring consumables, generally with a minimum term of 12 months unless local law requires otherwise. Apple requires expiry disclosure near the purchase button, a visible balance, earliest-expiring eligible credits to be used first, and email reminders 30 and 7 days before expiry. Apple also says included subscription credits must be used before those expiring consumables. Model these as separate balances with explicit spending rules.

In Flutter, the in_app_purchase package exposes a purchaseStream for purchase updates. Subscribe early in the app lifecycle so the handler can receive unfinished updates when the app reopens. Show the store’s localized price, treat a pending purchase as pending, and send purchase evidence to the backend for verification. When the Flutter client owns store completion, call completePurchase for a verified, durably delivered purchase when the plugin reports that completion is pending. If the backend owns Google Play acknowledgment or consumption, keep that responsibility there and configure the client flow accordingly.

RevenueCat is another option. Its Flutter SDK handles purchase integration, and its virtual currency feature supports recurring grants from subscriptions. Decide whether RevenueCat or your backend owns the credit balance. If detailed reservations and refunds live in your own ledger, avoid configuring both systems to grant or debit the same credits independently.

3. Verify purchases and grant each billing period once

Send purchase evidence from Flutter to an authenticated endpoint such as POST /billing/purchases/verify. The server verifies it with the store, checks the app and product identifiers, and binds the purchase to the correct account. The verified product determines the credit amount. The API can return already_applied when a purchase was processed before the client received its response.

There are two deduplication problems. The first is event delivery. The same store notification can arrive again. The second is the economic event. A purchase reported by Flutter and the same purchase reported by a store notification may have different delivery IDs. Deduplicate the credit grant using a unique key derived from the verified store transaction or billing period, then write the purchase and grant in the same database transaction.

On Apple, verify signed transaction data and use the individual transaction ID for purchase or renewal grants. Keep the original transaction ID to associate renewals with a subscription chain. On Google Play, use real-time developer notifications to trigger a lookup of the current state through purchases.subscriptionsv2.get. A subscription purchase token alone is insufficient to identify each renewal grant. Use verified line-item order or period information for the grant. Google exposes latestSuccessfulOrderId on the line item and deprecates the top-level latestOrderId.

Handle renewals, cancellations, grace periods, and refunds as separate events. A cancellation can stop the next renewal while access remains available through the paid period. For a refunded pack, append a reversal against the original grant and apply a defined rule for credits already spent. On reinstall or a second device, reload the balance from the backend. Consumed credit packs need that account-level history because the store’s restore flow does not rebuild a spent consumable balance.

4. Reserve credits before the AI job starts

Suppose an image generation costs 8 credits and the account has 12 available. If two devices submit jobs at once, both can read 12 before either writes a debit. The backend should reserve credits in a database transaction before sending the job to the model provider.

A practical request flow is:

  1. The app sends a stable requestId and the generation parameters. The backend calculates the price from its own rate card.
  2. The backend locks the account’s spendable balance, checks the available lots, and saves the job and reservation together. Repeating the request returns the original job.
  3. When the job succeeds, the backend converts the reservation to a spend. If it fails and the product charges only for delivered output, the backend releases the reservation to the original lots under their existing expiry rules.
  4. If the provider times out and the outcome is unclear, the job remains pending reconciliation. The app can show Check status instead of submitting another generation.

The Flutter screen can then show the quoted cost before submission and the available balance after reservation. For example, 4 available · 8 reserved explains where the credits went while generation is still running.

5. How five companies approach subscriptions and credits

CompanyPublicly documented practice
GeekyAntsIts JFIT marketplace case study documents RevenueCat In-App Purchase for digital expert subscriptions and Stripe for client service payments. It illustrates how one mobile product can route different purchase types through different billing systems. The published case describes subscription and service billing, so its relevance here is the payment architecture.
AdobeCreative Cloud plans include monthly generative credit allocations. Which features consume credits depends on the plan, and premium capabilities can have different credit costs. The model shows how one visible credit unit can cover several types of generation.
RunwayRunway documents separate monthly, rollover, and purchased balances. Its spending order uses current plan credits first, then rollover credits, then purchased credits. Separately purchased credits are documented as non-expiring.
ElevenLabsElevenLabs offers subscriptions with a monthly credit quota and prepaid pay-as-you-go credits. Eligible unused subscription credits can roll over within a cap while the user remains on the same plan. The rollover rule is part of the billing model and has to survive plan changes.
OpenAIOpenAI documents flexible usage credits for eligible ChatGPT features after included usage is used. Those credits extend usage for supported features while the underlying plan remains the same.

What should teams test before release?

  • Duplicate delivery: Process the same purchase through Flutter and a store notification. Confirm one grant.
  • Renewal and plan change: Verify each eligible period gets one allowance and upgrades or downgrades follow the product’s grant policy.
  • Two devices spending at once: Confirm simultaneous jobs cannot reserve more than the available balance.
  • Interrupted purchase and reinstall: Confirm a paid pack is credited once even if the original confirmation screen never appears.
  • Refund after partial spend: Verify the reversal is traceable and the remaining balance follows the published terms.
  • Provider timeout: Verify a generation with an unknown outcome cannot trigger another spend simply because the user retries.

A Flutter paywall is ready when a user can buy credits on one device, spend them on another, and explain the resulting balance from purchase and usage history. That depends on verified store events, a ledger that records every change, and AI jobs that reserve and settle credits once.

Previous articleHow to Keep an AI Task Running While Users Navigate Between Flutter Screens
Next articleHow to Collect and Track AI Response Feedback in Flutter

LEAVE A REPLY

Please enter your comment!
Please enter your name here