ProcessPurchase partially fails with mobile data connection
Hi everyone, I got a little problem with Unity IAP on my Android game. When I purchase my consumable products when connected to internet with mobile datas, it looks like the ProcessPurchase Method fails. Let my explain more with my code.
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
if (string.Equals(args.purchasedProduct.definition.id, fiftyBrocoinsID, StringComparison.Ordinal))
{
Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
PlayerData.nbBrocoins += 50;
PlayerData.SaveBrocoinsAndAccess(); // the player datas are save successfully in any case
StartCoroutine(MakeNSoundsOfBrocoins(5)); // but sounds are not always played when connected to internet with mobile datas
}
else if (string.Equals(args.purchasedProduct.definition.id, fullAccessID, StringComparison.Ordinal))
{
Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
PlayerData.hasFullAccess = true;
mainMenu.UpdateToFullAccessDisplay();
PlayerData.SaveBrocoinsAndAccess();
StartCoroutine(MakeNSoundsOfBrocoins(10));
GetComponent<BroCoinMenu>().CheckIfFullAccessAndAdjustButtons();
}
else
Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id));
return PurchaseProcessingResult.Complete;
}
private IEnumerator MakeNSoundsOfBrocoins(int n)
{
for (int i = 0; i < n; i++)
{
AudioManagerForOneGame.am.PlaySound("OneBrocoin");
yield return new WaitForSecondsRealtime(0.2f);
}
}
So what happen is that when I buy 50 brocoins while connected to internet with mobile datas, the payment goes well, but sometime ( it happens about once in two), StartCoroutine(MakeNSoundsOfBrocoins(5));
doesnt make any sounds (yet PlayerData.nbBrocoins += 50;
and PlayerData.SaveBrocoinsAndAccess();
are called with no problem) and, when I close and then restart the game, I get 50 brocoins more (without paying more) and I hear the sounds from StartCoroutine(MakeNSoundsOfBrocoins(5));
!
So, my guess is that the ProcessPurchase method fails at StartCoroutine(MakeNSoundsOfBrocoins(5));
and the purchase is marked as Pending, and when I restart the game, it is done again and marked as completed this time. (I'm not sure though, this is what I think is happening but I might be completly wrong!)
What I don't understand is that it only happens when connected to internet with mobile datas, It work as intended with wifi or in the editor. What sould I do to fix this and be sure the player won't get the purchase twice ?
Thank you for your time !