firebaseflutterdartin-app-purchaseflutter-in-app-purchase

Flutter In app purchase - How allow purchase based on the user that is logged?


I'm building a flutter app that will allow users to subscribe. I'm using this plugin: in_app_purchase 0.5.2

So, my question is: I have to log my users in, and I do this using firebase Auth. But, how can I check which user is logged to deliver them the right purchase? I mean, using the firebase Auth, where or must I check if the current user has purchased something?


Solution

  • You can use a database like firestore to store all the purchase information. Ex: Users/Auth-id

    then retrieve it whenever needed. you can also get the previous purchases with the API

    Ex:

    final QueryPurchaseDetailsResponse response = await InAppPurchaseConnection.instance.queryPastPurchases(); //returns previous purchases 
    

    Note that the App Store does not have any APIs for querying consumable products, and Google Play considers consumable products to no longer be owned once they're marked as consumed and fails to return them here. For restoring these across devices you'll need to persist them on your own server and query that as well.