purchaseSubscriptionOption static method

Future<CustomerInfo> purchaseSubscriptionOption(
  1. SubscriptionOption subscriptionOption, {
  2. GoogleProductChangeInfo? googleProductChangeInfo,
  3. bool? googleIsPersonalizedPrice,
})

Google Play only.

Makes a purchase. Returns a CustomerInfo object. Throws a PlatformException if the purchase is unsuccessful. Check if PurchasesErrorHelper.getErrorCode is PurchasesErrorCode.purchaseCancelledError to check if the user cancelled the purchase.

subscriptionOption The SubscriptionOption you wish to purchase

googleProductChangeInfo Android and Google Play only. Optional GoogleProductChangeInfo you wish to change from containing the googleOldProductIdentifer and the optional prorationMode.

googleIsPersonalizedPrice Android and Google Play only. Optional boolean indicates personalized pricing on products available for purchase in the EU. For compliance with EU regulations. User will see "This price has been customize for you" in the purchase dialog when true. See https://developer.android.com/google/play/billing/integrate#personalized-price for more info.

Implementation

static Future<CustomerInfo> purchaseSubscriptionOption(
  SubscriptionOption subscriptionOption, {
  GoogleProductChangeInfo? googleProductChangeInfo,
  bool? googleIsPersonalizedPrice,
}) async {
  if (defaultTargetPlatform != TargetPlatform.android) {
    throw UnsupportedPlatformException();
  }

  final prorationMode = googleProductChangeInfo?.prorationMode?.value;

  final customerInfo =
      await _invokeReturningCustomerInfo('purchaseSubscriptionOption', {
    'productIdentifier': subscriptionOption.productId,
    'optionIdentifier': subscriptionOption.id,
    'googleOldProductIdentifier':
        googleProductChangeInfo?.oldProductIdentifier,
    'googleProrationMode': prorationMode,
    'googleIsPersonalizedPrice': googleIsPersonalizedPrice,
    'presentedOfferingIdentifier':
        subscriptionOption.presentedOfferingIdentifier,
  });
  return customerInfo;
}