【问题标题】:Flutter: purchases stream is empty and attempted purchase throws 'pending transaction for the same product identifier'Flutter:购买流为空,尝试购买会抛出“相同产品标识符的待处理交易”
【发布时间】:2020-05-10 12:48:58
【问题描述】:

我正在使用 Flutter in_app_purchase 插件,v0.3.3+1

在 iOS 上进行测试时,我开始购买,但中途取消了。之后,每当我再次尝试购买时,都会收到一条异常消息:

同一产品标识符有一个待处理的交易

我在购买流(下面的代码)上设置了一个监听器来完成购买。但是流没有发出任何事件。

_purchaseListener = InAppPurchaseConnection.instance.purchaseUpdatedStream.listen((purchases) {
  purchases.forEach((purchase) async {
    if (purchase.status == PurchaseStatus.purchased) //...
    if (purchase.pendingCompletePurchase) {
      //Complete purchase (retrying as Google Play refunds after 3 days if this does not succeed)
      retry<BillingResultWrapper>(() async {
        final completion = await InAppPurchaseConnection.instance.completePurchase(purchase);
        const errors = {BillingResponse.error, BillingResponse.serviceUnavailable};
        if (errors.contains(completion.responseCode)) throw Exception();
        return completion;
      });
    }
  });
});

【问题讨论】:

    标签: flutter in-app-purchase in-app-billing


    【解决方案1】:

    您必须先清理待处理的事务

    var paymentWrapper = SKPaymentQueueWrapper();
    var transactions = await paymentWrapper.transactions();
    transactions.forEach((transaction) async {
      await paymentWrapper.finishTransaction(transaction);
    });
    

    【讨论】:

    • 我怎样才能访问 SKPaymentQueueWrapper() 。我有一个错误未定义函数“SKPaymentQueueWrapper”。
    • 我已修复 -> 导入 'package:in_app_purchase_ios/store_kit_wrappers.dart';
    【解决方案2】:

    流在debug 模式下没有发出任何事件,因此购买从未通过并完成。

    release模式下测试,完美运行。

    【讨论】:

    • 您是如何在发布模式下使用沙盒用户进行测试的?
    • 也许更重要的是,一旦你弄清楚出了什么问题,你是如何设法清除队列的?
    猜你喜欢
    • 1970-01-01
    • 2011-12-10
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-16
    相关资源
    最近更新 更多