LinkFive Purchases flutter sdk

Getting Started

Initialize the SDK

LinkFivePurchases.init("LinkFive Api Key");

fetch all available subscripton:

LinkFivePurchases.fetchSubscriptions();

Available Subscription Data

LinkFive uses a stream to pass data to your application. You can either just use the stream or use a StreamBuilder

StreamBuilder<LinkFiveSubscriptionData?>(
  stream: LinkFivePurchases.listenOnSubscriptionData(),
  builder: (context, snapshot) {
    if (snapshot.hasData) {
      var subscriptionData = snapshot.data;
      if(subscriptionData != null) {
        // do something
      }
    }
    return Center(child: Text('Loading...'));
  },

Purchase a Subscription

Just call purchase including the skuDetails

makePurchase(LinkFiveProductDetails linkFiveProductDetails) async {
  await LinkFivePurchases.purchase(linkFiveProductDetails.productDetails);
}

Get Active Subscription Data

You will receive the data through the active subscription stream. You can either just use the stream or use a StreamBuilder

LinkFivePurchases.listenOnActiveSubscriptionData().listen(_activeSubscriptionListener);

///
/// subscriptionData can be null
///
void _activeSubscriptionListener(LinkFiveActiveSubscriptionData? subscriptionData) async {
  // active Subscription
}

Restore Purchases

All restored subscriptions will be available through the activeSubscription listener

LinkFivePurchases.restore();

Android Errors

if you get something like:

e: .../LinkFivePurchasesPlugin.kt: (89, 9): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from .../.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.5.0/29dae2501ca094416d15af0e21470cb634780444/kotlin-stdlib-1.5.0.jar!/kotlin/Unit.class

The SDK uses kotlin v1.5.0. You can change the kotlin version in your android/build.gradle file

buildscript {
    ...
    dependencies {
        ...
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0"
    }
}

Gradle

The sdk uses Gradle version 6.7.1

Libraries

linkfive_active_subscription
linkfive_app_data_store
linkfive_billing_client
linkfive_client
linkfive_logger
linkfive_purchases
linkfive_response
linkfive_subscription
linkfive_verified_receipt
purchases
subscription_period