【问题标题】:How to access in-app purchase history in flutter?如何在 Flutter 中访问应用内购买历史记录?
【发布时间】:2019-03-06 18:16:30
【问题描述】:

我想使用 flutter_inapp_purchase 库在 Flutter 中实现应用内购买。

使用buyProduct() 购买商品已经可以了,但是我想确保已经购买商品的客户会自动转发并且不会被购买对话打断。这就是为什么我要求客户的购买历史记录

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

但是我在处理收到的purchaseHistory 列表时遇到了问题,我现在如何检查应用内购买 ID 是否为例如'com.test.points100' 是否包含在该列表中,即用户是否已经购买了 ID 为 'com.test.points100' 的商品?

【问题讨论】:

    标签: flutter in-app-purchase


    【解决方案1】:

    你试过了吗

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

    请注意,我不熟悉这个库 - getPurchaseHistory 也可能返回已取消或无效的购买 - 最好检查一下。

    【讨论】:

    • 成功了! getPurchaseHistory 似乎只包括有效和成功的购买,这应该使它成为我案例的一个很好的候选人。非常感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-23
    • 1970-01-01
    • 2021-07-26
    • 1970-01-01
    • 2022-07-25
    相关资源
    最近更新 更多