3

使用flutter_inapp_purchase在 Flutter中实现 InApp 购买(非消耗品)。我有 1 个月、6 个月和 1 年的三个计划,现在我正在检查是否是 1 个月计划,然后检查transactionData并添加 30 天以检查其他 2 个计划的到期日期,但问题是当用户处于试用期时如何我可以查看试用期到期日期吗

List<String> storeItems = ['onemonth', 'sixmonth', 'oneyear'];
List<IAPItem> subscriptions = [];
List<PurchasedItem> purchasesSubscriptions = [];
StreamSubscription _purchaseUpdatedSubscription;
StreamSubscription _purchaseErrorSubscription;
StreamSubscription _conectionSubscription;
initPurchaseState(SportsProvider sportsProvider) async {

print("initPurchaseState");
await FlutterInappPurchase.instance.initConnection;
if (!mounted) return;

_conectionSubscription =
    FlutterInappPurchase.connectionUpdated.listen((connected) {
  print('connected: $connected');
});

_purchaseUpdatedSubscription =
    FlutterInappPurchase.purchaseUpdated.listen((productItem) {
  var data = jsonDecode(productItem.transactionReceipt);
  int purchaseState = data["purchaseState"];
  String productId = data["productId"];
  String purchaseToken = data["purchaseToken"];

  print("Data : ${data.toString()}, ${purchaseState}, ${productId}, ${purchaseToken}");
  print('purchase-updated: $productItem');
  FlutterInappPurchase.instance.finishTransaction(productItem);
});

_purchaseErrorSubscription =
    FlutterInappPurchase.purchaseError.listen((purchaseError) {
  print('purchase-error: $purchaseError');
});

subscriptions =
    await FlutterInappPurchase.instance.getSubscriptions(storeItems);
//print("subscriptions: ${subscriptions}");
//subscriptions.forEach((f){print("subscription : ${f.freeTrialPeriodAndroid}");});
subscriptions.forEach((f){print("subscriptionPeriodAndroid : ${f.subscriptionPeriodAndroid}");});
subscriptions.forEach((f){print("subscriptionPeriodAndroid : ${f.toString()}");});
subscriptions.forEach((f){print("subscriptionPeriodAndroid : ${f.originalJson}");});


//Here we check for 1 month subscription is available or not by passig productId and days
var isSubscribedForMonth = await FlutterInappPurchase.instance.checkSubscribed(sku:subscriptions[0].productId,duration: Duration(days: 30));
print(isSubscribedForMonth);
//Here we check for 1 month subscription is available or not by passig productId and days
var isSubscribedForSixMonth = await FlutterInappPurchase.instance.checkSubscribed(sku:subscriptions[1].productId,duration: Duration(days: 180));
print(isSubscribedForSixMonth);
//Same for one year 
//But how can identify the current subscription is on trial period?  

// code for already subscribed
}

有什么办法可以辨别当前是试用期还是常规期。

我已经尝试过这样的解决方案,但没有为我的问题得到任何相关的解决方案,

请帮我解决这个问题

如果需要更多说明,请发表评论

4

0 回答 0