【问题标题】:On complete purchase i'm getting developer error such as response (In app purchase )完成购买后,我收到开发人员错误,例如响应(应用内购买)
【发布时间】:2021-04-09 14:46:52
【问题描述】:

BillingResponse.developerError I/flutter (5091):购买处于无效状态。

有时我会收到此错误,但我会遇到计费响应正常 (BillingResponse.ok) 的情况。可能是什么问题?我的代码遵循flutter.dev的官方示例https://pub.dev/packages/in_app_purchase 在这段代码之前一切都很好

var completePurchase = await InAppPurchaseConnection.instance
              .completePurchase(purchaseDetails);

返回 BillingResponse.developerError 或者有时魔法返回 BillingResponse.ok

在小部件中我只是调用 buyNonConsumable

  instance.buyNonConsumable(prod);

是否有可能是因为它不在生产中或其他与内部测试相关的东西,因为应用程序正在进行内部测试? 总而言之,代码是这样的

     _subscription = getPurchaseStream.listen(
        (purchaseDetailsList) {
          _listenToPurchaseUpdated(purchaseDetailsList);
        }, onDone: () {
      _subscription.cancel();
      }, onError: (error) {
        // handle error here.
        print('Subscription error: $error');
      });

    _isAvailable = await _connection.isAvailable();
    if(!_isAvailable) {
      print('The store is not available, try again later..');
      return;
    }
    _myProductsIds = await _categoryRepository.getCategoriesGoogleProductsIds(); 
    await _getProducts();
    await _getPastPurchases();
    for (PurchaseDetails purchase in _purchases) {
      verifyPurchase(purchase.productID);
      if (_isPurchased) {  //Check if product is purchased
        await deliverProduct(); // Give the products on the user
      } else {
         _handleInvalidPurchase(purchase);
      }
    }
 purchaseDetailsList.forEach((PurchaseDetails purchaseDetails) async {
      if (purchaseDetails.status == PurchaseStatus.pending) { 
        print('Pending..');
      } else {
        if (purchaseDetails.status == PurchaseStatus.error) {
         print('To purchases status error: ${purchaseDetails.error}');
        } else if (purchaseDetails.status == PurchaseStatus.purchased) {
          verifyPurchase(purchaseDetails.productID); // change value of _isPurchased
          if (_isPurchased) {
            _purchases.add(purchaseDetails);
     
            for(String id in _myProductsIds) {
              if (purchaseDetails.productID == id) {
                await deliverProduct(); // Give the products on the user
              }
            }
          } else {
            _handleInvalidPurchase(purchaseDetails);
            return;
          }
        }
        if (Platform.isAndroid) {
          for(String id in _myProductsIds) {
            if (purchaseDetails.productID == id) {
              await InAppPurchaseConnection.instance
                  .consumePurchase(purchaseDetails);
            }
          }
        }
        if (purchaseDetails.pendingCompletePurchase) {
          var completePurchase = await InAppPurchaseConnection.instance
              .completePurchase(purchaseDetails);
        }
      }

【问题讨论】:

    标签: flutter dart in-app-purchase


    【解决方案1】:

    如果平台是android,我不知道为什么在官方示例中有consumePurchase,但是由于这段代码,我的应用程序崩溃了,并且在重要行中返回了错误“Developer.error”,并且他们是

    var completePurchase = await InAppPurchaseConnection.instance
                  .completePurchase(purchaseDetails);
    

    我阅读了 completePurchase 方法的文档,我看到了重要的评论,内容如下:

      /// The [consumePurchase] acts as an implicit [completePurchase] on Android.
      Future<BillingResultWrapper> completePurchase(PurchaseDetails purchase);
    

    也许应用内购买的版本有更新,在此之后某个示例没有更新。

    示例链接:https://github.com/flutter/plugins/tree/master/packages/in_app_purchase/in_app_purchase/example

    【讨论】:

      猜你喜欢
      • 2017-11-16
      • 1970-01-01
      • 1970-01-01
      • 2017-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多