Search Unity

Saving Purchased Items

Discussion in 'Unity IAP' started by onurduha, Mar 9, 2019.

  1. onurduha

    onurduha

    Joined:
    Dec 29, 2018
    Posts:
    51
    Im implementing codeless IAP in my app, but I have some questions. I have 5 consumable and one non-consumable, so let's say player bought 100 gold and remove ads and deleted app or changed his/her phone. After reinstalling the game are these purchases restoring or they have to buy again. How can I save the purchase history. My purchase script is below.

    Code (CSharp):
    1. if(product != null)
    2.         {
    3.             switch (product.definition.id)
    4.             {
    5.                 case "Gold.50":
    6.                     PlayerPrefs.SetInt("Gold", PlayerPrefs.GetInt("Gold") + 50);
    7.                     GoldText.text = PlayerPrefs.GetInt("Gold").ToString();
    8.                     Debug.Log("Completed");
    9.                     break;
    10.                 case "Gold.100":
    11.                     PlayerPrefs.SetInt("Gold", PlayerPrefs.GetInt("Gold") + 100);
    12.                     GoldText.text = PlayerPrefs.GetInt("Gold").ToString();
    13.                     Debug.Log("Completed");
    14.                     break;
    15.                 case "Gold.250":
    16.                     PlayerPrefs.SetInt("Gold", PlayerPrefs.GetInt("Gold") + 250);
    17.                     GoldText.text = PlayerPrefs.GetInt("Gold").ToString();
    18.                     Debug.Log("Completed");
    19.                     break;
    20.                 case "Gold.500":
    21.                     PlayerPrefs.SetInt("Gold", PlayerPrefs.GetInt("Gold") + 500);
    22.                     GoldText.text = PlayerPrefs.GetInt("Gold").ToString();
    23.                     Debug.Log("Completed");
    24.                     break;
    25.                 case "Gold.1000":
    26.                     PlayerPrefs.SetInt("Gold", PlayerPrefs.GetInt("Gold") + 1000);
    27.                     GoldText.text = PlayerPrefs.GetInt("Gold").ToString();
    28.                     Debug.Log("Completed");
    29.                     break;
    30.                 case "removeads":
    31.                     break;
    32.                 default:
    33.                     Debug.Log("Failed");
    34.                     break;
    35.             }
    36.         }
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Use server side database.
     
  3. onurduha

    onurduha

    Joined:
    Dec 29, 2018
    Posts:
    51
    Can you explain more. Im really new with these things and I didn't understand sorry :)
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    I am sure you know what I mean, if you talking about purchased in app.
    Otherwise, how you would deal with in game purchases itself?

    Basically you need store relevant information on some server.
    If you not familiar with a subject, I suggest search and read about it.
     
  5. onurduha

    onurduha

    Joined:
    Dec 29, 2018
    Posts:
    51
    ohh ok. Can I use google play services cloud saving
     
  6. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Use whatever is suitable for your project.
    Do your research first.
     
  7. onurduha

    onurduha

    Joined:
    Dec 29, 2018
    Posts:
    51
    I did research before writing here. but I could not find what I wanted so I opened the subject here. if I had found what I want, I wouldn't open the subject here. I just want to save the purchase history, so that when the player reinstall the game, can get back what he/she bought. The question was so simple. what I need to use to save the purchase history
     
    g3r0nt1u5 likes this.
  8. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    As I said, you need use some form of database on the server.
    This is in brief as it can be, to give the idea about searching for information.

    From what you describe you don't want save on local device history.
    Because database subject is beyond your current expertise, that is why I suggested you to read about this.

    Look about clouds, database storing data, Unity and you will find tons of subjects.
    I am not going into what services are available, as this is ocean topic by its own.

    You could use web request from Unity to PhP to save on the server.
    But this may be too complex at this stage for you.
    Not that can not be learned of course.
    Depends what you really need.
     
  9. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    A good solution, as mentioned, is to use a web service API to write to a database on the server. So as a first step you would need a public server, like on AWS or Azure or Google Cloud. You can develop on your own computer, but you need it to be running a local web server and a local database like MySQL.