How can I get the user purchase history in flutter?

54 views Asked by At

Using the flutter_inapp_purchase I got successfully the user Googlepay history of past subscriptions. But when I use the same method for iOS, it doesn't work. It returns me an empty array. Is there any different way for be doing that? Can I still use this package for this purpose? The main reason why I'm doing this, is because I'm working on an app which has a previous version which used to allow users to make subscriptions, but in this version I'm working on, we do not have it anymore, but I need to know which users have made previously the subscription in the legacy app so I can treat this user in a different way.

PS: I have already added the Apple Pay Capability in xcode.

The following code returns me the purchase list:

Future _getPurchaseHistory() async {
    await FlutterInappPurchase.instance.initialize();
    //Initializes the plugin

    List<PurchasedItem>? items =
        await FlutterInappPurchase.instance.getPurchaseHistory();
    // Returns the past purchases
    for (var item in items!) {
      _purchases.add(item);
    }

    setState(() {
      _items = [];
      _purchases = items;
    });
  }

Thanks in advance.

0

There are 0 answers