Search Unity

ios Restore Transactions appears to refresh receipts rather than restore.

Discussion in 'Unity IAP' started by playsportmatt, Jan 25, 2019.

  1. playsportmatt

    playsportmatt

    Joined:
    Sep 1, 2016
    Posts:
    4
    Hi, I'm following your example code for restoring transactions: https://docs.unity3d.com/Manual/UnityIAPiOSMAS.html

    Code (CSharp):
    1. mExtensions.GetExtension<IAppleExtensions>().RestoreTransactions(OnRestore);
    However, the external receipt validation (PlayFab) fails because the receipt has already been used. This seems to suggest the receipts are being refreshed rather than restored, which as I understand it would produce a new transaction & receipt - https://developer.apple.com/documen...23-restorecompletedtransactions?language=objc

    Additionally the docs say the user's password will be required to restore purchases, I'm not being asked for a password when trying to restore. I am asked for a password every time I purchase an item.

    I'm extracting the receipt like so:

    Code (CSharp):
    1. var wrapper = (Dictionary<string, object>)MiniJson.JsonDecode(e.purchasedProduct.receipt);
    2. var payload = (string)wrapper["Payload"];
    Is there something I'm missing or need to setup for this to work as expected?

    I am using 2018.2.4f1, the services tab says IAP is up to date, and the IAP package is 2.0.3 in the package manager.
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,914
    I am checking with the IAP team here, but I don't believe Restore creates a new transaction and receipt.
     
  3. playsportmatt

    playsportmatt

    Joined:
    Sep 1, 2016
    Posts:
    4
    It's this part of the Apple docs that suggest to me there should be a new receipt, there's a new transaction anyway.

    "The payment queue delivers a new transaction for each previously completed transaction that can be restored. Each transaction includes a copy of the original transaction."

    Perhaps I'm wrong, but if that's the case how does receipt validation work? I'm just getting errors about it being the same receipt.

    Also, as mentioned above I'm not being asked to enter a password for the restore in sandbox either.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,914
    You would want to contact Apple about the password in the Sandbox. You might count it as a blessing however, previously, a few months ago anyway, users were constantly being asked for their Sandbox password. So Apple may have removed it altogether. And do you really want to check a receipt on a Restore operation? A restore implies they already successfully and legitimately purchased previously.
     
  5. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,268
    Jumping in on this...

    Yes, I would really want to check the restore receipt again, especially when using PlayFab: when users are getting new devices, logging in with PlayFab creates a new account for them. If they forgot adding a persistent login method (like Facebook, or Google), they are forced to use their new PlayFab account. In this case, restoring purchases with Unity IAP & validating receipts fails, due to the receipts being used on a different PlayFab account already - because the transaction id in the restore receipt is the same. So on their new account, they are never able to get the product.

    I created a FogBugz entry for this in 2017 and it was never answered: 932848.
    Source
     
    JeffDUnity3D likes this.
  6. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,268
    Is this being looked at or should I create a new bug report with a recent Unity version (same information though)?
     
  7. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,914
    A bug report would not be necessary. Keep in mind that Apple returns all products in each receipt. Your users create their own PlayFab account? Perhaps I missed your point. Would this not be a PlayFab issue then?
     
  8. cabbyU

    cabbyU

    Joined:
    Sep 21, 2016
    Posts:
    8
    With PlayFab it's possible for this scenario to occur:

    1) A user creates an anonymous PlayFab account on one device and purchases a non-consumable
    2) The user gets a new device hooked up to the same iTunes account and creates a new anonymous PlayFab account (since there's no way to login to an anonymous account on multiple devices).

    On the second device, the user will never be able to purchase the non-consumable item, because according to iTunes it has already been purchased, and according to Playfab it has already been redeemed by the first anonymous account. PlayFab needs a new receipt in order to redeem the item on the second anonymous account, but as far as I can tell there isn't any way to do this with Unity. I'm also having this issue, and I'm now in the process of writing custom restore functionality because the built-in RestoreTransactions function appears to refresh rather than doing a true restore with new receipts.
     
  9. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,914
    Restore across devices is currently broken in IAP 1.22. You might test also with IAP 1.19 to confirm. But the user would not be expected to purchase the non-consumable again. But the product "Should" be restored when you call the Restore method https://docs.unity3d.com/Manual/UnityIAPRestoringTransactions.html and ProcessPurchase would be expected to fire for the product upon restore.
     
  10. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    2,268
    The issue is that the product is restored, but with the same transaction identifier. Which is different from what Apple mentions as I wrote above. We cannot send the same transaction identifier to PlayFab multiple times. I have actually given up on this ever getting fixed.