Integrating HUAWEI In-App Purchases Using Unity

Search This thread

riteshchanchal

Senior Member
Jun 24, 2020
73
56
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​

2640852000006560358.20210316065857.04052412201860937966225579083562:50520321102934:2800:CDDE483082C2D565AC3CE7807B491B6F84CAC29A3B4047EB1DCF6DCA22D054C8.png


1.1.1 Version Dependencies​

l The SDK of the latest version can be used only on devices running HMS Core (APK) 4.0.0.300 or later. If a user is using a device without HMS Core (APK) 4.0.0.300 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.

2640852000006560358.20210316065913.67989776515432682171901669130850:50520321102934:2800:5CC6D129ED0BD4BBAF739862AF460CC7FDBF61F767820A8A9C59E2CB3E1877C9.png




2. Search for and import the Unity Distribution Portal (UDP) asset in Asset Store. For information about UDP, please visit https://docs.unity3d.com/Packages/[email protected]/manual/index.html.

2640852000006560358.20210316070001.77514593822028493563226625490823:50520321102934:2800:ED36D89191BD0B3737A30543F3026FCD1C9827604426FFDE2286776314A09F86.png


1.2.2 App Development​

Configure product information based on the sample, and then use the sample for test.

1.2.2.1 Uploading Your Project to UDP​

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

2640852000006560358.20210316070012.18278173016226300355854373427303:50520321102934:2800:F9C5824729DAEA4D93A0167BA63B82EA31E4F4019DF1DC33997956342250047E.png


2. Select an organization.

2640852000006560358.20210316070020.86545744539965662147374558626277:50520321102934:2800:B2EBE4B18B355B76AB65C44A756149DF78770876077FAAEF0A76A35C764D71B2.png


3. linked your project to a UDP client

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

2640852000006560358.20210316070031.82352793437444787800542173684170:50520321102934:2800:785A4B3C9EE4B176A1AED6DEB4EFBE62B0B488DDA96402729D8CC6D4B65FF4EB.png


4. Set Game Title and UDP Sandbox Test Accounts.

2640852000006560358.20210316070040.13258831560142173192900032191662:50520321102934:2800:0D90B1433B29AFED80F7E91D29261B66D78B7DDC55957222AF6EA8E39892A04E.png


1.2.2.2 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.

2640852000006560358.20210316070048.84445687113513233874531133551764:50520321102934:2800:96125232D10B7481A3520338A6A65A57DE00D8EE52B175891EAF481B1213271B.png


2640852000006560358.20210316070059.11247649581938565077228056468929:50520321102934:2800:E5BE8BBF3B044F20B88EDF1C66DD4F4FE761C40B906828F60D4FC36F6BBB11D5.png


1.2.2.3 Creating an App and Configuring Product Information in AppGallery Connect​

1.2.2.3.1 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.

1.2.2.3.2 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.

2640852000006560358.20210316070114.20286715038069595440767502234397:50520321102934:2800:C75288EDCCF19E9B7C5C0CBC40499FB7A20962DAC1AD235F1E46CECB84284662.png


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

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

2640852000006560358.20210316070317.20643017033910048742051174534623:50520321102934:2800:19B87E82C73602BAAA6F4A5A8CB2E3D1A3305CC6DCB615D1DC1E2CC094906D32.png


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

2640852000006560358.20210316070355.62459472449108552017986506906987:50520321102934:2800:C7A6B86EACD80F201356F2AF494ACB99925E7AF3B91073B7A054B2DE70DBC8D6.png


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

2640852000006560358.20210316070409.15226901253538986042656661069408:50520321102934:2800:614BB2DC09780134004FC338319E109AE2729B348F87A997F9D0A8D550EB1A0D.png


3. Activate the product.

2640852000006560358.20210316070717.35414558925225474314996545856689:50520321102934:2800:F48F76409B9341C22318BCCE475AC4746E3C84B9A372A26BC1F4268A099A58BF.png


1.2.2.4 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.

2640852000006560358.20210316070727.99146585224184082284423778351942:50520321102934:2800:CE4C339763A04FE91B89FE833CB0FC4A5BF8E3369BEB0D692EC88FCC97DD7374.png


2640852000006560358.20210316070737.32788974833148185245671735981138:50520321102934:2800:C872840F7AC4752EB8D9752926FBA85BECB8C79FF230D9DFA6D6F04ED1098F0B.png


1.2.2.5 Configuring Product Information in GameManager​

1. Drag UDPSampleScene to the top.

2640852000006560358.20210316070748.53327011380570584245642197121523:50520321102934:2800:7442B8D3414A18548CADA292EA5F6273B8E68C70F7A4C121DE0A8C7E076747AD.png


2. Enter the configured product ID in GameManger.

2640852000006560358.20210316070800.86279619134373827287038899523244:50520321102934:2800:E5178C1ABCC4C4118AD90E3210DF39FAB59571F3B48189294341AD586A595D20.png


3. Push all configurations.

2640852000006560358.20210316070807.25893411680257335242449379359842:50520321102934:2800:90D8E58C0AD6A80202C5115CE081685AF7F6CE1CA7B26D03823C61ADF7FD8ECE.png


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.

2640852000006560358.20210316070821.62298513182960714991001835578606:50520321102934:2800:EF949003C8A0E3A42C9B138536A17918F604D570F449F195923705E377D78544.png


1.2 Build the project. Save and install the APK.

2640852000006560358.20210316070833.67809694061838556904151416860883:50520321102934:2800:E9237F5426196D4D58547967BD830BA3175E2C474949280F40B1A57A80CFC67D.png


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.

2640852000006560358.20210316070845.94896716331144643701272756288523:50520321102934:2800:29D67FA4A832BDFA29A0091A4CC59816F4C95058812B8B915E66D132508333B4.png
2640852000006560358.20210316070852.11348962442590572283194333660068:50520321102934:2800:F2BA363721B4E3E8C834506DF0CA7E9DA4A3CCA6505D210651D59E125EAA7BCA.png


3. Initialize the sandbox test.

2640852000006560358.20210316070902.57364608465890848290257348890060:50520321102934:2800:BBB696E3470C6A7009B1B65BA3773B5758B03130410CCBA0C48CC5C87F8C9717.png


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

2640852000006560358.20210316070926.34199463323113192977513972556935:50520321102934:2800:EB93ED0F3CA37EDFC15DA092FAD11F6752B124D4DC8220ACD4C2A73418D0A301.png


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.

2640852000006560358.20210316070937.04477487932328160473703028173627:50520321102934:2800:7CE5EFD743F0D872C181BB55DF823D8540F67833E483D3697E626177543BD216.png


3. Edit the game information and then click Release.

4. Choose HUAWEI AppGallery.

2640852000006560358.20210316072439.87814401127164981383571642143770:50520321102934:2800:FEA9E4F7C9CFAD5C77FB6C7F66B7D86CA985A0D8EAEF7491DF3EC5F91EC75C57.png


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

2640852000006560358.20210316072451.52155093802296203410927689104321:50520321102934:2800:637E2DA500286BE489824CAB36BC5E8DB1565B89B0B8972913DDC2B888AB1900.png


6. Choose HUAWEI AppGallery and click Publish.

2640852000006560358.20210316072501.41686802428654167951485638090072:50520321102934:2800:44F94E8BABFA95C55FC1708C4742072FAF73B07F2173A60DA172CE5876D6A264.png


7. The UDP console repacks your APK.

2640852000006560358.20210316072510.01088611823153992757944135983923:50520321102934:2800:D3B3A2F8DD1167004345BDBC092A3F37D0A48C7727667CE99ADE03D31BEB7794.png


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

2640852000006560358.20210316072517.78343886904616222652887886984649:50520321102934:2800:905EB804B2A4D925DFD9E28754C14C54FB9805AD69853153F91CB00882634F44.png





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
 
  • Like
Reactions: irahus

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    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​

    2640852000006560358.20210316065857.04052412201860937966225579083562:50520321102934:2800:CDDE483082C2D565AC3CE7807B491B6F84CAC29A3B4047EB1DCF6DCA22D054C8.png


    1.1.1 Version Dependencies​

    l The SDK of the latest version can be used only on devices running HMS Core (APK) 4.0.0.300 or later. If a user is using a device without HMS Core (APK) 4.0.0.300 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.

    2640852000006560358.20210316065913.67989776515432682171901669130850:50520321102934:2800:5CC6D129ED0BD4BBAF739862AF460CC7FDBF61F767820A8A9C59E2CB3E1877C9.png




    2. Search for and import the Unity Distribution Portal (UDP) asset in Asset Store. For information about UDP, please visit https://docs.unity3d.com/Packages/[email protected]/manual/index.html.

    2640852000006560358.20210316070001.77514593822028493563226625490823:50520321102934:2800:ED36D89191BD0B3737A30543F3026FCD1C9827604426FFDE2286776314A09F86.png


    1.2.2 App Development​

    Configure product information based on the sample, and then use the sample for test.

    1.2.2.1 Uploading Your Project to UDP​

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

    2640852000006560358.20210316070012.18278173016226300355854373427303:50520321102934:2800:F9C5824729DAEA4D93A0167BA63B82EA31E4F4019DF1DC33997956342250047E.png


    2. Select an organization.

    2640852000006560358.20210316070020.86545744539965662147374558626277:50520321102934:2800:B2EBE4B18B355B76AB65C44A756149DF78770876077FAAEF0A76A35C764D71B2.png


    3. linked your project to a UDP client

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

    2640852000006560358.20210316070031.82352793437444787800542173684170:50520321102934:2800:785A4B3C9EE4B176A1AED6DEB4EFBE62B0B488DDA96402729D8CC6D4B65FF4EB.png


    4. Set Game Title and UDP Sandbox Test Accounts.

    2640852000006560358.20210316070040.13258831560142173192900032191662:50520321102934:2800:0D90B1433B29AFED80F7E91D29261B66D78B7DDC55957222AF6EA8E39892A04E.png


    1.2.2.2 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.

    2640852000006560358.20210316070048.84445687113513233874531133551764:50520321102934:2800:96125232D10B7481A3520338A6A65A57DE00D8EE52B175891EAF481B1213271B.png


    2640852000006560358.20210316070059.11247649581938565077228056468929:50520321102934:2800:E5BE8BBF3B044F20B88EDF1C66DD4F4FE761C40B906828F60D4FC36F6BBB11D5.png


    1.2.2.3 Creating an App and Configuring Product Information in AppGallery Connect​

    1.2.2.3.1 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.

    1.2.2.3.2 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.

    2640852000006560358.20210316070114.20286715038069595440767502234397:50520321102934:2800:C75288EDCCF19E9B7C5C0CBC40499FB7A20962DAC1AD235F1E46CECB84284662.png


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

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

    2640852000006560358.20210316070317.20643017033910048742051174534623:50520321102934:2800:19B87E82C73602BAAA6F4A5A8CB2E3D1A3305CC6DCB615D1DC1E2CC094906D32.png


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

    2640852000006560358.20210316070355.62459472449108552017986506906987:50520321102934:2800:C7A6B86EACD80F201356F2AF494ACB99925E7AF3B91073B7A054B2DE70DBC8D6.png


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

    2640852000006560358.20210316070409.15226901253538986042656661069408:50520321102934:2800:614BB2DC09780134004FC338319E109AE2729B348F87A997F9D0A8D550EB1A0D.png


    3. Activate the product.

    2640852000006560358.20210316070717.35414558925225474314996545856689:50520321102934:2800:F48F76409B9341C22318BCCE475AC4746E3C84B9A372A26BC1F4268A099A58BF.png


    1.2.2.4 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.

    2640852000006560358.20210316070727.99146585224184082284423778351942:50520321102934:2800:CE4C339763A04FE91B89FE833CB0FC4A5BF8E3369BEB0D692EC88FCC97DD7374.png


    2640852000006560358.20210316070737.32788974833148185245671735981138:50520321102934:2800:C872840F7AC4752EB8D9752926FBA85BECB8C79FF230D9DFA6D6F04ED1098F0B.png


    1.2.2.5 Configuring Product Information in GameManager​

    1. Drag UDPSampleScene to the top.

    2640852000006560358.20210316070748.53327011380570584245642197121523:50520321102934:2800:7442B8D3414A18548CADA292EA5F6273B8E68C70F7A4C121DE0A8C7E076747AD.png


    2. Enter the configured product ID in GameManger.

    2640852000006560358.20210316070800.86279619134373827287038899523244:50520321102934:2800:E5178C1ABCC4C4118AD90E3210DF39FAB59571F3B48189294341AD586A595D20.png


    3. Push all configurations.

    2640852000006560358.20210316070807.25893411680257335242449379359842:50520321102934:2800:90D8E58C0AD6A80202C5115CE081685AF7F6CE1CA7B26D03823C61ADF7FD8ECE.png


    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.

    2640852000006560358.20210316070821.62298513182960714991001835578606:50520321102934:2800:EF949003C8A0E3A42C9B138536A17918F604D570F449F195923705E377D78544.png


    1.2 Build the project. Save and install the APK.

    2640852000006560358.20210316070833.67809694061838556904151416860883:50520321102934:2800:E9237F5426196D4D58547967BD830BA3175E2C474949280F40B1A57A80CFC67D.png


    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.

    2640852000006560358.20210316070845.94896716331144643701272756288523:50520321102934:2800:29D67FA4A832BDFA29A0091A4CC59816F4C95058812B8B915E66D132508333B4.png
    2640852000006560358.20210316070852.11348962442590572283194333660068:50520321102934:2800:F2BA363721B4E3E8C834506DF0CA7E9DA4A3CCA6505D210651D59E125EAA7BCA.png


    3. Initialize the sandbox test.

    2640852000006560358.20210316070902.57364608465890848290257348890060:50520321102934:2800:BBB696E3470C6A7009B1B65BA3773B5758B03130410CCBA0C48CC5C87F8C9717.png


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

    2640852000006560358.20210316070926.34199463323113192977513972556935:50520321102934:2800:EB93ED0F3CA37EDFC15DA092FAD11F6752B124D4DC8220ACD4C2A73418D0A301.png


    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.

    2640852000006560358.20210316070937.04477487932328160473703028173627:50520321102934:2800:7CE5EFD743F0D872C181BB55DF823D8540F67833E483D3697E626177543BD216.png


    3. Edit the game information and then click Release.

    4. Choose HUAWEI AppGallery.

    2640852000006560358.20210316072439.87814401127164981383571642143770:50520321102934:2800:FEA9E4F7C9CFAD5C77FB6C7F66B7D86CA985A0D8EAEF7491DF3EC5F91EC75C57.png


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

    2640852000006560358.20210316072451.52155093802296203410927689104321:50520321102934:2800:637E2DA500286BE489824CAB36BC5E8DB1565B89B0B8972913DDC2B888AB1900.png


    6. Choose HUAWEI AppGallery and click Publish.

    2640852000006560358.20210316072501.41686802428654167951485638090072:50520321102934:2800:44F94E8BABFA95C55FC1708C4742072FAF73B07F2173A60DA172CE5876D6A264.png


    7. The UDP console repacks your APK.

    2640852000006560358.20210316072510.01088611823153992757944135983923:50520321102934:2800:D3B3A2F8DD1167004345BDBC092A3F37D0A48C7727667CE99ADE03D31BEB7794.png


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

    2640852000006560358.20210316072517.78343886904616222652887886984649:50520321102934:2800:905EB804B2A4D925DFD9E28754C14C54FB9805AD69853153F91CB00882634F44.png





    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