question

Alex Girgis avatar image
Alex Girgis asked

ValidateIOSReceipt - how to get base64 receipt for ReceiptData?

Hi Guys,

Apologies for my inexperience here. I know this question has been asked and I've read many answers which explain that (As I understand it) I need to parse the receipt from Apple before passing it to Playfab, but I'm having trouble understanding exactly how to do that.

Can anyone point me to any actual code for unity that parses the receipt which I'm currently getting from UnityEngine.Purchasing.Product.receipt and allows me to pass it here:

public void OnPurchasecomplete(UnityEngine.Purchasing.Product product) {

PlayFabClientAPI.ValidateIOSReceipt(new ValidateIOSReceiptRequest() {

CurrencyCode = product.metadata.isoCurrencyCode,

PurchasePrice = (int)(product.metadata.localizedPrice * 100),

// Pass in the receipt

ReceiptData = ???, // not sure how to get this exactly

I tried passing through product.receipt but it didn't work which I assume is because that's JSON format not base64?

The error was:

Validation failed: /Client/ValidateIOSReceipt: iTunes Sandbox validation result: 21002 (InvalidReceiptData) from https://sandbox.itunes.apple.com/verifyReceipt

I'm currently using codeless IAP.

Any help is much appreciated.

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.

JayZuo avatar image
JayZuo answered

As you are using Unity IAP, you can refer to Unity docs to get more details: Unity - Manual: Purchase Receipts (unity3d.com). Thus, the receipt you've got is a JSON string. You will need to deserialize it to get the base 64 encoded App Receipt. You can refer to the code in Getting started with PlayFab, Unity IAP, and Android - PlayFab. Although the code is written for Google Play, getting iOS payload would be similar.

public class iOSPurchase {
    // JSON Fields, ! Case-sensitive
    public string Store;
    public string TransactionID;
    public string Payload;

    public static iOSPurchase FromJson(string json) {
        var purchase = JsonUtility.FromJson<iOSPurchase>(json);
        return purchase;
    }
}
10 |1200

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

Rick Chen avatar image
Rick Chen answered

You may refer to this thread: https://answers.unity.com/questions/1191677/getting-unity-iap-receipt-data-to-validate-with-pl.html where you could parse the receipt using MiniJSON, then get the “Payload” field from the result. Or this thread: https://community.playfab.com/questions/16098/ios-purchase-validation-no-matching-catalogue-item.html, in the first codesnippet, at line 98, use the JsonMapper.ToObject to parse the receipt, then get the “Payload” field for the ReceiptData argument at line 103.

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.