purchasePackage static method
- Package packageToPurchase, {
- @Deprecated('Use GoogleProductChangeInfo') UpgradeInfo? upgradeInfo,
- GoogleProductChangeInfo? googleProductChangeInfo,
- bool? googleIsPersonalizedPrice,
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.
packageToPurchase
The Package you wish to purchase
upgradeInfo
Android and Google Play only. Optional UpgradeInfo you wish to upgrade from
containing the oldSKU and the optional prorationMode.
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 isPersonalizedPrice 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> purchasePackage(
Package packageToPurchase, {
@Deprecated('Use GoogleProductChangeInfo') UpgradeInfo? upgradeInfo,
GoogleProductChangeInfo? googleProductChangeInfo,
bool? googleIsPersonalizedPrice,
}) async {
final prorationMode = googleProductChangeInfo?.prorationMode?.value ??
upgradeInfo?.prorationMode?.index;
final customerInfo = await _invokeReturningCustomerInfo('purchasePackage', {
'packageIdentifier': packageToPurchase.identifier,
'presentedOfferingContext':
packageToPurchase.presentedOfferingContext.toJson(),
'googleOldProductIdentifier':
googleProductChangeInfo?.oldProductIdentifier ?? upgradeInfo?.oldSKU,
'googleProrationMode': prorationMode,
'googleIsPersonalizedPrice': googleIsPersonalizedPrice,
});
return customerInfo;
}