Xiaomi IAP FAQs

Unity partner page:

Xiaomi developer quick start guide:

Unity IAP Xiaomi integration guide:
https://docs.unity3d.com/Manual/UnityIAPXiaomi.html
Unity Channel SDK and API extensions:
https://docs.unity3d.com/Manual/UnityIAPXiaomiAPI.html

1. How may I test Xiaomi Mi Game Pay for Unity IAP (Xiaomi IAP)?
If you set appInfo.debug to true when initializing Xiaomi IAP, you’ll be able to test Xiaomi IAP without real money.
If you want to test real purchasing, you must set appInfo.debug to false. Please note that real purchasing requires a Xiaomi Mi Account and appropriate currency such as Chinese Yuan.
You can create a Mi Account on a Xiaomi device or Xiaomi official page: https://account.xiaomi.com

2. I found an “Unavailable product…” log message and OnInitializeFailed() was fired with an InitializationFailureReason.NoProductsAvailable reason.
Xiaomi IAP needs an IAP Catalog for product metadata before purchase.
Configure all your products in [Window > Unity IAP > IAP Catalog].
And then export the products by clicking “App Store Export → Xiaomi Mi Game Pay Catalog”.
This step will export all products to “Assets\Plugins\Android\assets\MiGameProductCatalog.prop” which will be read by the Xiaomi SDK.

3. How can I see the Xiaomi IAP log?
In Android Studio, you can filter log with “(/Unity)|(/MiGameSDK)”.

4. How to restore my products in Xiaomi store?
Xiaomi IAP doesn’t have “Restore” feature. If a user bought a non-consumable product and reinstalled your game, when he/she tries to buy again, OnPurchaseFailed() will be fired with a PurchaseFailureReason.DuplicateTransaction reason.
More information can be found in [Assets\Plugins\UnityPurchasing\script\IAPDemo.cs].

5. What version of Unity should I use if I want to integrate Xiaomi IAP?
Xiaomi IAP supports 5.3+.

6. I can’t buy a product when I set appInfo.debug to true, I found a “3001” error code in logcat printed by Xiaomi SDK.

“3001” means “product doesn’t exist”. Please contact with Xiaomi to check your product IDs.

7. When should our game make the call to login into the StoreService? Just before the player makes a purchase or rather at game startup?

(* Copied from IAPDemo.cs)
You just need to make sure that players login successfully before you call InitiatePurchase(). So both before the player makes a purchase and game startup are OK. It’s up to you.

8. I tried to sign in with Mi Account on my device, I have an error in unityChannelLoginHandler.loginFailedAction with “User Login Failed:-400” in the log.
Please contact with Xiaomi to confirm that your products have been configured.

9. We need the link to redirect player to the review page of the store during the game.
You can use “market://details?id=your package name” as an Intent to redirect player to the review page of Xiaomi store.
The URL for your game in Xiaomi app store(website) is “http://app.mi.com/details?id=your package name”.

10. My app crashed during initialization of UnityIAP and I found this crash log.

All of appId, appKey, clientId, clientKey are necessary for the initialization of UnityChannel. So if any of them is null or empty, an exception should be thrown.
appId and appKey can be any value in debug mode.

11. I can’t push my apk to Xiaomi Dev Portal. There is no “Push to Xiaomi” option on my Cloud Build dashboard.

The “Push to Xiaomi” option is only available to the Owner of the organization.

Other Tips

  1. Google Play services are not allowed in Xiaomi store.

  2. Xiaomi IAP needs an extra login step which other app stores don’t have. Please refer to Q7.

  3. App package name must end with “.mi”.

  4. The prices must follow the tiers of Xiaomi IAP. All tiers can be found in “IAP Catalog” window. [Window → Unity IAP → IAP Catalog]

3 Likes

Is there any chance this update makes some AliPay (or Xiaomi) related code get into the Xcode project? I got my app rejected by Apple stating AliPay is being used.

Hi! I’ve got the following error when pressing “Generate Unity Client”

How can I get error details?

3293782--255222--Без имени-1.png

Hi @hippogames
You can also find your Client ID, ClientKey, Client RSA Public Key and Client Secret via Unity Project ID on this page: Unity ID

Thanks! Seems I have no some kind of access to this project, and this is producing HTTP error. Anyway, I’ll request all required perissions from my game publisher.

And one more question. Can I add “Xiaomi Mi Game Center” from Build Settings instead of importing plugin? Because both they are producing conflicts. Are those plugins will be equal?

Hi @hippogames
You might get a conflict in some versions of Unity if you add both “Xiaomi Mi Game Center” from Build Settings and Unity IAP plugin. This is a known issue and we’ll fix it.
“Xiaomi Mi Game Center” is different from Unity IAP plugin.
Xiaomi requires that your game must have Xiaomi SDK integrated.
“Xiaomi Mi Game Center” is used for a game that doesn’t have IAP and it only has Xiaomi SDK.
Unity IAP has already integrated “Xiaomi Mi Game Center”(or Xiaomi SDK).
So if you have IAP in your game, please use Unity IAP.

Hi,

I try to integrate IAP for xiaomi but I have an error

I fill up the “AppStoreSettings” create by “Asset/Create/App Store Settings” with all data and I try the class UnityChannelSample as descrive on google document “[2017.1 DRAFT] Unity IAP - Xiaomi Game Center Installation And Setup Guide - Google Docs” but I receive the following error, I’m missing somethings?

Exception: JNI: Init'd AndroidJavaClass with null ptr!
UnityEngine.AndroidJavaClass..ctor (IntPtr jclass) (at /Users/builduser/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:622)
UnityEngine.AndroidJavaObject.get_JavaLangClass () (at /Users/builduser/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:600)
UnityEngine.AndroidJavaObject.FindClass (System.String name) (at /Users/builduser/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:591)
UnityEngine.AndroidJavaClass._AndroidJavaClass (System.String className) (at /Users/builduser/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:611)
UnityEngine.AndroidJavaClass..ctor (System.String className) (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/AndroidJavaBindings.gen.cs:92)
UnityEngine.Store.StoreService..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for UnityEngine.Store.StoreService
UnityChannelSample.Start () (at Assets/UnityChannelSample.cs:47)

Hi, Can someone share IAP Purchase script for Xiaomi? I have spent hours but can’t figure it out this: https://docs.unity3d.com/Manual/UnityIAPXiaomi.html

There are scripts available at that location that you can use. Did you have a specific question on the code implementation? Are you receiving an error?

That scripts are my problem :smile: I just don’t know how to add "Client-side initialization" part to my code. My IAP script same as this tutorial and works with Google Play.

Can you be more specific? The code is listed on the page, have you tried placing that code into your project? Step 2 goes in your Awake method, for example, and uses the code from Step 1.

Yes, I tried. When I added them, I get lots of errors:

  • error CS0246: The type or namespace name `AppStoreSupport’ could not be found. Are you missing an assembly reference?
  • You are trying to create a MonoBehaviour using the ‘new’ keyword. This is not allowed (code: SampleLoginListener loginListener = new SampleLoginListener()
  • Exception: JNI: Init’d AndroidJavaClass with null ptr!

Also where should I call Buy function (controller.InitiatePurchase(product)? I can’t access other class from base class.

Taking it one step at a time, let’s fix the first error. Did you import the IAP asset described previously in the document?

Hi @wonderkid ,
That tutorial doesn’t have the implement of Xiaomi IAP.
You can find a demo script in [Assets\Plugins\UnityPurchasing\script\IAPDemo.cs] and a demo scene in [Assets\Plugins\UnityPurchasing\scenes].

@JeffDUnity3D Do you mean importing Unity IAP from Services? If so, yes.
@unityjingyao Does IAPDemo.cs handles Xiaomi login and AppStoreSettings? I looked it and didn’t find anything.

I just want to know how to add Client-side initialization part to my IAP code. Copying these lines just throws errors.

Understood, we are continuing to research here. I too get errors, specifically when trying

using AppStoreSupport;

When I change it to “using AppStoresSupport;” error goes but I am not sure thats the solution. Also IAPDemo.cs doesn’t call that.

The “using” syntax is specified in the documentation, see attached.

1 Like

Hi @wonderkid ,
UnityIAP offers 2 ways to set up Xiaomi settings.

  1. Use App store settings.
    You can find the documentation on this page:
    https://docs.unity3d.com/Manual/UnityIAPXiaomi.html#AppStoreSettings
    Note: The AppStoreSettings Asset is only available in Unity 5.6+.

  2. Create an “AppInfo” manually.

AppInfo unityChannelAppInfo = new AppInfo();
unityChannelAppInfo.appId = “app id”;
unityChannelAppInfo.appKey = “app key”;
unityChannelAppInfo.clientId = “client id”;
unityChannelAppInfo.clientKey = “client key”;
unityChannelAppInfo.debug = false;

You can find this snippet in IAPDemo.cs.

I guess that you were using the first method without creating AppStoreSettings Asset file.
I’m sorry that we don’t make the second method clear in our Manual.
I’ll report it to the documentation team.