FFXPurchases class

Store purchases surface (docs/architecture/payments-ux.md §11): what the app sells in the App Store and Google Play, and what the signed-in end user bought.

The app buys through the store itself (Flutter's in_app_purchase); this surface is plain HTTP. read answers the end user's purchase id, which the app passes to the store with every purchase (applicationUserName), the products with each store's ids, the upgrade as it stands, the unlocks they own and their credits. checkAppStore and checkGooglePlay hand drip a purchase the store just returned: drip checks it with the store, records it and grants it, and only then should the app finish the store's transaction. In the preview, where no store runs, checkPretend records a purchase on drip's pretend store.

import 'package:flutterflow_cloud/purchases.dart';

final state = await cloud.purchases.read();
final plus = state.products.first;
// … buy plus.appStoreId through the store, then:
final after = await cloud.purchases.checkAppStore(
  details.verificationData.serverVerificationData,
);
if (after.upgraded) showThanks();

A check that changes the upgrade sets its claim; the session is then refreshed so the next request's rules see it. Problems map to typed errors with end-user copy; see the package README's Purchases section.

Constructors

FFXPurchases(HttpCore _http, FFXAuth _auth)

Properties

changes → Stream<FFXPurchaseState>
Every answer reads and checks give, as they arrive.
no setter
current → FFXPurchaseState?
The signed-in end user's last answer from a read or a check; null before the first, or once someone else signs in.
no setter
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

checkAppStore(String signedTransaction, {bool restored = false}) → Future<FFXPurchaseState>
Checks a purchase StoreKit 2 returned: its signed transaction (the jwsRepresentation, serverVerificationData in in_app_purchase).
checkGooglePlay({required String productId, required String purchaseToken, bool restored = false}) → Future<FFXPurchaseState>
Checks a purchase Google Play returned: its product id and purchase token (serverVerificationData in in_app_purchase). restored is as for checkAppStore.
checkPretend({required String item, String? plan, int? amount}) → Future<FFXPurchaseState>
Records a purchase on drip's pretend store, in the preview: item is the upgrade's claim with its plan (monthly, yearly or once), an unlock with none, or the credits with the pack's amount. Only the preview's backend records it, as a test purchase that charges nothing; a pretend subscription lasts its free trial, else one period, and doesn't renew. The platform refuses it with purchaseNotVerified.
close() → void
Stops changes; FlutterFlowCloud.close stops the instance's.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
read() → Future<FFXPurchaseState>
The end user's purchase id, upgrade, unlocks and purchases, and the products the app sells. The first read makes their purchase id.
recordEvents(List<FFXPurchaseEvent> events) → Future<int>
Records what the app's paywall and shop saw, for Payments' Reports: the paywall or the shop shown and what opened it, a plan or pack picked, a purchase started or cancelled in the store's sheet. At most 50 at a time. Each event's FFXPurchaseEvent.id makes a repeat record nothing, so a batch can be sent again after a lost answer. Answers how many were new: only the production environment's are kept, and the emulator keeps none.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited