在内部测试中,如果我订阅然后从 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);
}
});
}
}
}
仅通过使用连接到商店的移动应用程序,您无法确定此人是否取消订阅。据我所知,每当进行购买时,您都需要将购买的商品存储在数据库中,并且在您的 Play Store/App Store 验证购买后,您必须调用移动应用程序中的
verifyPurchase
功能。服务器。关于如何检测用户何时取消订阅购买的问题,您必须使用 Firebase 将后端服务器连接到 Play 商店,并且还需要在 App Store 的情况下配置 Webhooks。本指南中解释了端到端应用内购买配置,请在此处查看:flutter-in-app-purchases