Huawei Developers
Published in

Huawei Developers

Integrating HUAWEI In-App Purchases Using Unity

Huawei’s In-App Purchases (IAP) service allows you to offer in-app purchases and facilitates in-app payment. Users can purchase a variety of virtual products, including consumables and non-consumables.

1.1 Version Change History

1.1.1 Version Dependencies

l The SDK of the latest version can be used only on devices running HMS Core (APK) or later. If a user is using a device without HMS Core (APK) or later, the user will be directed to install it when it is called by your app. User devices need to run EMUI 3.0 or later or Android 4.4 or later (API level 19 or later). The Unity version must be 2018.4.25 or later.

1.2 Preparations

1.2.1 Importing Unity Assets

1. Open Asset Store in Unity.

Go to Window > Asset Store in Unity.

2. Search for and import the Unity Distribution Portal (UDP) asset in Asset Store. For information about UDP, please visit

1.2.2 App Development

Configure product information based on the sample, and then use the sample for test. Uploading Your Project to UDP

1. Go to Window > Unity Distribution Portal > Settings in Unity and click Go to the Services Window.

2. Select an organization.

3. linked your project to a UDP client

Go to Window > Unity Distribution Portal > Settings > Inspector in Unity and click Generate new UDP client.

4. Set Game Title and UDP Sandbox Test Accounts. Configuring Product Information in Your Unity Project

Go to Window > Unity Distribution Portal > Settings > Inspector > IAP Catalog.

After product information is configured, click Push to synchronize the information to UDP. Creating an App and Configuring Product Information in AppGallery Connect Creating an App

Create an app by following instructions in Creating an AppGallery Connect Project and Adding an App to the Project. The package name of the game for AppGalleryKit must end with .HUAWEI or .huawei. Otherwise, the game will be rejected. Configuring Product Information

1. Sign in to AppGallery Connect and click My projects. Select your project, enable In-App Purchases, and obtain the public key.

2. Sign in to AppGallery Connect and click My apps.

3. Click an app from the app list to add a product.

1. Go to Operate > Products > Product Management and click Add Product.

2. Configure product information, which must be the same as that configured in Unity.

3. Activate the product. Configuring the Unity Project Package Name

Go to Edit > Project Settings > Player, click the Android icon, and go to Other Settings.

Note: Ensure that the package name configured here must be the same as that in AppGallery Connect. All package names in AppGallery Connect must end with .huawei. If the package name in Unity does not end with .huawei, the UDP console will supplement it during repacking for name consistency. Configuring Product Information in GameManager

1. Drag UDPSampleScene to the top.

2. Enter the configured product ID in GameManger.

3. Push all configurations.

1.2.3 Testing the APK

1. Go to File > Build Settings > Android in Unity and click Switch Platform.

1.1 Select UDP/Sample/UDPSampleScene.

1.2 Build the project. Save and install the APK.

2. Use the configured sandbox test account to initialize the APK.

2.1 Open the APK and tap Init.

2.2 Enter the configured sandbox account.

3. Initialize the sandbox test.

4. Tap the Buy button to test the product purchase function.

Verify that the sandbox test is complete.

1.2.4 Repacking the APK

1. Sign in to the UDP console.

2. Click the newly created game.

3. Edit the game information and then click Release.

4. Choose HUAWEI AppGallery.

5. Unity will automatically find the project info that has same package name in AGC, Set your IAP public Key manually

6. Choose HUAWEI AppGallery and click Publish.

7. The UDP console repacks your APK.

8. Download the repacked APK, which supports payment by IAP.

For more details, you can go to:

l Our official website

l Our Development Documentation page, to find the documents you need

l Reddit to join our developer discussion

l GitHub to download demos and sample codes

l Stack Overflow to solve any integration problems

Original Source URL



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store