简体   繁体   English

如何在Flutter中访问应用内购买历史记录?

[英]How to access in-app purchase history in flutter?

I would like to implement in-app purchases in flutter using the flutter_inapp_purchase library. 我想使用flutter_inapp_purchase库在flutter中实现应用内购买。

Purchasing the item using buyProduct() already works, however I would like to ensure that customers who have already purchased an item are forwarded automatically and are not interrupted with the purchase dialog. 使用buyProduct()购买商品已经可以了,但是我想确保已经购买商品的客户能够自动转发,并且不会被购买对话框打断。 This is why I request the purchase history of the customer with 这就是为什么我要求客户的购买历史

List<PurchasedItem> purchaseHistory =
                      await FlutterInappPurchase.getPurchaseHistory();

However I have trouble working with the received purchaseHistory list, how do I now check whether the in-app purchase id of eg 'com.test.points100' is contained in that list or not, ie whether the user has already purchased the item wtih the id 'com.test.points100' ? 但是,我在处理收到的purchaseHistory列表时遇到麻烦,现在如何检查该列表中是否包含例如'com.test.points100'的应用内购买标识,即用户是否已经购买了商品'com.test.points100'吗?

Did you try 你试过了吗

List<PurchasedItem> purchaseHistory =
                  await FlutterInappPurchase.getPurchaseHistory();
int purchaseIndex = purchaseHistory.indexWhere((item) =>
    item.productId == "com.test.points100"
);
bool hasPurchased = purchaseIndex >= 0;

Note I'm not familiar with this library - it may be that getPurchaseHistory returns cancelled or invalid purchases as well - better check that. 请注意,我对该库不熟悉-可能是getPurchaseHistory返回取消的商品或无效的购买商品-最好检查一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM