question

josephferano avatar image
josephferano asked

How does Unity provide the iOS Restore Purchase Receipt?

Hello, we've been having issues restoring purchases for iOS. We're a little confused as to what's happening.

We went through the docs, as well as these forum posts. Here are the relevant links;

https://api.playfab.com/documentation/Client/method/RestoreIOSPurchases
https://community.playfab.com/questions/6045/restoring-purchases-multiple-playfab-accounts.html
https://community.playfab.com/questions/5815/receipt-validation-iosandroid-after-restore-purcha.html

They keep making a reference to `restoreCompleteTransactions`
https://developer.apple.com/documentation/storekit/skpaymentqueue/1506123-restorecompletedtransactions

What I'm getting from this documentation is that this iOS call will return a single receipt for all purchases, which is what PlayFab then uses.

However, this does not seem to be what the Unity API provides;
https://docs.unity3d.com/Manual/UnityIAPiOSMAS.html

Their example docs show a method called `GetExtension<IAppleExtensions> ().RestoreTransactions`

However, the callback just returns a boolean and it just calls `ProcessPurchase` for each productId found in the restore purchases call. We send this receipt to both `ValidateIOSReceipt` and `RestoreIOSPurchases` but both API calls return an error saying that the receipts have already been validated. Oddly enough, we don't experience this behavior on Android and the receipts get validated.

Any input would be appreciated. We already have a cloudscript to grant items for Android when restoring purchases, but since the Validate seems to be working we haven't used it.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Andy avatar image
Andy answered

An answer was provided in private support. Summarizing here for others that may run into this:

The way receipt validation works (for all platforms), we record the ID of the specific receipt, so that replay attacks won't work (a common technique for getting free things in games is to re-send the receipt multiple times). So if you're just getting the same receipt again, it will always fail with that error.

Now, as stated in one of the PlayFab forum posts linked, Apple provides this via their Restore Receipt (https://developer.apple.com/documentation/storekit/skpaymentqueue/1506123-restorecompletedtransactions), while Google does not.

For the Apple Restore Receipt, yes, the call at the OS level must be to restoreCompletedTransactions. The example Unity gives, where nothing changes except the top-level transactions ID, is due to using SKReceiptRefreshRequest. A refreshreceipt is just the same receipts sent back to the client. Only a restorereceipt is different from the original receipt. So if you're getting back a "used receipt" error, that would mean that under the covers, the call you're making to Unity is returning a refresh receipt, instead of a restore receipt.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

countinglampposts avatar image countinglampposts commented ·

So I have come to this same conclusion after a lot of testing. Has anyone found a way to get the restore receipt in Unity?

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.