Hello Unity IAP Team,
When using codeless IAP, shouldn’t any purchase attempt be expected to end either via OnPurchaseComplete or OnPurchaseFailed?
Because, if the store is not correctly initialized (for example, internet was not available at app start), a LogError message is delivered, but the OnPurchaseFailed event is not triggered and the whole purchasing process fails. We’ve run into a few scenarios, on iOS, where this behavior proved to be an issue - because Apple expects the App to pause itself while waiting for the store operation to complete.
We’ve made our own hack inside the IAPButtonStoreManager.Instance.InitiatePurchase(string productID) method to force it to trigger OnPurchaseFailed in this scenario but it is kind of dirty and we must make sure not to break anything any time we update the IAP. Would it be possible for you to make this behaviour the standard for Codeless IAP?
Anyway, big shout-out to you for developing Codeless IAP - it has certainly made configuring products and integrating Unity IAP much faster.
Cheers,
Alex.
@sharkyro ,
Thanks for the report. We’re looking into this issue some more.
Would you be able to provide the complete hack you used?
The underlying problem is that if the Purchasing system is never initialized, then the callbacks are never linked to the functions set in the IAP button. If Initialization is started and then fails, then the the callbacks should be setup correctly and you would get the expected OnPurchaseFailed call when the purchase is attempted.
Hi @ap-unity ,
What I did was to alter the InitiatePurchase() function inside the IAPButtonStoreManager:
public void InitiatePurchase(string productID)
{
if(controller == null)
{
// This foreach is the hack
foreach(var button in activeButtons)
{
if(button.productId == productID)
{
button.OnPurchaseFailed(null, PurchaseFailureReason.PurchasingUnavailable);
}
}
// --------------
Debug.LogError("Purchase failed because Purchasing was not initialized correctly");
return;
}
controller.InitiatePurchase(productID);
}
Later edit: If I may add another suggestion/feature request - would it be possible to allow a manual initialization of the store? If the user is not online when the app starts, at the moment, the only way to get IAP working is an app restart.
Thank you,
Alex.
@sharkyro
Thanks for that code snippet. From discussing this with the IAP team, it sounds like this scenario is something we should be able to cover in a future version of the plugin.