Search Unity

Does Unity IAP save pending transaction receipt to the cloud?

Discussion in 'Unity IAP' started by LiuChong, Oct 14, 2018.

  1. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    Hello,

    Just wondering does Unity IAP save pending transaction receipts to the cloud automatically? to make sure pengding transaction can be processed even after player uninstall and re-install the app? If so, when will the pending transaction receipts be saved?

    Thanks,
     
    Last edited: Oct 14, 2018
  2. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    220
    Hi,
    Unity IAP sends every transaction receipt to Unity Analytics before calling 'ProcessPurchase'. But it's used to track transactions in Unity Analytics instead of making sure a pending transaction can be processed again.
    Unity IAP will save a transaction record locally when you return 'PurchaseProcessingResult.Complete' in 'ProcessPurchase' or call 'm_Controller.ConfirmPendingPurchase'.
     
    mchenard_bhvr likes this.
  3. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    Thanks for your quick reply, what i am wondering is how unity working with the pending transactions. For example, a user has a pending purchase transaction record locally for some reason. If he uninstall and reinstall the game, the pending record should be removed, right? But we noticed that some players still have the pending payment after re-install.

    Could you let me know what is the reason? Is it something controlled by Unity IAP or not?
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  5. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    But if the pending purchase transaction record is saved locally, how does the game know if there is a pending purchase after uninstall and re-install? after uninstalling, the pending purchase transaction record should be already deleted, right?
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    My understanding is that the store keeps a record of these pending transactions across installs and across devices (for the same user), I will confirm with the IAP team. Why do you have pending transactions? Just checking, it makes sense if you are doing server side receipt validation for example. What specific behavior are you seeing during your testing?
     
  7. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    220
    For Google Play, Unity IAP will retrieve all of your already-owned products during initialization, including Non-Consumable, Subscription and pending Consumable products.
    For App Store, Unity IAP will do the same operation when you restore your products.
    Then Unity IAP will call ProcessPurchase if it doesn't find a local record.
     
  8. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    @JeffDUnity3D @unityjingyao Thanks for your quick response. I know Google Play will keep the non-consumable IAP, and it can be restored even after uninstall and reinstall, but are you sure the Google Play and iOS will keep the pending consumable product?

    From the store side, a pending consumable product should be already finished. Just not passed our own server side validation for some reason.
     
  9. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    So i am wondering does Unity IAP save this kind of purchase transaction record to some cloud? coz we do have some players still have this pending status even after they uninstall and re-install the game.
     
  10. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    We test on iOS, when there is a pending consumable payment transaction, after uninstall and reinstall the game, it can still be processed by Unity IAP, how can Unity IAP know about it?
     
  11. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    220
    Yes, I can confirm that Google Play and App Store keep the pending transactions.
    For each purchase, you need to call an API to inform the store that a purchase is finished successfully. This action is called 'consume product' on Google Play, or 'finish transaction' on App Store.
    Unity IAP doesn't save pending transactions to track the inventory. It only retrieves them from the app stores.
     
  12. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    Got it, thanks Jingyao.

    Another question: Since we have a lot of different in-game IAP packages, so we are using one store product ID corresponding to multiple in-game IAP package ID, is there any best practice how to handle the pending transaction in-game IAP package ID? We currently saved it to PlayerPrefs, and send it to server along with the receipt to verify payment, but after uninstall and reinstall, it will be gone.
     
    Last edited: Oct 18, 2018
  13. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    220
    I'm sorry that Unity IAP doesn't handle the inventory, you have to do it on your own.
    For pending transactions, app stores will do that for you. I don't think that you need to do any extra work.
    Regarding the product ID, PurchaseEventArgs offers two fields to indicate the ID:
    PurchaseEventArgs
    .purchasedProduct.definition.id and
    PurchaseEventArgs
    .purchasedProduct.definition.storeSpecificId.
    The first one is the unified product ID used in your game, and the second one is the ID you configured on app store side.
     
  14. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    Thanks @unityjingyao

    Do you mean the purchasedProduct.definition.id is a customized parameter that we can set by ourselves?
     
  15. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    220
    Yes, please find the demo script in 'Assets/Plugins/UnityPurchasing/script/IAPDemo.cs'.
    Code (CSharp):
    1. // In this case our products have the same identifier across all the App stores,
    2. // except on the Mac App store where product IDs cannot be reused across both Mac and
    3. // iOS stores.
    4. // So on the Mac App store our products have different identifiers,
    5. // and we tell Unity IAP this by using the IDs class.
    6. builder.AddProduct("100.gold.coins", ProductType.Consumable, new IDs
    7.     {
    8.         {"com.unity3d.unityiap.unityiapdemo.100goldcoins.7", MacAppStore.Name},
    9.         {"000000596586", TizenStore.Name},
    10.         {"com.ff", MoolahAppStore.Name},
    11.         {"100.gold.coins", AmazonApps.Name}
    12.     }
    13. );
     
  16. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    Thanks @unityjingyao , but this is not my question. My question is we have one store product ID corresponding to multiple in-game IAP package IDs. For example, we have a "100.gold.coins" Product ID, but actually in the game there are may be 5 different packs reusing this Produce ID. One of them gives play 100 more food, the other one gives player 100 more wood, etc. Am I clear now?
     
  17. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    Since Unity IAP does not handle inventory management, your scenario will be treated as if you only have a single product, which is how the stores will treat it as well.
     
  18. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    @ap-unity We currently saved the in-game specific IAP package ID to PlayerPrefs, and send it to server along with the receipt to verify payment and send correct together, but after uninstall and reinstall, it is no way to know which is the specific in-game IAP package ID. Do you have any suggestions how to implement this scenario?
     
  19. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    220
    Thanks for the clarification. It's clear now.
    You can use 'developerPayload' to do that for Google Play.
    If you are using Unity IAP 1.19+, you can refer to the code below.
    Code (CSharp):
    1. // When you buy a product, offer a value to the 'payload' parameter.
    2. m_Controller.InitiatePurchase(m_Controller.products.WithID(productID), "aDemoDeveloperPayload");
    3.  
    4. ...
    5.  
    6. public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
    7. {
    8. ...
    9.     string developerPayload = null;
    10.     var receiptDict = (Dictionary<string, object>)MiniJson.JsonDecode(e.purchasedProduct.receipt);
    11.     if (receiptDict.ContainsKey("Store") && receiptDict.ContainsKey("Payload"))
    12.     {
    13.         var payload = (string)receiptDict["Payload"];
    14.         if ((string)receiptDict["Store"] == GooglePlay.Name && payload != null)
    15.         {
    16.             var payloadDict = (Dictionary<string, object>)MiniJson.JsonDecode(payload);
    17.             if (payloadDict.ContainsKey("json"))
    18.             {
    19.                 var jsonDict = (Dictionary<string, object>)MiniJson.JsonDecode((string)payloadDict["json"]);
    20.                 if (jsonDict != null && jsonDict.ContainsKey("developerPayload"))
    21.                 {
    22.                     var developerPayloadJSON = (string)jsonDict["developerPayload"];
    23.                     var developerPayloadDict = (Dictionary<string, object>)MiniJson.JsonDecode(developerPayloadJSON);
    24.                     byte[] bytes = System.Convert.FromBase64String((string)developerPayloadDict["developerPayload"]);
    25.                     developerPayload = System.Text.Encoding.UTF8.GetString(bytes);
    26.                 }
    27.             }
    28.         }
    29.     }
    30.     // 'aDemoDeveloperPayload' will be outputed.
    31.     Debug.Log("developerPayload: " + developerPayload);
    32. ...
    33. }
    App Store doesn't support this feature. I'm sorry I don't have a suggestion for App Store yet.
     
  20. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    @unityjingyao Thank you very much, do you know if other platforms have this feature, like Amazon, Samsung, Windows, or Facebook payment ?
     
  21. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    220
    As far as I know, only Google Play has this feature, at least in Unity IAP. Maybe other stores also have a similar feature, but I've never investigated yet.
     
  22. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    Thank you very much
     
  23. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    @unityjingyao another question, do you know if PlayerPrefs will be saved to iCloud on iOS by default?
     
  24. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @LiuChong No, PlayerPrefs is only local to the device and is not saved to the cloud.
     
  25. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    I mean the iCloud on iOS, do you think it will be synced to iCould in some situation?
     
  26. unityjingyao

    unityjingyao

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    220
  27. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    No
     
  28. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    @JeffDUnity3D thank you for reply, so you mean this folder /Library/Preferences/[bundle identifier].plist. will not be synced to iCloud? No matter what kind of settings the user did on iCould?
     
  29. rickypu

    rickypu

    Joined:
    Aug 7, 2013
    Posts:
    9
    @LiuChong are you solution to the problem on ios?
     
  30. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Last edited: Oct 25, 2018
  31. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    @rickypu, no we don't have a prefect solution on iOS, just save to PlayerPrefs.
    @JeffDUnity3D But why some of our players still get the PlayerPrefs back after they uninstall and reinstalled the game?
     
  32. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    If they get PlayerPrefs back, it may be a bug which may be fixed in other versions or due to the OS version, hard to say. At any rate, you should not depend on it.
     
  33. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    @JeffDUnity3D So technically, with Unity, all local persistent files will be removed upon uninstalling, right?
     
  34. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @LiuChong PlayerPrefs, yes. If you save files to an SD card or similar, then they may persist. We don't have specific recommendations however. Is there a reason you don't want to save purchases to the cloud using your own server? You could use AWS, Azure or Google for a few dollars a month (or even use a free tier!)
     
    Last edited: Oct 26, 2018
  35. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    @JeffDUnity3D Yes we are using our own server to save purchases. The reason we use PlayerPrefs is to save our own in-game payment package IDs. So we we know which specific in-game package ID, and we can send to server for verification. I think @unityjingyao knows clearly about my issue.
     
  36. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @LiuChong Understood, good luck on your development.
     
  37. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
  38. LiuChong

    LiuChong

    Joined:
    May 10, 2017
    Posts:
    22
    @JeffDUnity3D @unityjingyao Hello guys, hope you are doing great. Do you know if Apple IAP support developer payout or not? and what will happen if i set a developer payout on iOS with Unity IAP? Thank you
     
  39. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    I believe you mean payload. The developer payload has been deprecated on both iOS and Android as far as I know. Feel free to test it.