question

regularstormy avatar image
regularstormy asked

Apple (iOS) receipt validation in Unity with Unity IAP

I'm having trouble validating my iOS receipts. I am using Unity IAP and passing the receipt string it gives me to Playfab, but it always results in the error result code

21002 The data in the receipt-data property was malformed or missing.

(that's from Apple's documentation, describing the failure code)

Things I have tried:

1.I made a bundle in playfab with the same name as the consumable IAP I made in itunesconnect. I also tried making a regular item with a matching name.

2. I enabled the "Apple" add-on in my project settings in the PlayFab manager. In the plugin page, I specified the bundle identifier for my game, as well as the shared secret.

3. I made sure my bundle in playfab has a purchase price specified.

4. I have an auto-renewable IAP as one of the things you can purchase. I am able to check if it has expired by using an AppleReceiptParser to see the products and check the expiration date. This makes me think my receipt string is totally valid and not malformed.

So... I'm not sure what to try now. As far as I can tell I am passing a legit receipt to playfab, but it fails every time. Please help!

apis
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.

regularstormy avatar image regularstormy commented ·

To further verify that my receipt is valid, I tried using the local validation code supplied by Unity here:

https://docs.unity3d.com/Manual/UnityIAPValidatingReceipts.html

Running this code confirms the receipt is valid.

Why is Playfab (or Apple) telling me it isn't valid? Does playfab change the receipt before sending it to Apple? Or is Unity doing something strange?

0 Likes 0 ·
regularstormy avatar image
regularstormy answered
5 comments
10 |1200

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

brendan avatar image brendan commented ·

Yep, that's good info for Unity developers on how to parse out the receipt. One thing I will add though, is that the option 1 he lists (validating the receipt directly from the client) is one that I would strongly advise against, as it's trivially easy to cheat your IAP system, then.

0 Likes 0 ·
matt-6 avatar image matt-6 brendan commented ·

Do we have to extract the receipt payload? At the moment the receipt is going to playfab as:

"ReceiptContent": "{\"Store\":\"AppleAppStore\",\"TransactionID\":\"1000000495357731\",\"Payload\":\"MIIXlAYJKoZIhvcNAQcCoIIXhTCCF4 etc etc

and failing.

0 Likes 0 ·
Andy avatar image Andy ♦♦ matt-6 commented ·

You should be setting the ReceiptContent property to the payload you extract from the UnityIAP receipt. It should be just a Base64 encoded string. The Store and TransactionID are added by UnityIAP and not what we expect.

0 Likes 0 ·
Show more comments
Denzie Gray avatar image Denzie Gray brendan commented ·
0 Likes 0 ·
brendan avatar image
brendan answered

No, nothing about the receipt you send to us in the API call is changed in any way.The response you're seeing is specifically what's coming back from the Apple receipt validation endpoint, with no modification. Can you please send the specifics of what you're sending to the receipt validation API call endpoint?

10 |1200

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

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.