[Huawei Developers] Freemind R:
4. Gradle 4.6 and later

Steps to integrate service

1. We need to register as a developer account in AppGallery Connect

2. Create an app by referring to Creating a Project and Creating an App in the Project

3. Set the data storage location based on current location

4. Enabling Required Services: IAP Kit you will be asked to apply for Merchant service this process will take 2 days for review.

5. Enable settings In-app Purchases choose My Projects > Earn > In-App Purchases and click Settings.

6. Generating a Signing Certificate Fingerprint.

7. Configuring the Signing Certificate Fingerprint.

8. Get your agconnect-services.json file to the app root directory.

Development Process

Create Application in Android Studio.

1. Create Flutter project.

2. App level gradle dependencies. Choose inside project Android > app > build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'

Root level gradle dependencies

maven {url 'https://developer.huawei.com/repo/'}
classpath 'com.huawei.agconnect:agcp:1.4.1.300'3.

3. Add HMS IAP kit plugin download using below URL.

https://developer.huawei.com/consum...y-V1/flutter-sdk-download-0000001050727030-V1

4. On your Flutter project directory find and open your pubspec.yaml file and add library to dependencies to download the package from pub.dev. Or if you downloaded the package from the HUAWEI Developer website, specify the library path on your local device. For both ways, after running pub get command, the plugin will be ready to use.

name: mlsample
description: A new Flutter application.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1

environment:
sdk: ">=2.7.0 <3.0.0"

dependencies:
flutter:
sdk: flutter
huawei_iap:
path: ../huawei_iap/
dev_dependencies:
flutter_test:
sdk: flutter

flutter:
uses-material-design: true

5. We can check the plugins under External Libraries directory.

6. Open main.dart file to create UI and business logics.

Configuring Product Info

To Add a product go to MyApps > DemoApp > Operate

Click Add Product Configure product information and click Save.

After the configuration is complete, Activate the product in the list to make it valid and purchasable.

Environment Check

Before calling any service you need to check user is login or not using IapClient.isEnvReady

environmentCheck() async {
isEnvReadyStatus = null;
try {
IsEnvReadyResult response = await IapClient.isEnvReady();
setState(() {
isEnvReadyStatus = response.status.statusMessage;
});
} on PlatformException catch (e) {
if (e.code == HmsIapResults.LOG_IN_ERROR.resultCode) {
_showToast(context, HmsIapResults.LOG_IN_ERROR.resultMessage);
} else {
_showToast(context, e.toString());
}
}
}

Fetch Product Info

We can fetch the product information of products using obtainProductInfo()

Note: The SkuIds is the same as that configured in AppGallery Connect.

loadConsumables() async {
try {
ProductInfoReq req = new ProductInfoReq();
req.priceType = IapClient.IN_APP_CONSUMABLE;
req.skuIds = ["SUB_30", "PR_6066"];
ProductInfoResult res = await IapClient.obtainProductInfo(req);
setState(() {
consumable = [];
for (int i = 0; i < res.productInfoList.length; i++) {
consumable.add(res.productInfoList[i]);
}
});
} on PlatformException catch (e) {
if (e.code == HmsIapResults.ORDER_HWID_NOT_LOGIN.resultCode) {
log(HmsIapResults.ORDER_HWID_NOT_LOGIN.resultMessage);
} else {
log(e.toString());
}
}
}

Purchase Result Info

When user click into buy button, first create purchase intent request and specify the type of the product and product ID in the request parameter.

If you want to test purchase functionality you need to create testing account. Using Sandbox testing we can do payment end-to-end functionality.

Once payment successfully done we get PurchaseResultInfo object, so this object has the details of the purchase.

subscribeProduct(String productID) async {
try {

PurchaseResultInfo result = await IapClient.createPurchaseIntent(
PurchaseIntentReq(
priceType: IapClient.IN_APP_CONSUMABLE, productId: productID));
if (result.returnCode == HmsIapResults.ORDER_STATE_SUCCESS.resultCode) {
log("Successfully plan subscribed");
} else {
log(result.errMsg);
}
} on PlatformException catch (e) {
if (e.code == HmsIapResults.ORDER_HWID_NOT_LOGIN.resultCode) {
log(HmsIapResults.ORDER_HWID_NOT_LOGIN.resultMessage);
} else {
log(e.toString());
}
}
}<strong><em><strong> </strong></em></strong>

For more, you can check https://forums.developer.huawei.com/forumPortal/en/topic/0204454642374170012