question

e.timofeev@flexilestudio.com avatar image
e.timofeev@flexilestudio.com asked

ValidateGooglePlayPurchase Invalid signature

I'm testing google IAP's with "Unity IAP" And have very strange results.

Only 1 from 20+ call ValidateGooglePlayPurchase return "OK". some times if you repeat request he can return "OK". but in most response is:

{

"code": 400,
"status": "BadRequest",
"error": "InvalidReceipt",
"errorCode": 1021,
"errorMessage": "Invalid signature"

}

for example. i request with:

"ReceiptJson":

{"orderId":"GPA.3308-5274-4198-51530","packageName":"pigbang.flex.su","productId":"pigbang.flex.su.billspack400","purchaseTime":1533326181614,"purchaseState":0,"purchaseToken":"jojhcaokfaalahadkcbnnpkn.AO-J1OxkKAHsSGQeXa6D_ajFm9e9eSSSXW_jvinq1PqQmpUdUmLrBxM7uXJhQvdF4hSaZ5uU3_4hGsPlYgKSjELUqIoAj9N9dPApT3MmfdrBjBA-WHdZ9axvtkYxrKHsBDw9EvO9zoPB"}

"Signature":

giCZwSDogBQffCiUWhADZZstbhOLwd1dvmfSaEjVAuSNWX6LNMEds9/M1/bFGaFp5+QyVFu1g2F6Q9paf4IXUrRkzYKtHZeHjj0mqX0Gi/wYHX+QO/tzmCGCpekiCNmWwFFVC7+uCO7FLWVfHEmgmEzmo6EI5zgTI2APjO8dv9T78P1JCj2NnlCMgTfKDFYChIIi4oiSbhT2RbnpRussMN78TsIGS8D7I48+up0CzPQ5rGRXYErx6YxRJ8A5KDfgJkV/bH6x0l9FLujBcRW2hbFM/9jTtiQpmt8maN4UtDGGW6pdNX7ZRgvmF3PVNhgKwq+jU2qk2+D+LeZuaSjOuA==

and it failed. After this I try make new IAP with:

"ReceiptJson":

{"orderId":"GPA.3394-3878-5611-84049","packageName":"pigbang.flex.su","productId":"pigbang.flex.su.billspack400","purchaseTime":1533326190900,"purchaseState":0,"purchaseToken":"nljmiclmobfkbikkildjhkia.AO-J1OyrZZVQH_hQf45fjJS_LJwppI7yz8q_uLPXK3Qu5MLKc6mWljkBegUMRpIOu0Ml88x0rBQUovdS_-ywBKqYr5mBevgu8T8yNcAyUM6xLuFAu9P6hcNY-7yTXoSZOTKXt036UGaV"}

"Signature":

AwHUQ+qTfebu1ulnFqYP0kDXfXAXgCzWkg5buwspxRPIn+eKb61qQ9zkxXZSQKwSeaOZZDDkOtNK9Q+pV9EkqQ5X2UwshmbQRSKeV3J5ERXV44vOSijiyJjLaTt/xCdTuui3aTCL5Yz4EAbJ5NTBzWhdRwi+JNXVSHzw6j5Sa4peAvCBFOM1oRgER84eXDLL9Dtzl5V/a3cdmjiedtW+tRkydXP2O3wLA7p8UNuGBqS5syjM98O8/aaA2BhYPUcfi7THvSoFLAaO5a6VcqgZpnYqfR70E6+5YxS4amnCtQ87YcgH82CcsPMJRkNDqjGlnjyypbDPVWPh3enGlv3Sjw==

and validate successful.

10 |1200

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

1 Answer

·
brendan avatar image
brendan answered

The "Invalid signature" errorMessage is only returned in cases where the SHA1 hash of the receipt content does not match the signature (converted from Base 64). That's specifically how you check the signature for validity. So if it's not matching, the receipt data you're being provided does not match what Google actually sent. From what we've been hearing on this topic, some Unity plugins do change the ordering of the parameters in the receipt, and some even remove some of the parameters from what they return to you. What you need to do is check if they have an option to return to you the original receipt.

1 comment
10 |1200

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

e.timofeev@flexilestudio.com avatar image e.timofeev@flexilestudio.com commented ·

I'm change my parcing code and disable Developmen Build and it works fine.

[Serializable]
public class ReceiptData
{
    [Serializable]
    public class PayloadData
    {
        public object json;
        public object signature;
    }

    public string Payload;

    public PayloadData payload => PlayFabSimpleJson.DeserializeObject<PayloadData>(Payload);
}

public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
    ReceiptData receipt = PlayFabSimpleJson.DeserializeObject<ReceiptData>(args.purchasedProduct.receipt);

    ValidateGooglePlayPurchaseRequest request = new ValidateGooglePlayPurchaseRequest();
    request.ReceiptJson = (string)receipt.payload.json;
    request.Signature = (string)receipt.payload.signature;

    // code...
}<br>
0 Likes 0 ·

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.