Search Unity

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

Discussion in 'Unity IAP' started by greenyello, Feb 18, 2016.

Thread Status:
Not open for further replies.
  1. greenyello

    greenyello

    Joined:
    Apr 19, 2013
    Posts:
    18
    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
      • 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
      • If you are using Prime31 plugin
        • Pass in GooglePurchase “signature” property.

    couln't i get receipt , signature only with Unity IAP api?
     
  2. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
  3. greenyello

    greenyello

    Joined:
    Apr 19, 2013
    Posts:
    18

    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 )

     
  4. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
  5. JennyHide

    JennyHide

    Joined:
    Sep 30, 2014
    Posts:
    47
    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 https://developer.android.com/google/play/billing/billing_integrate.html#Purchase).

    The Unity docs, http://docs.unity3d.com/Manual/UnityIAPPurchaseReceipts.html, indicate that this information is in the receipt when the ProcessPurchase method is called (which happens when a purchase is made):

    Code (CSharp):
    1. public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    2. {
    3.     string receipt = args.purchasedProduct.receipt;
    4. }
    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!
     
  6. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    Hi @EdgeOfCode 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.

    Code (CSharp):
    1. string receipt = args.purchasedProduct.receipt;
    2. var wrapper = (Dictionary<string, object>) MiniJson.JsonDecode (receipt);
    3. if (null == wrapper) {
    4.      throw new InvalidReceiptDataException ();
    5. }
    6.  
    7. var store = (string)wrapper ["Store"];
    8. var payload = (string)wrapper ["Payload"];
    9.  
    10. var details = (Dictionary<string, object>)MiniJson.JsonDecode (payload);
    11. var json = (string)details ["json"]; // This is the INAPP_PURCHASE_DATA information
    12. 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:
    Code (CSharp):
    1. var result = validator.Validate(e.purchasedProduct.receipt);
    Does that make more sense?
     
    JennyHide, nicholasr and mpinol like this.
  7. JennyHide

    JennyHide

    Joined:
    Sep 30, 2014
    Posts:
    47
    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?
     
    Last edited: Mar 14, 2016
  8. JennyHide

    JennyHide

    Joined:
    Sep 30, 2014
    Posts:
    47
  9. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    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)
     
    JennyHide and erika_d like this.
  10. JennyHide

    JennyHide

    Joined:
    Sep 30, 2014
    Posts:
    47
    Awesome.
     
    erika_d likes this.
  11. Mighty_Dragon_Studios

    Mighty_Dragon_Studios

    Joined:
    Jul 17, 2016
    Posts:
    23
    What to do when I get:

    'MiniJson' is inaccessible due to its protection level
     
  12. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    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.
     
    Last edited: Jul 19, 2016
  13. afftar

    afftar

    Joined:
    Apr 18, 2014
    Posts:
    65
    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?
     
Thread Status:
Not open for further replies.