Integration of Huawei IAP in Unity
By: Manoj Kumar
Tags: Unity, Apk, Huawei, Hms Core, Huawei Mobile Service

Integration of Huawei IAP in Unity

Overview

This article is based on Huawei’s In-App Purchases. I will develop a new demo game using Huawei IAP. I will provide the ads remove feature. So user can upgrade the game also can purchase other exciting feature in the game with an online payment using In-App Purchases.

Service Introduction

In-App Purchase allows the user to purchase an app-based item such as Game coins, app-based subscriptions. The developer advertises upgrades to the paid version, paid feature unlocks, special items for sale, or even ads other apps and services to anyone who downloads the free version. This allows the developer to profit despite giving the basic app itself away for free.

Huawei IAP provides a product management system (PMS) for managing the prices and languages of in-app products (including games) in multiple locations.

Following are 3 types of in-app products supported by the IAP:

1. Consumable: Consumables are used once, are depleted, and can be purchased again.

2. Non-consumable: Non-consumables are purchased once and do not expire.

3. Auto-renewable subscriptions: Users can purchase access to value-added functions or content in a specified period of time. The subscriptions are automatically renewed on a recurring basis until users decide to cancel.

Prerequisite

1. Unity Engine (Installed in the system)

2. Huawei phone

3. Visual Studio 2019

4. Android SDK and NDK (Build and Run)

5. Must have Huawei Developer Account

6. Must have Huawei Merchant Account

Integration process

1. Sign In and Create or Choose a project on AppGallery Connect portal.

2. Navigate to Project settings and download the configuration file.

3. Navigate to In-App Purchases and Copy Public Key.

4. Navigate to My Apps, click Operate, and then enter details in Add Product.

5. Click View and edit in the above image, enter Product price details, and then click Save.

6. Click Activate for product activation.

Game Development

1. Create a new game in Unity.

2. Now add game components and let us start game development.

3. Download HMS Unity Plugin from below site.

https://github.com/EvilMindDevs/hms-unity-plugin/releases

4. Open Unity Engine and import downloaded HMS Plugin.

Choose Assets > Import Package > Custom Package

5. Choose Huawei > App Gallery.

6. Provide the AppId and other details from agconnect-service.json file and click configure Manifest.

7. Create Huawei IAP based scripts.

I have created IapTestManager.cs file in which integrated Huawei in-app Purchase which redirects to the merchant account.

Click on IapTestManager.cs and open in Visual Studio 2019.

Result

Let us build the apk and install in android device.

.

Tips and Tricks

1. Download the latest HMS plugin.

2. HMS plugin v1.2.0 supports 7 kits.

3. HMS IAP supports multiple Consumable, Non-consumables and Auto-renewable subscriptions.

4. Consumables are used once, are depleted, and can be purchased again.

5. Non-consumables are purchased once and do not expire.

Conclusion

In this article, we have learned how to integrate Huawei IAP Kit in Unity-based Game.

User can get rid of ads if User purchases remove ads feature.

Thanks for reading this article. Be sure to like and comments to this article if you found it helpful. It means a lot to me.

References

https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/introduction-0000001050132986