daybook_subscriptions 0.10.1
daybook_subscriptions: ^0.10.1 copied to clipboard
Purchases for Flutter on Daybook: StoreKit 2 and Google Play Billing subscriptions that are never lost, access you can check, and paywalls as data.
daybook_subscriptions #
Purchases for Flutter on Daybook, on native cores: StoreKit 2 on iOS 15 and later, Google Play Billing 9.1 on Android 7 (API 24) and later.
It covers the install, its customer and who they are, what the customer may use now, purchases, plan changes, access that keeps working while Daybook cannot be reached, paywalls, and the buyer's store country.
Setup #
-
In Daybook, open the project's settings, find the app under App key and issue its key. The key,
dbk_…, ships inside the app, so it is not a secret. Every Daybook module in the app uses the same one. -
Add the core and this module, and start Daybook at launch, before anything else:
flutter pub add daybook daybook_subscriptionsdependencies: daybook: ^0.1.0 daybook_subscriptions: ^0.10.1import 'package:daybook/daybook.dart'; import 'package:daybook_subscriptions/daybook_subscriptions.dart'; final daybook = await Daybook.initialize('dbk_...'); final profile = await daybook.subscriptions.getProfile(); if (profile.isActive('premium')) { // Unlock. }Purchases are activated with Daybook; the app does not call
activate. Later, anywhere:Daybook.instance.subscriptions. -
Sign people in and out as your app does, once, on Daybook: every module hears it.
await daybook.identify('user_42', email: 'ann@example.com'); await daybook.reset();The email and name are kept on the customer, so support finds them and your webhooks carry them. The app's own attributes are set here:
await daybook.subscriptions.setAttributes({'level': 'C1', 'plan_type': null}); // null removes a key -
Sell:
final products = await daybook.subscriptions.getProducts(['premium.monthly']); switch (await daybook.subscriptions.makePurchase(products.first)) { case PurchaseSuccess(:final profile): // Unlock from profile. case PurchaseUserCancelled(): case PurchasePending(): // Ask to Buy: it completes later, on profileUpdates. }Or sell from a paywall, which you change in the console without a release:
await daybook.subscriptions.setFallback('assets/daybook-fallback.json'); // Subscriptions › Paywalls final paywall = await daybook.subscriptions.getPlacement('onboarding'); final offered = await daybook.subscriptions.getPaywallProducts(paywall); // Show paywall.remoteConfig and offered.products; log it, and buy from it: await daybook.subscriptions.logShowPaywall(paywall); await daybook.subscriptions.makePurchase(offered.products.first);Prices come in the buyer's currency. For copy or an offer by country, ask which App Store they use:
final storefront = await daybook.subscriptions.getStorefront(); // countryCode: 'USA', 'BLR', …A purchase is finished only once Daybook holds it; until then it waits and is sent again. An app that must deliver first, say coins its own backend keeps, calls
DaybookSubscriptions.configure(finishing: Finishing.manual)before Daybook starts andfinishTransactionitself.restorePurchases()is for your Restore button. Once a person is signed in, what the store already holds for them, say a subscription bought through another SDK, is sent to Daybook by itself, once, without asking for their Apple ID.
While Daybook cannot be reached, what the App Store holds is granted on the device and marked
AccessLevel.isLocal; Daybook's profile replaces it once it answers. profileUpdates tells you each
time the profile changes. A failed call throws
DaybookSubscriptionsException, whose code you can branch on.
Android #
The same calls work on Android, with these differences:
- Product ids. A subscription is Google Play's product and base plan,
productId:basePlanId, as you declare it in Daybook's catalog:getProducts(['premium:monthly']). Paywalls already give them so. - Intro offers. Google Play lists only the offers this buyer may take, so
introductoryOfferis the first offer on the base plan, such as a free week, and a purchase takes it. - Acknowledging. Google refunds a purchase nobody acknowledged within 3 days. The SDK acknowledges a
purchase once Daybook holds it, or, with
Finishing.manual, when you callfinishTransaction. Daybook's server acknowledges what the SDK did not, such as a resubscription in the Play Store; in Daybook, the app's Google Play connection says who acknowledges (Subscriptions › Settings › Android). - Changing plans. On Google Play, a plan change is a purchase that replaces the subscription the account
holds:
makePurchase(annual, replacing: const SubscriptionReplacement('premium:monthly')). The SDK finds the account's purchase of the old plan itself, and throwssubscription_not_foundbefore Play opens when there is none.modeis Google'sReplacementMode:withTimeProration(the default),chargeProratedPrice(only when the price per unit of time rises),chargeFullPrice,withoutProration, ordeferred, which switches at the old plan's renewal. On iOS, leave it out: StoreKit switches plans within a subscription group itself. - One-time products. A product id with no base plan, such as
lifetime_99, is a one-time product. Declare it in Daybook's catalog as Lifetime, NonSubscription or Consumable: a Consumable is consumed once Daybook holds it, so it can be bought again, and anything else is acknowledged. Google does not say which is which, so a one-time product'stypeisunknown. - The fallback file is the Android one: Subscriptions › Paywalls › Fallback file · Android.
- Testing. A license tester buys for free in a debug build whose
applicationIdis your app's on Google Play; nothing needs uploading.
Platforms #
iOS 15 and later (StoreKit 2), Android 7 (API 24) and later (Google Play Billing 9.1). A flutter create
app starts at iOS 13, so raise IPHONEOS_DEPLOYMENT_TARGET in ios/Runner.xcodeproj (and platform :ios
in a Podfile, if there is one). Daybook.initialize(key, serverUrl: …) points it at a Daybook of your own.
Privacy #
- No advertising id is read, and no permission is asked for beyond the store's own.
- At activation the SDK sends the install id, the platform and OS version, the app's version, this SDK's version and the locale. On iOS it also sends the identifier for vendor, so one device is one install to Daybook; on Android no device identifier is read.
- The customer's user id, and the email, name and attributes the app gives, are kept on the customer.
- A purchase carries the customer's id to the store: as
appAccountTokenon iOS, as the obfuscated account id on Google Play. - Tracking consent does not turn purchases off: they are a function of the app.
- The iOS privacy manifest declares the device id and the user id, both for app functionality and not
for tracking, and
UserDefaults(CA92.1).