android - 恢复购买在 Flutter/Google Play 中不起作用

标签 android flutter google-play flutter-in-app-purchase

我已根据 in_app_purchase 在应用程序购买 (IAP) 中实现包example
我可以从商店购买产品(我只有一个设置)。但是在测试“用户有一部新手机”的场景时,恢复购买似乎不起作用。也没有错误。
我已经在提供者模式中实现了这一点。存储连接初始化如下:

_isStoreAvailable = await _inAppPurchase.isAvailable();
采购是这样实现的:
 Future<void> initializePurchase() async {
      ProductDetailsResponse response =
          await _inAppPurchase.queryProductDetails(_productIds);
      if (response.notFoundIDs.isNotEmpty) {
        // Handle the error.
        print("not found product in store!)");
      } else {
        PurchaseParam purchaseParam = PurchaseParam(
          productDetails: response.productDetails.first,
        );
        _inAppPurchase.buyNonConsumable(purchaseParam: purchaseParam);
      }
  }
我使用以下代码监听更改:
  final Stream<List<PurchaseDetails>> purchaseUpdated =
        _inAppPurchase.purchaseStream;
    _subscription =
        purchaseUpdated.listen((List<PurchaseDetails> purchaseDetailsList) {
      _listenToPurchaseUpdated(purchaseDetailsList);
    }, onDone: () {
      _subscription.cancel();
    }, onError: (error) {
      print("listen error: $error");
    });
...和这个
  Future<void> _listenToPurchaseUpdated(
      List<PurchaseDetails> purchaseDetailsList) async {
    for (final PurchaseDetails purchaseDetails in purchaseDetailsList) {
      if (purchaseDetails.status != PurchaseStatus.pending) {
        if (purchaseDetails.status == PurchaseStatus.error) {
          //handle error
        } else if (purchaseDetails.status == PurchaseStatus.purchased ||
            purchaseDetails.status == PurchaseStatus.restored) {

          setLicense(StoreLicenseStatus.paid);
          notifyListeners();

          if (purchaseDetails.pendingCompletePurchase) {
            await _inAppPurchase.completePurchase(purchaseDetails);
          }
        }
      }
    }
  }
用户可以使用以下代码请求恢复购买:
 Future<void> restorePurchases() async {
    await _inAppPurchase.restorePurchases();
  }
除了恢复之外的一切都有效。我可以购买产品,清除数据,当我再次启动应用程序时,如果我尝试购买,我会收到来自商店的消息“您已经拥有该商品”。所以商店承认该产品已被购买,太棒了!但是当我点击“恢复”时,什么也没有发生。
我在这里错过了什么吗?
这是在模拟器(Pixel 4 API 32)上,也在真实设备上。

最佳答案

对我来说完全一样的情况。尽管我肯定有购买,但恢复购买并不能恢复任何东西。
此外,我必须提到,当我在本地构建应用程序(调试和 Release模式)时,它可以完美运行,但是当我使用 CICD 构建它并进行 Firebase App Distribution 或 Play Console 内部测试时,就会出现问题。
GitHub thread .

关于android - 恢复购买在 Flutter/Google Play 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72928285/

相关文章:

android - 如何在android中生成小apk

java - Android WebView 中的 Fragment

android - 有没有办法从另一个 android 应用程序获取 android 应用程序 View 层次结构?

android - 如何从最近导出的 Activity 中排除?

flutter - Flutter 中的响应式 MultiChildRenderObjectWidget

flutter - cmd 上的“flutter 医生”命令不起作用

android - Facebook Analytics 上的安装不同于 iTunes Connect 和 Google Play

unity3d - 在Unity中设置Google Play游戏时,我不断收到无效的类名:发现歧义匹配错误

dart - Flutter Firestore 离线持久化

android - 添加 flavor 后将apk上传到现有的Play商店项目