I am working on an IAP feature in my iOS app, and when testing I found that the payment sheets takes a long time to show up. So I added a “wait panel”, which simply shows up until there is a successful or failed purchase. However, this is very inconsistent, some times the “wait panel” deactivates but other times it does not. When I debug the code, it seems like the OnPurchaseFailed event was not even called when an user cancels the payment sheet. Same for successful purchase
public void BuyMonthlySubscription()
{
waitPanel.SetActive(true);
m_StoreController.InitiatePurchase(ProductsCatalog.monthlySubscriptionId);
}
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
// Retrieve the purchased product
var product = args.purchasedProduct;
UpdateUI();
isSubscribedText.text = purchaseInProgress ? "Processing" : "You are subscribed";
waitPanel.SetActive(false);
// We return Complete, informing IAP that the processing on our side is done and the transaction can be closed.
return PurchaseProcessingResult.Complete;
}
public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
{
waitPanel.SetActive(false);
}
public void OnPurchaseFailed(Product product, PurchaseFailureDescription failureDescription)
{
waitPanel.SetActive(false);
}
void UpdateUI()
{
var subscriptionProduct = m_StoreController.products.WithID(ProductsCatalog.monthlySubscriptionId);
try
{
// updates texts with subscription info
}
catch (StoreSubscriptionInfoNotSupportedException)
{
}
waitPanel.SetActive(false);
}