I am trying to get IAP working. I thought I had it working on Apple App Store but when releasing it did not work. It is probably my fault as the code became very complex to be able to handle the UI portion.
I decided to re-read the manual and create a new simplified IAP-script based. The problem I have is that I get the following messages when purchasing remove_Ads in the Unity Editor:
- Purchase OK: remove_ads
- Receipt: {“Store”:“fake”,“TransactionID”:“4e59a66b-xxxxxxxxx-a228152a4fbd”,“Payload”:“{ "this" : "is a fake receipt" }”}
- Invalid receipt, not unlocking content
Looking at the code I would like to understand if exception this happens given the fact that I am running this in the Unity Editor rather than on the iPhone. Is it the fake receipt that trigger the IAPSecurityException?
If not, could someone advise my next step.
/// <summary>
/// Called when a purchase completes.
///
/// May be called at any time after OnInitialized().
/// </summary>
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
{
print(c + ") PurchaseProcessingResult");
c++;
Debug.Log("Purchase OK: " + e.purchasedProduct.definition.id);
Debug.Log("Receipt: " + e.purchasedProduct.receipt);
bool validPurchase = true; // Presume valid for platforms with no R.V.
// Unity IAP's validation logic is only included on these platforms.
#if UNITY_ANDROID || UNITY_IOS || UNITY_STANDALONE_OSX
// Prepare the validator with the secrets we prepared in the Editor
// obfuscation window.
var validator = new CrossPlatformValidator(GooglePlayTangle.Data(),
AppleTangle.Data(), Application.identifier);
try
{
// On Google Play, result has a single product ID.
// On Apple stores, receipts contain multiple products.
var result = validator.Validate(e.purchasedProduct.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);
}
}
catch (IAPSecurityException)
{
Debug.Log("Invalid receipt, not unlocking content");
validPurchase = false;
}
#endif
if (validPurchase)
{
// Unlock the appropriate content here.
print(c + ") Unlock the appropriate content here");
c++;
}
return PurchaseProcessingResult.Complete;
}