【问题标题】:How to purchase for the first time an In-App Purchases Subscription in Flutter?如何在 Flutter 中首次购买 In-App Purchases 订阅?
【发布时间】:2021-07-26 08:38:55
【问题描述】:

我正在尝试使用 in_app_purchase 包在我的 Flutter 应用程序中实现订阅系统。我在文档中发现的只是我需要一个旧的购买来处理订阅:

final PurchaseDetails oldPurchaseDetails = ...;
PurchaseParam purchaseParam = PurchaseParam(
    productDetails: productDetails,
    changeSubscriptionParam: ChangeSubscriptionParam(
        oldPurchaseDetails: oldPurchaseDetails,
        prorationMode: ProrationMode.immediateWithTimeProration));
InAppPurchaseConnection.instance
    .buyNonConsumable(purchaseParam: purchaseParam);

我已经有了 productDetails。 第一次怎么订阅?

【问题讨论】:

    标签: flutter in-app-purchase google-play-console in-app-subscription


    【解决方案1】:

    第一次订阅不需要旧订阅,参数changeSubscriptionParam是可选的,可以传null。当您要更改订阅时,您需要在changeSubscriptionParam 中的此参数中传递旧订阅 范围。这仅适用于 android,获取旧订阅的简单方法是(在我的情况下,只有两个可能的签名):

        Future<GooglePlayPurchaseDetails> _getOld() async {
    
          if (Platform.isAndroid) {
                final InAppPurchaseAndroidPlatformAddition androidAddition =
                    _inAppPurchase
                        .getPlatformAddition<InAppPurchaseAndroidPlatformAddition>();
                QueryPurchaseDetailsResponse oldPurchaseDetailsQuery =
                    await androidAddition.queryPastPurchases();
                oldPurchaseDetailsQuery.pastPurchases.forEach((element) {
                  oldPurchaseDetails = element;
                });
              }
    
          return oldPurchaseDetails;
        }
    

    【讨论】:

      猜你喜欢
      • 2020-12-20
      • 1970-01-01
      • 2021-02-24
      • 2011-01-05
      • 2011-04-17
      • 1970-01-01
      • 2018-03-25
      • 2019-05-21
      • 1970-01-01
      相关资源
      最近更新 更多