question

nick-3 avatar image
nick-3 asked

Help with RedeemAppleAppStoreInventoryItems

Hi there.
I am working on getting Economy V2 configured for the Apple Store. When using the PlayFabEconomyAPI.RedeemAppleAppStoreInventoryItems call, I am getting back an error saying that I have a "malformed receipt".

Here is the code: public override void ValidateReceipt(PurchaseEventArgs eventArgs, Action successCallback, Action failedCallback) { validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.identifier);

         try
         {
             IPurchaseReceipt[] receipts = validator.Validate(eventArgs.purchasedProduct.receipt);
             foreach (IPurchaseReceipt receipt in receipts)
             {
                 AppleInAppPurchaseReceipt appleReceipt = receipt as AppleInAppPurchaseReceipt;
                 string receiptData = eventArgs.purchasedProduct.receipt;
                 receiptData = receiptData.Replace("\"", "");

                 RedeemAppleAppStoreInventoryItemsRequest request = new RedeemAppleAppStoreInventoryItemsRequest
                 {
                     Receipt = JsonConvert.SerializeObject(appleReceipt),
                     Entity = new EntityKey
                     {
                         Id = PlayFabSettings.staticPlayer.EntityId,
                         Type = PlayFabSettings.staticPlayer.EntityType
                     }
                 };
                 PlayFabEconomyAPI.RedeemAppleAppStoreInventoryItems(request, successCallback, failedCallback);
             }

         }
         catch (IAPSecurityException e)
         {
             Debug.LogException(e);
             return;
         }
         catch (Exception e)
         {
             Debug.LogException(e);
         }
     }

I've also tried using eventArgs.purchasedProduct.receipt as the value for RedeemAppleAppStoreInventoryItemsRequest.Receipt.

Hoping someone can tell me what I might be doing wrong here. I'm unclear on what the Receipt value really should be. Any help would be greatly appreciated.

Thanks, ~N

In-Game Economy
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

·
Simon Cui avatar image
Simon Cui answered

RedeemAppleAppStoreInventoryItems uses the validation process explained below.

Validating receipts with the App Store | Apple Developer Documentation

Make sure you obtain the receipt in the same way when calling the API.

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

nick-3 avatar image nick-3 commented ·

Thanks, Simon. That link was helpful, but also raised a few questions. Hopefully, you can help clarify.

When using the RedeemAppleAppStoreInventoryItems endpoint, we send the receipt in the request body or as the docs say "The receipt provided by the Apple marketplace upon successful purchase." We are getting a successful purchase. This data comes through our UnityIAP IStoreListener class with the PurchaseEventArgs object - I assume this is common for most PlayFab users. What I'm confused on exactly and hoping you can help. Does your Redeem endpoint for apple, require the receipt data to be in Base64 already, or does this handle that for us? What data, exactly, should we be sending in? Is it the PurchaseEventArgs.purchasedProduct.receipt object, or is it a patching of a few other things?

In the Apple docs link you posted, they are asking for a Password as part of that request body; however, in the RedeemAppleAppStoreInventoryItemsRequest object, I'm not seeing any way to include that information? Is this done through some other means I'm unaware of? As part of that Receipt object in the Redeem Items Request object?

Really need a bit more help here. 8( Thanks

0 Likes 0 ·
Simon Cui avatar image Simon Cui nick-3 commented ·

Referring to the Apple Official doc that I mentioned above: Validating receipts with the App Store | Apple Developer Documentation, you may try to send Base64-encoded data to your server. According to Purchase Receipts | In App Purchasing | 4.8.0 (unity3d.com) and Purchase Receipt | In App Purchasing | 4.8.0 (unity3d.com), the Payload in Purchase Receipts is a base 64 encoded App Receipt. Then you can refer to ValidateIOSReceipt - how to get base64 receipt for ReceiptData? - Playfab Community and set “Payload” as the receipt in RedeemAppleAppStoreInventoryItemsRequest.

0 Likes 0 ·
Simon Cui avatar image Simon Cui nick-3 commented ·

Besides, the password is your app’s shared secret, which should be filled in Apple add-on through Game Manager. 5946-image.png

0 Likes 0 ·
image.png (126.9 KiB)

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.