Search Unity

[Solved] Android Test Purchases Fail Receipt Validation

Discussion in 'Unity IAP' started by lblast, Mar 21, 2017.

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

    lblast

    Joined:
    Dec 1, 2016
    Posts:
    68
    Hi there,

    I've implemented Unity IAP fairly successfully on both iOS and Android. What I am currently having a problem with is the local receipt validation.

    Purchase flow works up until my ProcessPurchase function which calls ReceiptValidationCheck. I have implemented it to match https://docs.unity3d.com/Manual/UnityIAPValidatingReceipts.html. I have used the Obfuscator to tangle the license key for our app from the Google Play Developer Console (http://puu.sh/uTv3T/d920b0efd5.png).

    Then the error I get is: UnityIAP receipt validation failed. Item not granted.

    I do get what appears to be a legitimate receipt (some information redacted): http://puu.sh/uTvB1/340f80d7ea.png

    Receipt validation does work on iOS using the same method.

    Thanks for any help.
     
  2. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @lblast

    Which version of Unity and the IAP plugin are you using?

    Would you be able to provide a copy of your purchasing script and a device log when the purchase fails?

    If your code is structured similarly to the example you linked, it sounds like an IAPSecurityException is being thrown. It would good to confirm if that is the case.
     
  3. lblast

    lblast

    Joined:
    Dec 1, 2016
    Posts:
    68
    I have attached my purchasing script and I am using the most recent Unity IAP (http://puu.sh/vahjo/624be23227.png). If it is a IAPSecurityException what would be the likely culprit? I have attempted regenerating the tangles but I didn't get any better results.
     

    Attached Files:

  4. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @lblast

    Sorry for the delayed response.

    The problem is with this section:
    Code (CSharp):
    1. if (receipt.transactionID != purchaseDetails.purchasedProduct.transactionID)
    2. {
    3.     continue;
    4. }
    5.  
    Based on the receipt that you linked to in your first post, it looks like you are using test purchases (which is expected). Google Test purchases don't have the orderID (which is called transactionID in the GooglePlayReceipt class) in the receipt, so that will always fail.

    (In the Unity receipt, we take the purchaseToken and make it the transactionID, which you can verify in your logs. However, the CrossPlatformValidator parses the receipt that comes from the store.)

    That section should work fine in production (since the transactionID and the orderID should be equivalent).
     
  5. lblast

    lblast

    Joined:
    Dec 1, 2016
    Posts:
    68
    Ah, thank you.
     
Thread Status:
Not open for further replies.