When testing Unity IAP with a test user on an Android internal game build (using code based on the local receipt validation IAP sample), I’m getting this exception on every purchase when calling CrossPlatformValidator.Validate():
UnityEngine.Purchasing.Security.InvalidSignatureException. The same code works for iOS. I generated the GooglePlayTangle.cs. Unity version 6000.0.35f1, IAP 4.12.2. Is it expected to get this exception on an internal build with a test user, or is there anything else I should try/fix?
Exception stack trace:
Invalid receipt: UnityEngine.Purchasing.Security.InvalidSignatureException: Exception of type ‘UnityEngine.Purchasing.Security.InvalidSignatureException’ was thrown.
01-30 13:45:33.167 11631 11658 I Unity : at UnityEngine.Purchasing.Security.CrossPlatformValidator.Validate (System.String unityIAPReceipt) [0x00000] in <00000000000000000000000000000000>:0
Validation code:
var appleTangleData = m_UseAppleStoreKitTestCertificate ? AppleStoreKitTestTangle.Data() : AppleTangle.Data();
m_Validator = new CrossPlatformValidator(GooglePlayTangle.Data(), appleTangleData, Application.identifier);
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
//Retrieve the purchased product
var product = args.purchasedProduct;
var isPurchaseValid = IsPurchaseValid(product);
if (isPurchaseValid)
{
//Add the purchased product to the players inventory
UnlockContent(product);
Debug.Log("Valid receipt, unlocking content.");
}
else
{
Debug.Log("Invalid receipt, not unlocking content.");
}
//We return Complete, informing Unity IAP that the processing on our side is done and the transaction can be closed.
return PurchaseProcessingResult.Complete;
}
bool IsPurchaseValid(Product product)
{
//If we the validator doesn't support the current store, we assume the purchase is valid
if (IsCurrentStoreSupportedByValidator())
{
try
{
var result = m_Validator.Validate(product.receipt);
//The validator returns parsed receipts.
LogReceipts(result);
}
//If the purchase is deemed invalid, the validator throws an IAPSecurityException.
catch (IAPSecurityException reason)
{
Debug.Log($"Invalid receipt: {reason}");
return false;
}
}
return true;
}