我如何知道用户是否使用 in_app_purchase Flutter 从 google play 商店取消订阅?

问题描述 投票:0回答:1

在内部测试中,如果我订阅然后从 Play 商店取消订阅,产品仍显示已购买。我想知道,如何检查用户是否从 Play 商店取消订阅该产品?

这是初始化函数

  Future initiazlize() async {
    final Stream<List<PurchaseDetails>> purchaseUpdated = _iap.purchaseStream;

    _subscription = purchaseUpdated.listen((purchaseDetailsList) async {
      _purchases.addAll(purchaseDetailsList);

      _listenToPurchaseUpdated(purchaseDetailsList);
      notifyListeners();
    },
    availble = await _iap.isAvailable();
    notifyListeners();
    if (availble == true) {
      print("Is store availble ${availble}");
      await _getProducts();
    }
  }

这是购买订阅功能

  buySubscription(String id) async{
    PurchaseParam purchaseParam = PurchaseParam(
        productDetails: _products.firstWhere((element) => element.id == id));
    try {
      await _iap.buyConsumable(purchaseParam: purchaseParam);
    } catch (e) {
      print('Error while buying ${e}');
    }
  }

这是购买更新功能

  void _listenToPurchaseUpdated(List<PurchaseDetails> purchaseDetailsList) {
    purchaseDetailsList.forEach((PurchaseDetails purchaseDetails) async {
      switch (purchaseDetails.status) {
        case PurchaseStatus.pending:

        //  _showPendingUI();
          break;
        case PurchaseStatus.purchased:
          if (purchaseDetails.productID == subscriptionId) {
            setPurchases(fASubscribed: true);
          }

          break;
        case PurchaseStatus.restored:
          if (purchaseDetails.productID == subscriptionId) {
            setPurchases(fASubscribed: true);
          }

          break;
        case PurchaseStatus.error:
          print(purchaseDetails.error);
          break;
        default:
          break;
      }

      if (purchaseDetails.pendingCompletePurchase) {
        await _iap.completePurchase(purchaseDetails);
      }
    });
  }

  }
}

flutter in-app-purchase
1个回答
0
投票

仅通过使用连接到商店的移动应用程序,您无法确定此人是否取消订阅。据我所知,每当进行购买时,您都需要将购买的商品存储在数据库中,并且在您的 Play Store/App Store 验证购买后,您必须调用移动应用程序中的

verifyPurchase
功能。服务器。关于如何检测用户何时取消订阅购买的问题,您必须使用 Firebase 将后端服务器连接到 Play 商店,并且还需要在 App Store 的情况下配置 Webhooks。本指南中解释了端到端应用内购买配置,请在此处查看:flutter-in-app-purchases

© www.soinside.com 2019 - 2024. All rights reserved.