[Solved] [UnityIAP] should i make native android code for get Receipt, Signature?

i’m studying unity IAP receipt verification
and i found below

http://docs.unity3d.com/Manual/UnityAnalyticsReceiptVerification.html

receipt parameter

  • For Android
    To validate Android monetization, please enter your Google Public API Key in your Analytics dashboard Project Settings Form.

The Google Public API Key is needed for implementing receipt verification for in-app purchases (IAP) on Google Play. Your Google Public Key is under Google Play Developer console > All applications > Services & APIs > Your License Key For This Application. This is optional, but if you are developing for Android and have in-app purchases, we highly recommend implementing it.

  • receipt parameter*

  • If you leave this as null, this transaction will show up as Unverified Revenue

  • If you are writing a Native Android plugin

  • Pass in the the purchase data for the order, which is a String in JSON format that is mapped to the INAPP_PURCHASE_DATA key in the response Intent.

  • If you are using Unibill plugin

  • Parse the PurchasableItem’s “receipt” property as JSON, and pass in the value of the “json” property.

  • If you are using Prime31 plugin

  • Pass in GooglePurchase “originalJson” property

  • signature parameter*

  • If you leave this as null, this transaction will show up as Unverified Revenue

  • If you are writing a Native Android plugin

  • Pass in the the signature, which is mapped to the INAPP_DATA_SIGNATURE key in the response Intent.

  • If you are using Unibill plugin

  • Parse the PurchasableItem’s “receipt” property as JSON, and pass in the value of the signature property.

  • If you are using Prime31 plugin

  • Pass in GooglePurchase “signature” property.

couln’t i get receipt , signature only with Unity IAP api?

Yes, it is in the receipt unity IAP gives you.

self reply is
No,

unity IAP support
Receipt, Signature

as ProcessPurchases function’s parameter “receipt” by json format

i can parsing it to signature, purchase data( purchase token )

Hi @GRE ,

I’m not sure I understand your question. Can you please explain more what you’re looking for?

You can find the latest information about IAP receipt validation in the link on this post: [Solved] Get real receipt data from IAP payload - Unity Services - Unity Discussions

To use these latest features you will need to reimport the latest IAP SDK, which you can do from the services window by clicking the import button. Does that help?

I am looking for this information as well - I need to access the purchase data and data signature from Google Play (the information in INAPP_PURCHASE_DATA and INAPP_DATA_SIGNATURE from Google Play's billing system  |  Android Developers).

The Unity docs, Unity - Manual: Purchase Receipts, indicate that this information is in the receipt when the ProcessPurchase method is called (which happens when a purchase is made):

public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
    string receipt = args.purchasedProduct.receipt;
}

However, it’s not clear to me how to get the INAPP_PURCHASE_DATA and INAPP_DATA_SIGNATURE from this string. Do I just need to parse them out of the string receipt? I saw there’s a MiniJsonExtensions and JsonUtility class, but none of the methods seem to allow me to get a string out of the receipt string using the INAPP_PURCHASE_DATA string. Or do I just need to write something to parse this out myself? To sum up, the documentation says the INAPP_PURCHASE_DATA and INAPP_DATA_SIGNATURE information is in the receipt string, but not how to get it.

I also looked at the link you gave with the Receipt validation manual. However, if you mean that the info I need is in GooglePlayReceipt, the information in that manual doesn’t mention which variables INAPP_PURCHASE_DATA and INAPP_DATA_SIGNATURE correspond to.

Is the Receipt validation manual just a different way to get the same information that is already in the receipt string?

Thanks!

Hi @JennyHide_1 and @GRE ,

Thank you for your questions about parsing the receipt to get the INAPP_PURCHASE_DATA and INAPP_DATA_SIGNATURE information. Here is example code for how to actually get that information, we will be working to update the docs to include more detailed information on this. For converting strings to JSON we are using the MiniJson library, however any favorite JSON library should work. You’ll also note that, for users of our IAP system, to get the INAPP_PURCHASE_DATA and INAPP_DATA_SIGNATURE information the keys you are actually using to access them are json and signature, respectively.

string receipt = args.purchasedProduct.receipt;
var wrapper = (Dictionary<string, object>) MiniJson.JsonDecode (receipt);
if (null == wrapper) {
     throw new InvalidReceiptDataException ();
}

var store = (string)wrapper ["Store"];
var payload = (string)wrapper ["Payload"];

var details = (Dictionary<string, object>)MiniJson.JsonDecode (payload);
var json = (string)details ["json"]; // This is the INAPP_PURCHASE_DATA information
var sig = (string)details ["signature"]; // This is the INAPP_DATA_SIGNATURE information

As far as the information in the receipt validation guide goes, the payload is actually not currently accessible through the Google Play Receipt. To get that information you will want to continue to parse it out of the the receipt, as seen above. That receipt is also used for validation by passing it into Validator.validate, as seen in the guide:

var result = validator.Validate(e.purchasedProduct.receipt);

Does that make more sense?

3 Likes

Yes, that’s great - thank you.

Are there similar ways to get the following information?

-The xml receipt (string) returned from the windows phone 8 store. Is this just the whole receipt (args.purchasedProduct.receipt; ) when building for Windows phone?
-The receipt obtained from SKPaymentTransaction.transactionReceipt from Apple’s app store. Similarly, is this the whole receipt (args.purchasedProduct.receipt; ) when building for iOS?

@erica_d any ideas?

The receipt format is documented here; the outer receipt is JSON formatted on all platforms, with a ‘payload’ string that varies by platform. On Microsoft stores it is their XML receipt, on Apple it is the unified app receipt, not a transaction receipt (unless running on iOS < 7)

2 Likes

Awesome.

1 Like

What to do when I get:

‘MiniJson’ is inaccessible due to its protection level

Hi @Mighty_Dragon_Studios ,

We include a version of MiniJson, which is only available for our internal code to access. Therefore to use the library in your code you will need to include it yourself, and explicitly reference the namespace of the one you included. Note that you don’t have to use MiniJson, it is our Json-parsing library of choice, but if you have another you prefer you are welcome to use that one instead.

Its looks like anal penetration!
Why you can’t do something like this:

var result = validator.Validate(e.purchasedProduct.receipt);
foreach (IPurchaseReceipt productReceipt in result)
{
GooglePlayReceipt googleReceipt = productReceipt as GooglePlayReceipt;
var signature = googleReceipt.Signature;// This is the INAPP_DATA_SIGNATURE information
}

Wtf unity?