How do you check if someone has bought anything?



  • Hey. We would like to remove adverts if someone has bought any IAP. But the app is live so we could add a bool when you buy something but it wont count for existing users that has bought something. We have tried doing this.

    if (DBManager.isPurchased("X"))
    {
    //Turn off Ads
    }
    

    But it does not work for consumables.

    Any ideas



  • Hello Martin,

    regarding the thread title, you've answered yourself with the code snippet already.

    To be more specific about consumables - these type of purchases are not stored anywhere. If Unity IAP or we would keep them on the device forever, you could not buy a consumable again, ever. Then they would actually be non-consumables. Consumables are "consumed" immediately and so is their purchase receipt. Therefore, DBManager.isPurchased works for non-consumables and subscriptions only, which are not consumed.

    In your case, typically you would introduce another variable in the IAPListener's HandleSuccessfulPurchase method by calling DBManager.SetPlayerData. For example, SetPlayerData("no_ads", new JSONData(true)). This would be called every time a purchase has been made, allowing you to check it later. Note that since this is saved locally, users playing on multiple devices but only buying consumables on one of them, do not have that variable on all devices.

    Existing users: you are basically out of luck here. There is no way to recover consumable purchases without using a cloud provider for inventory management (like PlayFab). Neither Unity IAP nor SIS provides access to past consumable purchases since that would be a major security risk for users restoring the same (consumed) purchases over and over again.


Log in to reply