Question about receipt validation on android store. I have some code for a non-consumable IAP to verify that it hasn’t been refunded or cancelled. If it has, the code will remove the benefits they got from buying it.
The question is: if they purchase the non-consumable, get refunded, then purchase it again, will it return two product receipts, one good one refunded? Or will it only return the most recent receipt? I’m not sure how I could test this
The code I’m using is the below:
public bool ValidateVeteran()
{
if (!m_StoreController.products.WithID(veteran_productid).hasReceipt)
return false;
var validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.identifier);
statusUpdate("Verifying Receipt");
try
{
// On Google Play, result has a single product ID.
// On Apple stores, receipts contain multiple products.
var result = validator.Validate(m_StoreController.products.WithID(veteran_productid).receipt);
// For informational purposes, we list the receipt(s)
Debug.Log("Receipt is valid. Contents:");
foreach (IPurchaseReceipt productReceipt in result)
{
Debug.Log(productReceipt.productID);
Debug.Log(productReceipt.purchaseDate);
Debug.Log(productReceipt.transactionID);
if (productReceipt is GooglePlayReceipt google)
{
Debug.Log("Vet Purchase State: " + google.purchaseState);
if (google.purchaseState == GooglePurchaseState.Refunded || google.purchaseState == GooglePurchaseState.Cancelled)
return false;
}
}
return true;
}
catch (IAPSecurityException)
{
Debug.Log("Invalid receipt, not unlocking content");
//validPurchase = false;
}
return false;
}
Alternatively if there could be multiple receipts for the product return I would use this:
public bool ValidateVeteran()
{
if (!m_StoreController.products.WithID(veteran_productid).hasReceipt)
return false;
var validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.identifier);
statusUpdate("Verifying Receipt");
try
{
// On Google Play, result has a single product ID.
// On Apple stores, receipts contain multiple products.
var result = validator.Validate(m_StoreController.products.WithID(veteran_productid).receipt);
// For informational purposes, we list the receipt(s)
bool goodreceipt = false;
Debug.Log("Receipt is valid. Contents:");
foreach (IPurchaseReceipt productReceipt in result)
{
Debug.Log(productReceipt.productID);
Debug.Log(productReceipt.purchaseDate);
Debug.Log(productReceipt.transactionID);
if (productReceipt is GooglePlayReceipt google)
{
Debug.Log("Vet Purchase State: " + google.purchaseState);
if (google.purchaseState != GooglePurchaseState.Refunded && google.purchaseState != GooglePurchaseState.Cancelled)
goodreceipt = true;
}
}
return goodreceipt;
}
catch (IAPSecurityException)
{
Debug.Log("Invalid receipt, not unlocking content");
//validPurchase = false;
}
return false;
}