[Solved] Unity IAP Select store at runtime

Hi,
I’m encountering an issue with the latest Unity IAP v1.8.1, It’s always showing the Google Play IAP dialog instead the Amazon or Samsung Galaxy ones when these platforms are selected.

I initialized Unity IAP like this:

        var storeModule = StandardPurchasingModule.Instance();
        if (Application.platform == RuntimePlatform.Android)
        {
            if (MySelectedPlatform.Andoid == PlayStore)
            {
                storeModule = StandardPurchasingModule.Instance(AndroidStore.GooglePlay);
            }
            else if (MySelectedPlatform.Andoid == Amazon)
            {
                storeModule = StandardPurchasingModule.Instance(AndroidStore.AmazonAppStore);
            }
            else if (MySelectedPlatform.Andoid == Samsung)
            {
                storeModule = StandardPurchasingModule.Instance(AndroidStore.SamsungApps);
            }
        }
        ConfigurationBuilder builder = ConfigurationBuilder.Instance(storeModule);

        builder.AddProduct(iap.id, ProductType.Consumable, new IDs() {
                { iap.skuApple, AppleAppStore.Name},
                { iap.skuGooglePlay, GooglePlay.Name},
                { iap.skuAmazon, AmazonApps.Name}
            });
        UnityPurchasing.Initialize(this, builder);

I selected Windows → Unity IAP → Android → Select store at runtime.

And when I build I set the correct platform to be taken in account by Unity IAP.

Now that my app is released for GPlay, Amazon and Samsung, when user click on IAP purchase button, it always show the Google Play IAP dialog for all platforms instead of the Amazon and Samsung ones for these respective platforms!

1 Like

@ @erika_d @ @JayR Can you please look into this issue?

Hi @Wadjey ,

Looking at your code, it seems like you are initializing the instance of the module multiple times (Line 1 and then again in the if statements). I would try removing the first line and only initializing once you know what store you are using.

Also, would you be able to provide the code you are using to determine what Android platform the app is using? Are you using something like is mentioned in these stackoverflow threads:
https://stackoverflow.com/questions/10809438/how-to-know-an-application-is-installed-from-google-play-or-side-load
http://stackoverflow.com/questions/11072079/how-to-know-if-an-app-has-been-downloaded-from-google-play-or-amazon

The option to select stores at runtime has been causing some issues for users submitting to the app stores, so we are re-evaluating that as an option.

As for now, I would try removing the multiple initialization and maybe look into how you are determining the platform.

3 Likes

Hi,
Thanks for your help, it’s working for Amazon now, I’ll try later with Samsung.
I’m using an Enumerator with Android platforms names, and I set the target platform manually (from a list of my target platform in the inspector) before building, as my game has some specific behaviors for each platform. And the new feature “Select store at runtime” is very helpful for me, in the past I need to select my targeted platform two times (in my list in the inspector and also for Unity IAP), and this was causing problems as sometimes I forget to select the correct Unity IAP target platform!
Now I have to select the target Android platform only one time from my Android platforms list and all is OK :slight_smile:

1 Like