Flutter:购买流为空,尝试购买抛出“同一产品标识符的待处理交易”

Xan*_*der 8 in-app-purchase in-app-billing flutter

我正在使用 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;
      });
    }
  });
});
Run Code Online (Sandbox Code Playgroud)

Xan*_*der 0

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

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

  • 您是如何在发布模式下与沙箱用户进行测试的? (9认同)
  • 也许更重要的是,一旦你弄清楚出了什么问题,你是如何设法清除队列的? (3认同)