[Huawei Developers] Freemind R:
More information like this, you can visit HUAWEI Developer Forum​

This article is based on Huawei’s In-App Purchases. We can create a new sample application for online grocery store to buy fruits and vegetables with online payment using In-App Purchases.

Huawei's In-App Purchases (IAP) service integrates multiple payment methods for global payment and allows you to easily offer in-app purchases. Users can purchase a variety of products or services, including common virtual products and subscriptions, directly within your app.

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

The latest version of IAP supports the following functions:

Release: You can release an app or a game with one package and manage the prices and languages of in-app purchases. The locations supported by the PMS on the price configuration page shall prevail.

Currencies and languages: You can set one default currency and one default language for each location. Setting multiple languages for one location is not allowed.

Price: Huawei provides an in-app product price reference for each location based on the converted price (tax included) set the exchange rate. You can change the price.

Exchange rate: fixed exchange rate by which Huawei will update the price. Updating the exchange rate by Huawei will not affect your price if you do not change the price.

Intended audience: global developers. To release an in-app product (or a game) to multiple locations, you need to manage the price and language of the products locally.

These are the following 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) A computer (desktop or laptop)

2) A Huawei phone used for running the app with HUAWEI IAP integrated

3) A data cable used for connecting the computer to the Huawei phone

4) Android Studio 3.0 or later

5) Java SDK 1.7 or later

6) HMS Core (APK) 3.0.0.300 or later

7) HMS Core SDK 4.0.0.300 or later

8) Must have Huawei Developer Account

9) Must have Huawei Merchant Account

Things Need To Be Done

1) Create an app in AppGallery Connect.

2) Create an Android Studio project.

3) Start development with kit integration inside the application.

4) Launch the application.

Create a project on AppGalleryConnect portal:

1. Click My projects.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131441.64699459440370025931195238995626:50510902021435:2800:30A3840C398E618EB269F466643C170A07BC75777BD2D53415A9EA436371C3DB.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131441.64699459440370025931195238995626:50510902021435:2800:30A3840C398E618EB269F466643C170A07BC75777BD2D53415A9EA436371C3DB.png[/IMG]

2. Click Add project and provide your project details.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131522.99077533444337484787115962867666:50510902021435:2800:8FBD64E822BADDF03C6A5BDB274C56FC23FDDA07B99082B8B89877B52DE9FE57.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131522.99077533444337484787115962867666:50510902021435:2800:8FBD64E822BADDF03C6A5BDB274C56FC23FDDA07B99082B8B89877B52DE9FE57.png[/IMG]

3. Provide your project name and click OK.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131620.67847360135596759170649467564701:50510902021435:2800:16680ECD16A6743599F4F9C04AB334A8AB88348AC2A829C03F81013A9F08CB61.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131620.67847360135596759170649467564701:50510902021435:2800:16680ECD16A6743599F4F9C04AB334A8AB88348AC2A829C03F81013A9F08CB61.png[/IMG]

4. Navigate to General Information, and then provide Data Storage location.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131645.15468032062647360153189807167869:50510902021435:2800:AF813B4E002A908A29F51DF17509A16AC95157E18B293B93550B5FFBD545EEA9.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131645.15468032062647360153189807167869:50510902021435:2800:AF813B4E002A908A29F51DF17509A16AC95157E18B293B93550B5FFBD545EEA9.png[/IMG]

5. Navigate to Manage APIs and enable APIs which require by application

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131732.81034071212756788915688892345307:50510902021435:2800:BC6F9FDE908F7970D52725BA952FC9D9B959EFBBD96554F2D8BFC014F9EF6A08.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131732.81034071212756788915688892345307:50510902021435:2800:BC6F9FDE908F7970D52725BA952FC9D9B959EFBBD96554F2D8BFC014F9EF6A08.png[/IMG]

6. Navigate to General information and download the agconnect-services.json file

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131757.69571531651884077892079084449965:50510902021435:2800:E01697963DD9201C84CBD0EC92D9503FBFB7C4091D781856E9470E09D47D205F.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131757.69571531651884077892079084449965:50510902021435:2800:E01697963DD9201C84CBD0EC92D9503FBFB7C4091D781856E9470E09D47D205F.png[/IMG]

7. Navigate to In-App Purchases and copy Public Key.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131825.20601974637224226533811338082483:50510902021435:2800:81D4E178F26D078B4559C7EEF81441986E885C4A80F889BE6476936D9CEE0107.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131825.20601974637224226533811338082483:50510902021435:2800:81D4E178F26D078B4559C7EEF81441986E885C4A80F889BE6476936D9CEE0107.png[/IMG]

8. Navigate to My apps, click Operate, and then enter details in Add Product.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131905.06892353530894605000509246519758:50510902021435:2800:6A0E5A440F31294BB4CD8B1A4443B3FE0EA745D187AF7618B6B0E0162012FC36.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131905.06892353530894605000509246519758:50510902021435:2800:6A0E5A440F31294BB4CD8B1A4443B3FE0EA745D187AF7618B6B0E0162012FC36.png[/IMG]

9. Click View and Edit in above screenshot, enter Product price details, and then click Save.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131943.45774423650287339472646130916123:50510902022842:2800:3A5BA17E07D62D05E8B8DA480F8F9ED3A7CB8E153056947AF5526B008735FBDD.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821131943.45774423650287339472646130916123:50510902022842:2800:3A5BA17E07D62D05E8B8DA480F8F9ED3A7CB8E153056947AF5526B008735FBDD.png[/IMG]

10. Click Activate for product activation.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821132016.63251785906151582493773552460746:50510902021435:2800:67337B34089C6A221E6C73BA6B415E84677F85636358865D4F38F20AE9322054.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821132016.63251785906151582493773552460746:50510902021435:2800:67337B34089C6A221E6C73BA6B415E84677F85636358865D4F38F20AE9322054.png[/IMG]

Create a project in Android Studio:

1. Open your android studio and Create New Project.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821132147.01036949334956970621699371670777:50510902021435:2800:05C2FE3FF94FD43C81BEFC93AF01AF1AAE2FD9603A3935B2D561743526CA1C03.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821132147.01036949334956970621699371670777:50510902021435:2800:05C2FE3FF94FD43C81BEFC93AF01AF1AAE2FD9603A3935B2D561743526CA1C03.png[/IMG]

2. Enter the maven url inside the repositories of buildscript and allprojects (project build.gradle file)

Add maven url and add following AppGalleryConnect class path.

buildscript {

repositories {
maven {url 'http://developer.huawei.com/repo/'}
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.huawei.agconnect:agcp:1.0.0.300'

}
}

allprojects {
repositories {
maven {url 'http://developer.huawei.com/repo/'}
google()
jcenter()

}
}

3. Add the following dependencies in app module based gradle file

implementation 'com.huawei.hms:iap:4.0.0.300'

4. Generate SHA-256 fingerprint in android studio

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821132434.00135740059001009188533903589288:50510902021435:2800:FD2D816C0D4C456C21C9545CB3A3459337DF925C7A85EF816BCD2E0D69FD3AED.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821132434.00135740059001009188533903589288:50510902021435:2800:FD2D816C0D4C456C21C9545CB3A3459337DF925C7A85EF816BCD2E0D69FD3AED.png[/IMG]

5. Add json file inside your application

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821132500.92595005893685739576242369174956:50510902021435:2800:4C528E3C5DA5A8C5110AC83B096BCF7F1FCF07A66B1CD0CACB37459DC9247DEF.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821132500.92595005893685739576242369174956:50510902021435:2800:4C528E3C5DA5A8C5110AC83B096BCF7F1FCF07A66B1CD0CACB37459DC9247DEF.png[/IMG]

Start development with kit integration inside the application

We have created the following package inside the project.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821132611.92625047107240905432082119039618:50510902021435:2800:CC95F6E11B69E30DBDB2E276702A513481CCAFD0D48DED1710DD6158BD92F478.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/541/2640091000001768541.20200821132611.92625047107240905432082119039618:50510902021435:2800:CC95F6E11B69E30DBDB2E276702A513481CCAFD0D48DED1710DD6158BD92F478.png[/IMG]

We have created 3 activities Home, Store, and ViewPurchases activity inside activity package.

Home Activity: In this activity, we have created a simple User interface for our online store app.

public class HomeActivity extends BaseActivity {

private ActivityHomeBinding homeBinding;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
homeBinding = DataBindingUtil.setContentView(this, R.layout.activity_home);
init();
}

private void init() {
setToolbar(homeBinding.tbWidget.findViewById(R.id.toolbar),
false, "My Online Store", homeBinding.tbWidget.findViewById(R.id.tv_toolbar_title));
homeBinding.btnBuyFromStore.setOnClickListener(v->StoreActivity.start(this));
homeBinding.btnViewYourPurchases.setOnClickListener(v->ViewPurchasesActivity.start(this));
}

}

Store Activity: In this activity we have simply displayed the all products which is available.

public class HomeActivity extends BaseActivity {

private ActivityHomeBinding homeBinding;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
homeBinding = DataBindingUtil.setContentView(this, R.layout.activity_home);
init();
}

private void init() {
setToolbar(homeBinding.tbWidget.findViewById(R.id.toolbar),
false, "My Online Store", homeBinding.tbWidget.findViewById(R.id.tv_toolbar_title));
homeBinding.btnBuyFromStore.setOnClickListener(v->StoreActivity.start(this));
homeBinding.btnViewYourPurchases.setOnClickListener(v->ViewPurchasesActivity.start(this));
}

}

This is not the end. For full content, you can visit https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201333994591170041&fid=0101188387844930001