Hi,
Now I’m testing Google deferred purchase using Unity IAP 4.4.1 on Unity 2020.3.40f1.
I found “googlePlayStoreExtensions.IsPurchasedProductDeferred(product)” returns false, so I logged “googlePlayStoreExtensions” variable, it was “UnityEngine.Purchasing.FakeGooglePlayStoreExtensions”.
It is no probrem after call “UnityPurchasing.Initialize(listener, builder)” for the first time, but “extensions.GetExtension()” returns Fake class after calling initialize for the second time. I’d like to call initialize several time during running app because products may change.
Do you have any solutions?
yuki_goto:
Hi,
Now I’m testing Google deferred purchase using Unity IAP 4.4.1 on Unity 2020.3.40f1.
I found “googlePlayStoreExtensions.IsPurchasedProductDeferred(product)” returns false, so I logged “googlePlayStoreExtensions” variable, it was “UnityEngine.Purchasing.FakeGooglePlayStoreExtensions”.
It is no probrem after call “UnityPurchasing.Initialize(listener, builder)” for the first time, but “extensions.GetExtension()” returns Fake class after calling initialize for the second time. I’d like to call initialize several time during running app because products may change.
Do you have any solutions?
Please share the code that you are using, we will take a look. Are you testing on an Android device or in the Editor?
I’m testing on Android device.
Our code is like the following.
After the first time initializing, I see “UnityEngine.Purchasing.MetricizedGooglePlayStoreExtensions” in the log, but second time “UnityEngine.Purchasing.FakeGooglePlayStoreExtensions”.
private static readonly IStoreListener listener = new StoreListener();
public static void Init()
{
ConfigurationBuilder builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
builder.Configure<IGooglePlayConfiguration>().SetDeferredPurchaseListener(OnGoogleDefferredPurchase);
foreach (var productId in productIds)
{
builder.AddProduct(productId, ProductType.Consumable);
}
UnityPurchasing.Initialize(listener, builder);
}
private class StoreListener : IStoreListener
{
private IGooglePlayStoreExtensions goooglePlayStoreExtension;
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
goooglePlayStoreExtension = extensions.GetExtension<IGooglePlayStoreExtensions>();
Debug.Log(goooglePlayStoreExtension);
}
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
Debug.Log("IsDeferred : " + googlePlayStoreExtensions.IsPurchasedProductDeferred(args.purchasedProduct));
}
....
}
Thanks.
yuki_goto:
I’m testing on Android device.
Our code is like the following.
After the first time initializing, I see “UnityEngine.Purchasing.MetricizedGooglePlayStoreExtensions” in the log, but second time “UnityEngine.Purchasing.FakeGooglePlayStoreExtensions”.
private static readonly IStoreListener listener = new StoreListener();
public static void Init()
{
ConfigurationBuilder builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
builder.Configure<IGooglePlayConfiguration>().SetDeferredPurchaseListener(OnGoogleDefferredPurchase);
foreach (var productId in productIds)
{
builder.AddProduct(productId, ProductType.Consumable);
}
UnityPurchasing.Initialize(listener, builder);
}
private class StoreListener : IStoreListener
{
private IGooglePlayStoreExtensions goooglePlayStoreExtension;
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
goooglePlayStoreExtension = extensions.GetExtension<IGooglePlayStoreExtensions>();
Debug.Log(goooglePlayStoreExtension);
}
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
Debug.Log("IsDeferred : " + googlePlayStoreExtensions.IsPurchasedProductDeferred(args.purchasedProduct));
}
....
}
Thanks.
What happens when you try to make a purchase? I will check also. Also please test with IAP 4.5.0. Was this working in a previous version for you?
We have no problem on making a purchase. I’m testing like the following on an Android device.
Login (Initialize)
Make a purchase by the “Slow test card” of Google Play.
Logout and login again (Initialize again)
Callback “ProcessPurchase” and “IsPurchasedProductDeferred” returns false though the purchase is not completed.
I’ll try IAP 4.5.0 latar.
So you do have a problem making a purchase, I just wanted to confirm. We will take a look.
I updated IAP to 4.5.0 and tested again. But it seems it has the same problem.
1 Like
Just ran into this same issue.
Digging into the source code it appears to be because the storeInstance is only ever created once:
InstantiateStore normally ends up calling BindGoogleExtension() which would then overwrite the fake store.
It appears it’s simply not safe to reinitialise UnityIAP, even though I have read otherwise here: How to re-initlaize IAP on iOS device on a running game?
@John_Corbett - Can the reinitialisation flow be fixed, please?