handleAndroidSwitchPlan method

Future<bool> handleAndroidSwitchPlan(
  1. LinkFivePlan oldLinkFivePlan,
  2. LinkFiveProductDetails productDetails, {
  3. ProrationMode? prorationMode,
})

Handles the Up and Downgrade of a Subscription plan oldPurchaseDetails given by the LinkFive Plugin productDetails from the purchases you want to switch to prorationMode default replaces immediately the subscription, and the remaining time will be prorated and credited to the user. Check https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode for more information

Implementation

Future<bool> handleAndroidSwitchPlan(LinkFivePlan oldLinkFivePlan, LinkFiveProductDetails productDetails,
    {ProrationMode? prorationMode}) async {
  final GooglePlayPurchaseDetails? oldPurchase = await _getAndroidPurchase(oldLinkFivePlan);

  // If null, return false
  if (oldPurchase == null) {
    LinkFiveLogger.e("Old Purchase not found");
    return false;
  }

  // create the upgrade or downgrade Purchase param
  GooglePlayPurchaseParam googlePlayPurchaseParam = GooglePlayPurchaseParam(
      productDetails: productDetails.productDetails,
      changeSubscriptionParam:
          ChangeSubscriptionParam(oldPurchaseDetails: oldPurchase, prorationMode: prorationMode));

  // init the purchase
  return InAppPurchase.instance.buyNonConsumable(purchaseParam: googlePlayPurchaseParam);
}