Getting Unity IAP receipt data to validate with playfab (or somewhere else)

Hello there,

I’m kinda stuck at the moment.

I implemented the Unity IAP system and after making a purchase I receive the receipt.

Now I have to extract values from the receipt to validate the receipt itself, specifically the json/signature for validating the google receipt and the receipt data/purchase price for ios.

I realize the data is there, as Unity - Manual: Purchase Receipts says so, but I currently don’t know how to access it.

Can you help me with that problem?

Thanks in advance.

@kendogar Sure.

There are a few use-cases: (1) validating the receipt client-side (locally, to block on-device consumption of product for fraudulent purchases) using our CrossPlatformValidator class, (2) validating the receipt server-side (for reporting, not for blocking), and (3) validating the receipt through other means.

(1) I recommend looking at this doc: Unity - Manual: Receipt validation
Specifically, look at the “ProcessPurchase” code sample there. It gives you a boolean in your app with the fact of “valid or not”.

(2) Unity Analytics will automatically receive Unity IAP transaction logs to generate reports, validating receipts for you server-side if you configure with Analytics your game’s cryptographic public keys, showing you what money could be verified cryptographically. Use the Data Explorer in Unity Analytics: https://analytics.cloud.unity3d.com/ > “Data Explorer” > “Metrics and Custom Events” > change the drop-down to various Verified Revenue options to see the info!

(3) If you just want to parse out the receipt data for passing to PlayFab (et al), then I recommend also following the link’s instructions of (1). This means adding the Google Play Public Key from your Play Store Developer Console and using the little Unity IAP addition to the Window menu, first.

(3.1) Or if you’re feeling adventurous then crack the Unity Receipt field (product.receipt) as it’s JSON-wrapped-JSON for GooglePlay, and JSON-wrapped-base64-wrapped-ASN.1 for Apple. MiniJSON is a JSON parser I’ve had luck with.

var wrapper = (Dictionary<string, object>) MiniJson.JsonDecode (purchaseEventArgs.purchasedProduct.receipt);
if (null == wrapper) {
    return;
}

// Corresponds to http://docs.unity3d.com/Manual/UnityIAPPurchaseReceipts.html
var store = (string)wrapper ["Store"];
var payload = (string)wrapper ["Payload"]; // For Apple this will be the base64 encoded ASN.1 receipt

// For GooglePlay payload contains more JSON
if (Application.platform == RuntimePlatform.Android) {
    var gpDetails = (Dictionary<string, object>)MiniJson.JsonDecode (payload);
    var gpJson = (string)details ["json"];
    var gpSig = (string)details ["signature"];
}

Hi there,

This is all great, could you give more information on how does this work with Samsung Galaxy store? I am using Unity 5.4.1f1 with the latest version of IAP plugins that support Samsung galaxy IAP.

How do I get the receipt for a Samsung transaction? Should be we relying on the Google Playstore receipt validation instead?

@nicholasr Did you use the same approach for IOS receipt? As the IOS receipt has different parameters so how did you extract the ReceiptData, CurrencyCode and PurchasePrice from the IOS receipt to send to Playfab.