huawei_iap 5.0.2+300
huawei_iap: ^5.0.2+300

Flutter Android

HUAWEI IAP Kit plugin for Flutter. Huawei's In-App Purchases (IAP) service allows you to offer in-app purchases and facilitates in-app payment.

Huawei IAP Kit Flutter Plugin #


Contents #


1. Introduction #

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 one-time virtual products and subscriptions, directly within your app.

Huawei IAP provides the following core capabilities you need to quickly build apps with which your users can buy, consume and subscribe services you provide:

  • isEnvReady: Returns a response which indicates user's environment status.
  • isSandboxActivated: Returns a response which indicates user's account capabilities of sandbox testing.
  • obtainProductInfo: Returns a list of product information.
  • startIapActivity: Starts an activity to manage and edit subscriptions.
  • createPurchaseIntent: Starts an activity to buy the desired product or subscribe a product.
  • consumeOwnedPurchase: Consumes the desired purchased product.
  • obtainOwnedPurchases: Returns a list of products that purchased by user.
  • obtainOwnedPurchaseRecord: Returns a list of products that purchased and consumed by user.
  • enableLogger: This method enables the HMSLogger capability which is used for sending usage analytics of IAP SDK's methods to improve the service quality.
  • disableLogger: This method disables the HMSLogger capability which is used for sending usage analytics of IAP SDK's methods to improve the service quality.

This plugin enables communication between HUAWEI IAP Kit SDK and Flutter platform. It exposes all functionality provided by HUAWEI IAP Kit SDK.


2. Installation Guide #

  • Before you get started, you must register as a HUAWEI developer and complete identity verification on the HUAWEI Developer website. For details, please refer to Register a HUAWEI ID.

  • Create an app in your project is required in AppGallery Connect in order to communicate with Huawei services. To create an app, perform the following steps:

Step 1. Sign in to AppGallery Connect and select My projects.

Step 2. Click your project from the project list.

Step 3. Go to Project Setting > General information, and click Add app. If an app exists in the project, and you need to add a new one, expand the app selection area on the top of the page and click Add app.

Step 4. On the Add app page, enter app information, and click OK.

  • A signing certificate fingerprint is used to verify the authenticity of an app when it attempts to access an HMS Core service through the HMS Core SDK. Before using HMS Core (APK), you must locally generate a signing certificate fingerprint and configure it in AppGallery Connect. Ensure that the JDK has been installed on your computer.

  • To use HUAWEI IAP, you need to enable the IAP service first and also set IAP parameters. For details, please refer to Enabling Services.

Configuring the Signing Certificate Fingerprint #

Step 1: Go to Project Setting > General information. In the App information field, click the icon next to SHA-256 certificate fingerprint, and enter the obtained SHA256 certificate fingerprint.

Step 2: After completing the configuration, click check mark.

Integrating Flutter IAP Plugin #

Step 1: Sign in to AppGallery Connect and select My projects.

Step 2: Find your app project, and click the desired app name.

Step 3: Go to Project Setting > General information. In the App information section, click agconnect-service.json to download the configuration file.

Step 4: Create a Flutter project if you do not have one.

Step 5: Copy the agconnect-service.json file to the android/app directory of your Flutter project.

Step 6: Copy the signature file that generated in Generating a Signing Certificate section, to the android/app directory of your Flutter project.

Step 7: Check whether the agconnect-services.json file and signature file are successfully added to the android/app directory of the Flutter project.

Step 8: Open the build.gradle file in the android directory of your Flutter project.

  • Go to buildscript then configure the Maven repository address and agconnect plugin for the HMS SDK.

        buildscript {
            repositories {
                google()
                jcenter()
                maven { url 'https://developer.huawei.com/repo/' }
            }
    
            dependencies {
                /*
                 * <Other dependencies>
                 */
                classpath 'com.huawei.agconnect:agcp:1.4.1.300'
            }
        }
    
  • Go to allprojects then configure the Maven repository address for the HMS SDK.

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

Step 9: Open the build.gradle file in the android/app directory.

  • Add apply plugin: 'com.huawei.agconnect' line after the apply entries.

        apply plugin: 'com.android.application'
        apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
        apply plugin: 'com.huawei.agconnect'
    
  • Set your package name in defaultConfig > applicationId and set minSdkVersion to 19 or higher.

  • Package name must match with the package_name entry in agconnect-services.json file.

        defaultConfig {
                applicationId "<package_name>"
                minSdkVersion 19
                /*
                 * <Other configurations>
                 */
            }
    
  • Copy the signature file that generated in Generating a Signing Certificate to android/app directory.

  • Configure the signature in android according to the signature file information and configure Obfuscation Scripts.

        android {
            /*
             * <Other configurations>
             */
    
            signingConfigs {
                config {
                    storeFile file('<keystore_file>.jks')
                    storePassword '<keystore_password>'
                    keyAlias '<key_alias>'
                    keyPassword '<key_password>'
                }
            }
    
            buildTypes {
                debug {
                    signingConfig signingConfigs.config
                }
                release {
                    minifyEnabled true
                    shrinkResources true
                    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                    signingConfig signingConfigs.config
                }
            }
        }
    
  • For Obfuscation Scripts, please refer to Configuring Obfuscation Scripts.

Step 10: On your Flutter project directory find and open your pubspec.yaml file and add library to dependencies.

  • To download the package from pub.dev.

    dependencies:
      huawei_iap: { library version }
    

    or

    If you downloaded the package from the HUAWEI Developer website, specify the library path on your local device.

    dependencies:
      huawei_iap:
        # Replace {library path} with actual library path of Huawei IAP Plugin for Flutter.
        path: { library path }
    
    • Replace {library path} with the actual library path of Flutter IAP Plugin. The following are examples:
      • Relative path example: path: ../huawei_iap
      • Absolute path example: path: D:\Projects\Libraries\huawei_iap

Step 11: Run following command to update package info.

  [project_path]> flutter pub get

Step 12: Run following command to start the app.

  [project_path]> flutter run

3. API Reference #

IapClient #

Entry class of the Huawei IAP service.

Public Constants

ConstantTypeValueDescription
IN_APP_CONSUMABLEint0Consumable.
IN_APP_NONCONSUMABLEint1Non-consumable.
IN_APP_SUBSCRIPTIONint2Subscription.

Public Method Summary

MethodReturn TypeDescription
isEnvReady()Future<IsEnvReadyResult>Returns a response which indicates user's environment status.
isSandboxActivated()Future<IsSandboxActivatedResult>Returns a response which indicates user's account capabilities of sandbox testing.
obtainProductInfo(ProductInfoReq request)Future<ProductInfoResult>Returns a list of product information.
startIapActivity(StartIapActivityReq request)Future<void>Starts an activity to manage and edit subscriptions.
createPurchaseIntent(PurchaseIntentRequest request)Future<PurchaseResultInfo>Starts an activity to buy the desired product or subscribe a product.
consumeOwnedPurchase(ConsumeOwnedPurchaseReq request)Future<ConsumeOwnedPurchaseResult>Consumes the desired purchased product.
obtainOwnedPurchases(OwnedPurchasesReq request)Future<OwnedPurchasesResult>Returns a list of products that purchased by user.
obtainOwnedPurchaseRecord(OwnedPurchasesReq request)Future<OwnedPurchasesResult>Returns a list of products that purchased and consumed by user.
disableLogger()Future<void>Disables HMS Logger.
enableLogger()Future<void>Enables HMS Logger.

Public Methods

Future<IsEnvReadyResult> isEnvReady() async

Checks whether the currently signed-in Huawei ID is located in a country or region where Huawei IAP is available.

Return Type
Return TypeDescription
Future<IsEnvReadyResult>Represents a response object used to gather information about user environment.
Call Example
//Call isEnvReady API.
IsEnvReadyResult result = await IapClient.isEnvReady();

//Print the returnCode property.
log(result.returnCode);
Future<IsSandboxActivatedResult> isSandboxActivated() async

Checks whether the signed-in Huawei ID and the app APK version meet the requirements of the sandbox testing.

Return Type
Return TypeDescription
Future<IsSandboxActivatedResult>Represents a response object to gather information about user's sandbox permissions.
Call Example
//Call isSandboxActivated API.
IsSandboxActivatedResult result = await IapClient.isSandboxActivated();

//Print the isSandboxUser property.
log(result.isSandboxUser);
Future<ProductInfoResult> obtainProductInfo(ProductInfoReq request) async

Obtains product details configured in AppGallery Connect. If you use Huawei's PMS to price products, you can use this method to obtain product details from the PMS to ensure that the product information in your app is the same as that displayed on the checkout page of Huawei IAP.

Parameters
NameDescription
requestProductInfoReq object.
Return Type
Return TypeDescription
Future<ProductInfoResult>Represents a response object used to obtain product information.
Call Example
//Constructing request.
ProductInfoReq request = ProductInfoReq();
request.priceType = IapClient.IN_APP_CONSUMABLE; //You may also use 0 for consumables.
request.skuIds = ["consumable_product_1", "consumable_product_2"];
    
//Call the obtainProductInfo API.
ProductInfoResult result = await IapClient.obtainProductInfo(request);

//Print product name of the first product in the productInfoList.
log(result.productInfoList[0].productName)
Future<void> startIapActivity(StartIapActivityReq request) async

Brings up in-app payment pages, including:

  • Subscription editing page
  • Subscription management page
Parameters
NameDescription
requestStartIapActivityReq object.
Return Type
Return TypeDescription
Future<void>Future result of an execution that returns no value.
Call Example
//Constructing request.
StartIapActivityReq request = StartIapActivityReq();
request.type = StartIapActivityReq.TYPE_SUBSCRIBE_MANAGER_ACTIVITY;

//Call the startIapActivity API.
await IapClient.startIapActivity(request);
Future<PurchaseResultInfo> createPurchaseIntent(PurchaseIntentReq request) async

Creates orders for PMS products, including consumables, non-consumables, and subscriptions.

After creating a product in AppGallery Connect, you can call this method to open the HUAWEI IAP checkout page and display the product, price, and payment method. Huawei can adjust product prices by foreign exchange rate changes. To ensure price consistency, your app needs to call the obtainProductInfo method to obtain product details from Huawei instead of your own server.

Parameters
NameDescription
requestPurchaseIntentReq object.
Return Type
Return TypeDescription
Future<PurchaseResultInfo>Represents a response object of purchase intent.
Call Example
//Constructing request.
PurchaseIntentReq request = PurchaseIntentReq();
request.priceType = IapClient.IN_APP_CONSUMABLE; //You may also use 0 for consumables.
request.productId = "consumable_product_1";
request.developerPayload = "Test";

//Call the createPurchaseIntent API.
PurchaseResultInfo result = await IapClient.createPurchaseIntent(request);

//Print inAppDataSignature property. 
log(result.inAppDataSignature) 
Future<OwnedPurchasesResult> obtainOwnedPurchases(OwnedPurchasesReq request) async
Parameters
NameDescription
requestOwnedPurchasesReq object.
Return Type
Return TypeDescription
Future<OwnedPurchasesResult>Represents a response object of obtain owned purchases or owned purchase record APIs.
Call Example
//Constructing request.
OwnedPurchasesReq request = OwnedPurchasesReq();
request.priceType = IapClient.IN_APP_CONSUMABLE; //You may also use 0 for consumables.

//Call the obtainOwnedPurchases API.
OwnedPurchasesResult result = await IapClient.obtainOwnedPurchases(request);

//Print productId of the first product in inAppPurchaseDataList.
log(result.inAppPurchaseDataList[0].productId);
Future<ConsumeOwnedPurchaseResult> consumeOwnedPurchase(ConsumeOwnedPurchaseReq request) async

Consumes a consumable after the consumable is delivered to a user who has completed payment.

Parameters
NameDescription
requestConsumeOwnedPurchaseReq object.
Return Type
Return TypeDescription
Future<ConsumeOwnedPurchaseResult>Represents details about consumed product.
Call Example
//Constructing request.
ConsumeOwnedPurchaseReq request = ConsumeOwnedPurchaseReq();
request.purchaseToken = "PURCHASE_TOKEN"

//Call the consumeOwnedPurchase API.
ConsumeOwnedPurchaseResult result = await IapClient.consumeOwnedPurcases(request);

//Print dataSignature property.
log(result.dataSignature);
Future<OwnedPurchasesResult> obtainOwnedPurchaseRecord(OwnedPurchasesReq request) async

Obtains the historical consumption information about a consumable or all subscription receipts of a subscription.

  • For consumables, this method returns information about products that have been delivered or consumed in the product list.

  • For non-consumables, this method does not return product information.

  • For subscriptions, this method returns all subscription receipts of the current user in this app

Parameters
NameDescription
requestOwnedPurchasesReq object.
Return Type
Return TypeDescription
Future<OwnedPurchasesResult>Represents a response object of obtain owned purchases or owned purchase record APIs.
Call Example
//Constructing request.
OwnedPurchasesReq request = OwnedPurchasesReq();
request.priceType = IapClient.IN_APP_CONSUMABLE; //You may also use 0 for consumables.

//Call the obtainOwnedPurchaseRecord API.
OwnedPurchasesResult result = await IapClient.obtainOwnedPurchaseRecord(request);

//Print product ids from purchase history
for(int i = 0; i < result.inAppPurchaseDataList.length; i++){
    log(result.inAppPurchaseDataList[i].productId);}
Future<void> disableLogger() async

This method disables the HMSLogger capability which is used for sending usage analytics of IAP SDK's methods to improve the service quality.

Return Type
Return TypeDescription
Future<void>Future result of an execution that returns no value.
Call Example
//Call disableLogger API.
await IapClient.disableLogger();
Future<void> enableLogger() async

This method enables the HMSLogger capability which is used for sending usage analytics of IAP SDK's methods to improve the service quality.

Return Type
Return TypeDescription
Future<void>Future result of an execution that returns no value.
Call Example
//Call enableLogger API.
await IapClient.enableLogger();

Data Types #

Data Types Summary

ClassDescription
ConsumeOwnedPurchaseReqRepresents a request object used to consume a product.
ConsumeOwnedPurchaseResultRepresents a response object used to consume a product.
ConsumePurchaseDataRepresents details about consumed product.
InAppPurchaseDataRepresents details about purchased product.
IsEnvReadyResultRepresents a response object used to gather information about user environment.
IsSandboxActivatedResultRepresents a response object to gather information about user's sandbox permissions.
OwnedPurchasesReqRepresents a request object used to obtain owned purchases or owned purchase record.
OwnedPurchasesResultRepresents a response object used to obtain owned purchases or owned purchase record.
ProductInfoRepresents details of product.
ProductInfoReqRepresents a request object used to obtain product information.
ProductInfoResultRepresents a response object used to obtain product information.
PurchaseIntentReqRepresents a request object used to create a purchase intent.
PurchaseResultInfoRepresents a response object used to create a purchase intent.
StartIapActivityReqRepresents a request object used to start activity for editing or managing subscriptions.
StatusRepresents status of the API call.
HmsIapResultRepresents an error class for HmsIapResults.

ConsumeOwnedPurchaseReq

Request information of the consumeOwnedPurchase API.

Public Properties
NameTypeDescription
purchaseTokenStringPurchase token, which is generated by the Huawei IAP server during payment and returned to the app through InAppPurchaseData. The app passes this parameter for the Huawei IAP server to update the order status and then deliver the product.
developerChallengeStringCustom challenge, which uniquely identifies a consumption request. After the consumption is successful, the challenge is recorded in the purchase information and returned. Note: The value length of this parameter is within (0,64).
Public Constructor Summary
ConstructorDescription
ConsumeOwnedPurchaseReq({String purchaseToken, String developerChallenge})Default constructor.
ConsumeOwnedPurchaseReq.fromJson(String source)Creates a ConsumeOwnedPurchaseReq object from a JSON string.
Public Constructors
ConsumeOwnedPurchaseReq({String purchaseToken, String developerChallenge})

Constructor for ConsumeOwnedPurchaseReq object.

ParameterTypeDescription
purchaseTokenStringPurchase token, which is generated by the Huawei IAP server during payment and returned to the app through InAppPurchaseData. The app passes this parameter for the Huawei IAP server to update the order status and then deliver the product.
developerChallengeStringCustom challenge, which uniquely identifies a consumption request. After the consumption is successful, the challenge is recorded in the purchase information and returned. Note: The value length of this parameter is within (0,64).
ConsumeOwnedPurchaseReq.fromJson(String source)

Creates a ConsumeOwnedPurchaseReq object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

ConsumeOwnedPurchaseResult

Information returned when the consumeOwnedPurchase API is successfully called.

Public Properties
NameTypeDescription
consumePurchaseDataConsumePurchaseDataConsumePurchaseData object that contains consumption result data.
dataSignatureStringSignature string generated after consumption data is signed using a private payment key. The signature algorithm is SHA256withRSA
errMsgStringResult code description.
returnCodeStringResult code.
statusStatusStatus object that contains the task processing result.
rawValueStringUnparsed JSON String of response. NOTE: IAP SDK does not return a JSON response. This field is the response class converted to JSON.
Public Constructor Summary
ConstructorDescription
ConsumeOwnedPurchaseResult({ConsumePurchaseData consumePurchaseData, String dataSignature, String errMsg, String returnCode, Status status})Default Constructor
ConsumeOwnedPurchaseResult.fromJson(String source)Creates a ConsumeOwnedPurchaseResult object from a JSON string.
Public Constructors
ConsumeOwnedPurchaseResult({ConsumePurchaseData consumePurchaseData, String dataSignature, String errMsg, String returnCode, Status status})

Constructor for ConsumeOwnedPurchaseResult object.

ParameterTypeDescription
consumePurchaseDataConsumePurchaseDataConsumePurchaseData object that contains consumption result data.
dataSignatureStringSignature string generated after consumption data is signed using a private payment key. The signature algorithm is SHA256withRSA
errMsgStringResult code description.
returnCodeStringResult code.
statusStatusStatus object that contains the task processing result.
ConsumeOwnedPurchaseResult.fromJson(String source)

Creates a ConsumeOwnedPurchaseResult object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

ConsumePurchaseData

Object that contains consumption result data.

Public Properties
Click to expand/collapse Properties table
NameTypeDescription
applicationIdintID of an app that initiates a purchase.
autoRenewingboolIndicates whether the subscription is automatically renewed. Currently, the value is always false.
confirmedintConfirmation.
orderIdStringOrder ID on the Huawei IAP server, which uniquely identifies a transaction and is generated by the Huawei IAP server during payment.
kindintProduct type.
packageNameStringSoftware package name of the app that initiates a purchase.
payOrderIdStringMerchant ID, which uniquely identifies a transaction and is generated by the Huawei IAP server during payment.
payTypeStringPayment method. 0: HUAWEI Points 3: Credit card 4: Alipay 6: Carrier billing 13: PayPal 16: Debit card 17: WeChat Pay 19: Gift card 20: Balance 21: HUAWEI Point card 24: WorldPay 31: HUAWEI Pay 32: Ant Credit Pay 200: M-Pesa
productIdStringProduct ID.
productNameStringProduct name.
purchaseTimeintPurchase timestamp, which is the number of milliseconds from 00:00:00 on January 1, 1970 to the purchase time.
purchaseTimeMillisintPurchase time.
purchaseTypeintPurchase type. 0: In the sandbox 1: In the promotion period (currently unsupported). This parameter is not returned during formal purchase.
purchaseStateintOrder status. -1: initialized and invisible 0: Purchased 1: Canceled 2: Refunded
developerPayloadStringReserved information on the merchant side, which is passed by the app during payment.
purchaseTokenStringPurchase token, which uniquely identifies the mapping between a product and a user. It is generated by the Huawei IAP server when the payment is complete.
developerChallengeStringChallenge defined when the app initiates a consumption request, which uniquely identifies a consumption request.
consumptionStateintConsumption status. 0: Not consumed 1: Consumed
acknowledgedintReceiving status. 0: Not received 1: Received. This parameter is valid only for receiving APIs. The value is always 0. You can ignore this parameter.
currencyStringCurrency. The value must be a currency defined in the ISO 4217 standard. Example: USD, CNY, and TRY
priceintValue after the actual price of a product is multiplied by 100. The actual price is accurate to two decimal places. For example, if the value of this parameter is 501, the actual product price is 5.01.
countryStringCountry or region code of a user service area. The value must comply with the ISO 3166 standard. Example: US, CN, and TR
responseCodeStringResponse code. 0: The execution is successful.
responseMessageStringResponse information.
Public Constructor Summary
ConstructorDescription
ConsumePurchaseData({int applicationId, bool autoRenewing, String orderId, String packageName, String productId, int purchaseTime, int purchaseState, String developerPayload, String purchaseToken, String developerChallenge, int consumptionState, int acknowledged, String currency, int price, String country, String responseCode, String responseMessage, int kind, String productName, int purchaseTimeMillis, int confirmed, int purchaseType, String payOrderId, String payType})Default constructor.
ConsumePurchaseData.fromJson(String source)Creates a ConsumePurchaseData object from a JSON string.
Public Constructors
ConsumePurchaseData({int applicationId, bool autoRenewing, String orderId, String packageName, String productId, int purchaseTime, int purchaseState, String developerPayload, String purchaseToken, String developerChallenge, int consumptionState, int acknowledged, String currency, int price, String country, String responseCode, String responseMessage, int kind, String productName, int purchaseTimeMillis, int confirmed, int purchaseType, String payOrderId, String payType})

Constructor for ConsumePurchaseData object.

Click to expand/collapse Parameter table
ParameterTypeDescription
applicationIdintID of an app that initiates a purchase.
autoRenewingboolIndicates whether the subscription is automatically renewed. Currently, the value is always false.
confirmedintConfirmation.
orderIdStringOrder ID on the Huawei IAP server, which uniquely identifies a transaction and is generated by the Huawei IAP server during payment.
kindintProduct type.
packageNameStringSoftware package name of the app that initiates a purchase.
payOrderIdStringMerchant ID, which uniquely identifies a transaction and is generated by the Huawei IAP server during payment.
payTypeStringPayment method. 0: HUAWEI Points 3: Credit card 4: Alipay 6: Carrier billing 13: PayPal 16: Debit card 17: WeChat Pay 19: Gift card 20: Balance 21: HUAWEI Point card 24: WorldPay 31: HUAWEI Pay 32: Ant Credit Pay 200: M-Pesa
productIdStringProduct ID.
productNameStringProduct name.
purchaseTimeintPurchase timestamp, which is the number of milliseconds from 00:00:00 on January 1, 1970 to the purchase time.
purchaseTimeMillisintPurchase time.
purchaseTypeintPurchase type. 0: In the sandbox 1: In the promotion period (currently unsupported). This parameter is not returned during formal purchase.
purchaseStateintOrder status. -1: initialized and invisible 0: Purchased 1: Canceled 2: Refunded
developerPayloadStringReserved information on the merchant side, which is passed by the app during payment.
purchaseTokenStringPurchase token, which uniquely identifies the mapping between a product and a user. It is generated by the Huawei IAP server when the payment is complete.
developerChallengeStringChallenge defined when the app initiates a consumption request, which uniquely identifies a consumption request.
consumptionStateintConsumption status. 0: Not consumed 1: Consumed
acknowledgedintReceiving status. 0: Not received 1: Received. This parameter is valid only for receiving APIs. The value is always 0. You can ignore this parameter.
currencyStringCurrency. The value must be a currency defined in the ISO 4217 standard. Example: USD, CNY, and TRY
priceintValue after the actual price of a product is multiplied by 100. The actual price is accurate to two decimal places. For example, if the value of this parameter is 501, the actual product price is 5.01.
countryStringCountry or region code of a user service area. The value must comply with the ISO 3166 standard. Example: US, CN, and TR
responseCodeStringResponse code. 0: The execution is successful.
responseMessageStringResponse information.
ConsumePurchaseData.fromJson(String source)

Creates a ConsumePurchaseData object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

InAppPurchaseData

Purchase information about products including consumables, non-consumables, and subscriptions.

Public Properties
Click to expand/collapse Properties table
NameTypeDescription
applicationIdintID of an app that initiates a purchase.
autoRenewingboolIndicates whether the subscription is automatically renewed. Currently, the value is always false.
orderIdStringOrder ID on the Huawei IAP server, which uniquely identifies a transaction and is generated by the Huawei IAP server during payment.
packageNameStringSoftware package name of the app that initiates a purchase.
productIdStringProduct ID.
productNameStringProduct name.
purchaseTimeintPurchase timestamp, which is the number of milliseconds from 00:00:00 on January 1, 1970 to the purchase time.
purchaseStateintOrder status. -1: Initialized and invisible 0: Purchased 1: Canceled 2: Refunded
developerPayloadStringReserved information on the merchant side, which is passed by the app during payment.
purchaseTokenStringPurchase token, which uniquely identifies the mapping between a product and a user. It is generated by the Huawei IAP server when the payment is complete.
purchaseTypeintPurchase type.0: in the sandbox1: in the promotion period (currently unsupported)This parameter is not returned during formal purchase.
currencyStringCurrency. The value must be a currency defined in the ISO 4217 standard. Example: USD, CNY, and TRY
priceintValue after the actual price of a product is multiplied by 100. The actual price is accurate to two decimal places. For example, if the value of this parameter is 501, the actual product price is 5.01.
countryStringCountry or region code of a user service area. The value must comply with the ISO 3166 standard. Example: US, CN, and TR
lastOrderIdStringOrder ID generated by the Huawei IAP server during fee deduction on the previous renewal.
productGroupStringID of the subscription group to which a subscription belongs.
oriPurchaseTimeintFirst fee deduction timestamp, which is the number of milliseconds since 00:00:00 on January 1, 1970.
subscriptionIdStringSubscription ID.
quantityintPurchase quantity.
daysLastedintDays of a paid subscription, excluding the free trial period and promotion period.
numOfPeriodsintNumber of successful standard renewal periods (that is, renewal periods without promotion). If the parameter is set to 0 or left empty, no renewal has been performed successfully.
numOfDiscountsintNumber of successful renewal periods with promotion.
expirationDateintSubscription expiration timestamp. For an automatic renewal receipt where the fee has been deducted successfully, this parameter indicates the renewal date or expiration date. If the value is a past time for the latest receipt of a product, the subscription has expired.
expirationIntentintReason why a subscription expires. 1: Canceled by a user. 2: Product being unavailable. 3: Abnormal user signing information. 4: Billing error. 5: Price increase disagreed with by a user. 6: Unknown error
retryFlagintIndicates whether the system still tries to renew an expired subscription.
introductoryFlagintIndicates whether a subscription is in the renewal period with promotion.
trialFlagintIndicates whether a subscription is in the free trial period.
cancelTimeintSubscription cancellation timestamp. This parameter has a value when a user makes a complaint and cancels a subscription through the customer service, or when a user performs subscription upgrade or cross-grade that immediately takes effect and cancels the previous receipt of the original subscription.
cancelReasonintReason why a subscription is canceled. 0: Others. For example, a user mistakenly purchases a subscription and has to cancel it. 1: A user encounters a problem within the app and cancels the subscription. 2: A user performs subscription upgrade or cross-grade.
appInfoStringApp information, which is reserved.
notifyClosedintIndicates whether a user has disabled the subscription notification function.
renewStatusintRenewal status. 1: The subscription renewal is normal. 0: The user cancels subscription renewal.
priceConsentStatusintUser opinion on the price increase of a product. 1: The user has agreed to the price increase. 0: The user does not take any action. After the subscription expires, it becomes invalid.
renewPriceintRenewal price.
subIsvalidbooltrue: A user has been charged for a product, the product has not expired, and no refund has been made. In this case, you can provide services for the user. false: The purchase of a product is not finished, the product has expired, or a refund has been made for the product after its purchase is the subscription valid.
cancelledSubKeepDaysintNumber of days for retaining a subscription relationship after the subscription is canceled.
kindintProduct type. 0: Consumable. 1: Non-consumable. 2: Renewable subscription. 3: Non-renewable subscription
developerChallengeStringChallenge defined when an app initiates a consumption request, which uniquely identifies the consumption request. This parameter is valid only for one-off products.
consumptionStateintConsumption status, which is valid only for one-off products. The options are as follows: 0: Not consumed. 1: Consumed.
payOrderIdStringMerchant ID, which uniquely identifies a transaction and is generated by the Huawei IAP server during payment.
payTypeStringPayment method. 0: HUAWEI Points 3: Credit card 4: Alipay 6: Carrier billing 13: PayPal 16: Debit card 17: WeChat Pay 19: Gift card 20: Balance 21: HUAWEI Point card 24: WorldPay 31: HUAWEI Pay 32: Ant Credit Pay 200: M-Pesa
deferFlagintIndicates whether to postpone the settlement date. The value 1 indicates that the settlement date is postponed.
oriSubscriptionIdStringOriginal subscription ID. If the parameter is set to a value, the current subscription is switched from another one. The value can be associated with the original subscription.
cancelWayintSubscription cancellation initiator. 0: User 1: Developer 2: Huawei
cancellationTimeintSubscription cancellation time in UTC.
resumeTimeintTime when a subscription is resumed.
accountFlagintAccount type. 1: AppTouch ID. Other values: HUAWEI ID
purchaseTimeMillisintPurchase time.
confirmedintConfirmation.
graceExpirationTimeintObtains timestamp when a grace period ends.
Public Constants
ConstantTypeValueDescription
NOT_PRESENTint-2147483648Not present.
INITIALIZEDint-2147483648Initialized.
PURCHASEDint0Purchased.
CANCELEDint1Canceled.
REFUNDEDint2Refunded.
Public Constructor Summary
ConstructorDescription
InAppPurchaseData({int applicationId, bool autoRenewing, String orderId, String packageName, String productId, String productName, int purchaseTime, int purchaseState, String developerPayload, String purchaseToken, int purchaseType, String currency, int price, String country, String lastOrderId, String productGroup, int oriPurchaseTime, String subscriptionId, int quantity, int daysLastes, int numOfPeriods, int numOfDiscounts, int expirationDate, int expirationIntent, int retryFlag, int introductoryFlag, int TrialFlag, int cancelTime, int cancelReason, String appInfo, int notifyClosed, int renewStatus, int priceConsentStatus, int renewPrice, bool subIsvalid, int cancelledSubKeepDays, int kind, String developerChallenge, int consumptionState, String payOrderId, String payType, int deferFlag, String orioriSubscriptionId, int cancelWay, int cancellationTime, int resumeTime, int accountFlag, int purchaseTimeMillis, int confirmed})Default constructor.
InAppPurchaseData.fromJson(String source)Creates an InAppPurchaseData object from a JSON string.
Public Constructors
InAppPurchaseData({int applicationId, bool autoRenewing, String orderId, String packageName, String productId, String productName, int purchaseTime, int purchaseState, String developerPayload, String purchaseToken, int purchaseType, String currency, int price, String country, String lastOrderId, String productGroup, int oriPurchaseTime, String subscriptionId, int quantity, int daysLastes, int numOfPeriods, int numOfDiscounts, int expirationDate, int expirationIntent, int retryFlag, int introductoryFlag, int TrialFlag, int cancelTime, int cancelReason, String appInfo, int notifyClosed, int renewStatus, int priceConsentStatus, int renewPrice, bool subIsvalid, int cancelledSubKeepDays, int kind, String developerChallenge, int consumptionState, String payOrderId, String payType, int deferFlag, String orioriSubscriptionId, int cancelWay, int cancellationTime, int resumeTime, int accountFlag, int purchaseTimeMillis, int confirmed, int graceExpirationTime})

Constructor for InAppPurchaseData object.

Click to expand/collapse Parameter table
ParameterTypeDescription
applicationIdintID of an app that initiates a purchase.
autoRenewingboolIndicates whether the subscription is automatically renewed. Currently, the value is always false.
orderIdStringOrder ID on the Huawei IAP server, which uniquely identifies a transaction and is generated by the Huawei IAP server during payment.
packageNameStringSoftware package name of the app that initiates a purchase.
productIdStringProduct ID.
productNameStringProduct name.
purchaseTimeintPurchase timestamp, which is the number of milliseconds from 00:00:00 on January 1, 1970 to the purchase time.
purchaseStateintOrder status. -1: Initialized and invisible 0: Purchased 1: Canceled 2: Refunded
developerPayloadStringReserved information on the merchant side, which is passed by the app during payment.
purchaseTokenStringPurchase token, which uniquely identifies the mapping between a product and a user. It is generated by the Huawei IAP server when the payment is complete.
purchaseTypeintPurchase type.0: in the sandbox1: in the promotion period (currently unsupported)This parameter is not returned during formal purchase.
currencyStringCurrency. The value must be a currency defined in the ISO 4217 standard. Example: USD, CNY, and TRY
priceintValue after the actual price of a product is multiplied by 100. The actual price is accurate to two decimal places. For example, if the value of this parameter is 501, the actual product price is 5.01.
countryStringCountry or region code of a user service area. The value must comply with the ISO 3166 standard. Example: US, CN, and TR
lastOrderIdStringOrder ID generated by the Huawei IAP server during fee deduction on the previous renewal.
productGroupStringID of the subscription group to which a subscription belongs.
oriPurchaseTimeintFirst fee deduction timestamp, which is the number of milliseconds since 00:00:00 on January 1, 1970.
subscriptionIdStringSubscription ID.
quantityintPurchase quantity.
daysLastedintDays of a paid subscription, excluding the free trial period and promotion period.
numOfPeriodsintNumber of successful standard renewal periods (that is, renewal periods without promotion). If the parameter is set to 0 or left empty, no renewal has been performed successfully.
numOfDiscountsintNumber of successful renewal periods with promotion.
expirationDateintSubscription expiration timestamp. For an automatic renewal receipt where the fee has been deducted successfully, this parameter indicates the renewal date or expiration date. If the value is a past time for the latest receipt of a product, the subscription has expired.
expirationIntentintReason why a subscription expires. 1: Canceled by a user. 2: Product being unavailable. 3: Abnormal user signing information. 4: Billing error. 5: Price increase disagreed with by a user. 6: Unknown error
retryFlagintIndicates whether the system still tries to renew an expired subscription.
introductoryFlagintIndicates whether a subscription is in the renewal period with promotion.
trialFlagintIndicates whether a subscription is in the free trial period.
cancelTimeintSubscription cancellation timestamp. This parameter has a value when a user makes a complaint and cancels a subscription through the customer service, or when a user performs subscription upgrade or cross-grade that immediately takes effect and cancels the previous receipt of the original subscription.
cancelReasonintReason why a subscription is canceled. 0: Others. For example, a user mistakenly purchases a subscription and has to cancel it. 1: A user encounters a problem within the app and cancels the subscription. 2: A user performs subscription upgrade or cross-grade.
appInfoStringApp information, which is reserved.
notifyClosedintIndicates whether a user has disabled the subscription notification function.
renewStatusintRenewal status. 1: The subscription renewal is normal. 0: The user cancels subscription renewal.
priceConsentStatusintUser opinion on the price increase of a product. 1: The user has agreed to the price increase. 0: The user does not take any action. After the subscription expires, it becomes invalid.
renewPriceintRenewal price.
subIsvalidbooltrue: A user has been charged for a product, the product has not expired, and no refund has been made. In this case, you can provide services for the user. false: The purchase of a product is not finished, the product has expired, or a refund has been made for the product after its purchase is the subscription valid.
cancelledSubKeepDaysintNumber of days for retaining a subscription relationship after the subscription is canceled.
kindintProduct type. 0: Consumable. 1: Non-consumable. 2: Renewable subscription. 3: Non-renewable subscription
developerChallengeStringChallenge defined when an app initiates a consumption request, which uniquely identifies the consumption request. This parameter is valid only for one-off products.
consumptionStateintConsumption status, which is valid only for one-off products. The options are as follows: 0: Not consumed. 1: Consumed.
payOrderIdStringMerchant ID, which uniquely identifies a transaction and is generated by the Huawei IAP server during payment.
payTypeStringPayment method. 0: HUAWEI Points 3: Credit card 4: Alipay 6: Carrier billing 13: PayPal 16: Debit card 17: WeChat Pay 19: Gift card 20: Balance 21: HUAWEI Point card 24: WorldPay 31: HUAWEI Pay 32: Ant Credit Pay 200: M-Pesa
deferFlagintIndicates whether to postpone the settlement date. The value 1 indicates that the settlement date is postponed.
oriSubscriptionIdStringOriginal subscription ID. If the parameter is set to a value, the current subscription is switched from another one. The value can be associated with the original subscription.
cancelWayintSubscription cancellation initiator. 0: User 1: Developer 2: Huawei
cancellationTimeintSubscription cancellation time in UTC.
resumeTimeintTime when a subscription is resumed.
accountFlagintAccount type. 1: AppTouch ID. Other values: HUAWEI ID
purchaseTimeMillisintPurchase time.
confirmedintConfirmation.
graceExpirationTimeintObtains timestamp when a grace period ends.
InAppPurchaseData.fromJson(String source)

Creates an InAppPurchaseData object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

IsEnvReadyResult

Information returned when the isEnvReady API is successfully called.

Public Properties
NameTypeDescription
returnCodeStringResult code. 0: The country or region of the signed-in HUAWEI ID supports HUAWEI IAP.
statusStatusStatus object that contains the task processing result.
Public Constructor Summary
ConstructorDescription
IsEnvReadyResult({String returnCode, Status status})Default constructor.
IsEnvReadyResult.fromJson(String source)Creates an IsEnvReadyResult object from a JSON string.
Public Constructors
IsEnvReadyResult({String returnCode, Status status})

Constructor for IsEnvReadyResult object.

ParameterTypeDescription
returnCodeStringResult code. 0: The country or region of the signed-in HUAWEI ID supports HUAWEI IAP.
statusStatusStatus object that contains the task processing result.
IsEnvReadyResult.fromJson(String source)

Creates an IsEnvReadyResult object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

IsSandboxActivatedResult

Information returned when the isSandboxActivated API is successfully called.

Public Properties
NameTypeDescription
errMsgStringResult code description.
isSandboxApkboolIndicates whether the app APK version meets the requirements of the sandbox testing.
isSandboxUserboolIndicates whether a sandbox testing account is used.
returnCodeStringResult code. 0: Success
versionFrMarketStringInformation about the app version that is last released on HUAWEI AppGallery.
versionInApkStringApp version information.
statusStatusStatus object that contains the task processing result.
Public Constructor Summary
ConstructorDescription
IsSandboxActivatedResult({String errMsg, bool isSandboxApk, isSandboxUser, String returnCode, String versionFrMarket, String versionInApk, Status status})Default constructor.
IsSandboxActivatedResult.fromJson(String source)Creates an IsSandboxActivatedResult object from a JSON string.
Public Constructors
IsSandboxActivatedResult({String errMsg, bool isSandboxApk, isSandboxUser, String returnCode, String versionFrMarket, String versionInApk, Status status})

Constructor for IsSandboxActivatedResult object.

ParameterTypeDescription
errMsgStringResult code description.
isSandboxApkboolIndicates whether the app APK version meets the requirements of the sandbox testing.
isSandboxUserboolIndicates whether a sandbox testing account is used.
returnCodeStringResult code. 0: Success
versionFrMarketStringInformation about the app version that is last released on HUAWEI AppGallery.
versionInApkStringApp version information.
statusStatusStatus object that contains the task processing result.
IsSandboxActivatedResult.fromJson(String source)

Creates an IsSandboxActivatedResult object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

OwnedPurchasesReq

Request information of the obtainOwnedPurchases and obtainOwnedPurchaseRecord API.

Public Properties
NameTypeDescription
priceTypeintType of a product to be queried. 0: Consumable 1: Non-consumable 2: Auto-renewable subscription
continuationTokenStringData location flag for query in pagination mode. This parameter is optional for the first query. After the API is called, the returned information contains this parameter. If query in pagination mode is required for the next API call, this parameter can be set for the second query.
Public Constructor Summary
ConstructorDescription
OwnedPurchasesReq({int priceType, String continuationToken})Default constructor.
OwnedPurcahsesReq.fromJson(String source)Creates an OwnedPurchasesReq object from a JSON string.
Public Constructors
OwnedPurchasesReq({int priceType, String continuationToken})

Constructor for OwnedPurchasesReq object.

ParameterTypeDescription
priceTypeintType of a product to be queried. 0: Consumable 1: Non-consumable 2: Auto-renewable subscription
continuationTokenStringData location flag for query in pagination mode. This parameter is optional for the first query. After the API is called, the returned information contains this parameter. If query in pagination mode is required for the next API call, this parameter can be set for the second query.
OwnedPurcahsesReq.fromJson(String source)

Creates an OwnedPurchasesReq object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

OwnedPurchasesResult

Information returned when the obtainedOwnedPurchases and obtainOwnedPurchaseRecord API is successfully called.

Public Properties
NameTypeDescription
continuationTokenStringData location flag. If a user has a large number of products and the response contains continuationToken, the app must initiate another call on the current method and pass continuationToken currently received. If product query is still incomplete, the app needs to call the API again until no continuationToken is returned, indicating that all products are returned.
errMsgStringResult code description.
inAppPurchaseDataListList<InAppPurchaseData>Information about products that have been purchased but not consumed or about all existing subscription relationships of users using the obtainOwnedPurchases method. Historical consumable information or all subscription receipts, which are returned using the obtainOwnedPurchaseRecord method.
inAppSignatureList<String>Signature character string of each subscription relationship in the InAppPurchaseDataList list.
itemListList<String>ID list of found products. The value is a string array.
returnCodeStringResult code.0: The query is successful.
statusStatusStatus object that contains the task processing result.
placedInappPurchaseDataListList<String>Subscription relationship information about a user who has performed subscription switchover. The value is a JSON string array. For details about the parameters contained in each JSON string, please refer to the description of InAppPurchaseData.
placedInappSignatureListList<String>Signature string of each subscription relationship in the placedInappPurchaseDataList list.
rawValueStringUnparsed JSON String of response. NOTE: IAP SDK does not return a JSON response. This field is the response class converted to JSON.
Public Constructor Summary
ConstructorDescription
OwnedPurchasesResult({String continuationToken, String errMsg, List<InAppPurchaseData> inAppPurchaseDataList, List<String> inAppSignature, List<String> itemList, String returnCode, Status status, List<String> placedInappPurchaseDataList, List<String> placedInappSignatureList})Default constructor.
OwnedPurchasesResult.fromJson(String source)Creates an OwnedPurchasesResult object from a JSON string.
Public Constructors
OwnedPurchasesResult({String continuationToken, String errMsg, List<InAppPurchaseData> inAppPurchaseDataList, List<String> inAppSignature, List<String> itemList, String returnCode, Status status, List<String> placedInappPurchaseDataList, List<String> placedInappSignatureList})

Constructor for OwnedPurchasesResult object.

ParameterTypeDescription
continuationTokenStringData location flag. If a user has a large number of products and the response contains continuationToken, the app must initiate another call on the current method and pass continuationToken currently received. If product query is still incomplete, the app needs to call the API again until no continuationToken is returned, indicating that all products are returned.
errMsgStringResult code description.
inAppPurchaseDataListList<InAppPurchaseData>Information about products that have been purchased but not consumed or about all existing subscription relationships of users using the obtainOwnedPurchases method. Historical consumable information or all subscription receipts, which are returned using the obtainOwnedPurchaseRecord method.
inAppSignatureList<String>Signature character string of each subscription relationship in the InAppPurchaseDataList list.
itemListList<String>ID list of found products. The value is a string array.
returnCodeStringResult code.0: The query is successful.
statusStatusStatus object that contains the task processing result.
placedInappPurchaseDataListList<String>Subscription relationship information about a user who has performed subscription switchover. The value is a JSON string array. For details about the parameters contained in each JSON string, please refer to the description of InAppPurchaseData.
placedInappSignatureListList<String>Signature string of each subscription relationship in the placedInappPurchaseDataList list.
OwnedPurchasesResult.fromJson(String source)

Creates an OwnedPurchasesResult object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

ProductInfo

Details of a product.

Public Properties
Click to expand/collapse Properties table
NameTypeDescription
productIdStringProduct ID.
priceTypeintProduct type. 0: Consumable 1: Non-consumable 2: Auto-renewable subscription
priceStringDisplayed price of a product, including the currency symbol and actual price of the product. The value is in the Currency symbolPrice format, for example, ¥0.15. The price includes the tax.
microsPriceintProduct price in micro unit, which equals to the actual product price multiplied by 1,000,000. For example, if the actual price of a product is US$1.99, the product price in micro unit is 1990000 (1.99 x 1000000).
originalLocalPriceStringOriginal price of a product, including the currency symbol and actual price of the product. The value is in the Currency symbolPrice format, for example, ¥0.15. The price includes the tax.
originalMicroPriceintOriginal price of a product in micro unit, which equals to the original product price multiplied by 1,000,000. For example, if the original price of a product is US$1.99, the product price in micro unit is 1990000 (1.99 x 1000000).
currencyStringCurrency used to pay for a product. The value must comply with the ISO 4217 standard. Example: USD, CNY, and TRY
productNameStringProduct name, which is set during product information configuration. The name is displayed on the checkout page.
productDescStringDescription of a product, which is set during product information configuration.
subSpecialPriceMicrosintPromotional subscription price in micro unit, which equals to the actual promotional subscription price multiplied by 1,000,000. For example, if the actual price of a product is US$1.99, the product price in micro unit is 1990000 (1.99 x 1000000). This parameter is returned only when subscriptions are queried.
subSpecialPeriodCyclesintNumber of promotion periods of a subscription. It is set when you set the promotional price of a subscription in AppGallery Connect. For details, please refer to Setting a Promotional Price. This parameter is returned only when subscriptions are queried.
subProductLevelintLevel of a subscription in its subscription group.
statusintProduct status. 0: Valid. 1: Deleted. Products in this state cannot be renewed or subscribed to. 6: Removed. New subscriptions are not allowed, but users who have subscribed to products can still renew them.
subFreeTrialPeriodStringFree trial period of a subscription. It is set when you set the promotional price of a subscription in AppGallery Connect. For details, please refer to Setting a Promotional Price.
subGroupIdStringID of the subscription group to which a subscription belongs.
subGroupTitleStringDescription of the subscription group to which a subscription belongs.
subSpecialPeriodStringPromotion period unit of a subscription, which complies with the ISO 8601 standard. For example, P1W indicates 1 week, P1M indicates 1 month, P2M indicates 2 months, P6M indicates 6 months, and P1Y indicates 1 year. This parameter is returned only when subscriptions are queried.
subPeriodStringUnit of a subscription period, which complies with the ISO 8601 standard. For example, P1W indicates 1 week, P1M indicates 1 month, P2M indicates 2 months, P6M indicates 6 months, and P1Y indicates 1 year. This parameter is returned only when subscriptions are queried.
subSpecialPriceStringPromotional price of a subscription, including the currency symbol and actual price. The value is in the Currency symbolPrice format, for example, ¥0.15. The price includes the tax. This parameter is returned only when subscriptions are queried.
Public Constructor Summary
ConstructorDescription
ProductInfo({String productId, int priceType, String price, int microsPrice, String originalLocalPrice, int originalMicroPrice, String currency, String productName, String productDesc, int subSpecialPriceMicros, int subSpecialPeriodCycles, int subProductLevel, int status, String subFreeTrialPeriod, String subGroupId, String subGroupTitle, String subSpecialPeriod, String subPeriod, String subSpecialPrice})Default constructor.
ProductInfo.fromJson(String source)Creates a ProductInfo object from a JSON string.
Public Constructors
ProductInfo({String productId, int priceType, String price, int microsPrice, String originalLocalPrice, int originalMicroPrice, String currency, String productName, String productDesc, int subSpecialPriceMicros, int subSpecialPeriodCycles, int subProductLevel, int status, String subFreeTrialPeriod, String subGroupId, String subGroupTitle, String subSpecialPeriod, String subPeriod, String subSpecialPrice})

Constructor for ProductInfo object.

Click to expand/collapse Parameter table
ParameterTypeDescription
productIdStringProduct ID.
priceTypeintProduct type. 0: Consumable 1: Non-consumable 2: Auto-renewable subscription
priceStringDisplayed price of a product, including the currency symbol and actual price of the product. The value is in the Currency symbolPrice format, for example, ¥0.15. The price includes the tax.
microsPriceintProduct price in micro unit, which equals to the actual product price multiplied by 1,000,000. For example, if the actual price of a product is US$1.99, the product price in micro unit is 1990000 (1.99 x 1000000).
originalLocalPriceStringOriginal price of a product, including the currency symbol and actual price of the product. The value is in the Currency symbolPrice format, for example, ¥0.15. The price includes the tax.
originalMicroPriceintOriginal price of a product in micro unit, which equals to the original product price multiplied by 1,000,000. For example, if the original price of a product is US$1.99, the product price in micro unit is 1990000 (1.99 x 1000000).
currencyStringCurrency used to pay for a product. The value must comply with the ISO 4217 standard. Example: USD, CNY, and TRY
productNameStringProduct name, which is set during product information configuration. The name is displayed on the checkout page.
productDescStringDescription of a product, which is set during product information configuration.
subSpecialPriceMicrosintPromotional subscription price in micro unit, which equals to the actual promotional subscription price multiplied by 1,000,000. For example, if the actual price of a product is US$1.99, the product price in micro unit is 1990000 (1.99 x 1000000). This parameter is returned only when subscriptions are queried.
subSpecialPeriodCyclesintNumber of promotion periods of a subscription. It is set when you set the promotional price of a subscription in AppGallery Connect. For details, please refer to Setting a Promotional Price. This parameter is returned only when subscriptions are queried.
subProductLevelintLevel of a subscription in its subscription group.
statusintProduct status. 0: Valid. 1: Deleted. Products in this state cannot be renewed or subscribed to. 6: Removed. New subscriptions are not allowed, but users who have subscribed to products can still renew them.
subFreeTrialPeriodStringFree trial period of a subscription. It is set when you set the promotional price of a subscription in AppGallery Connect. For details, please refer to Setting a Promotional Price.
subGroupIdStringID of the subscription group to which a subscription belongs.
subGroupTitleStringDescription of the subscription group to which a subscription belongs.
subSpecialPeriodStringPromotion period unit of a subscription, which complies with the ISO 8601 standard. For example, P1W indicates 1 week, P1M indicates 1 month, P2M indicates 2 months, P6M indicates 6 months, and P1Y indicates 1 year. This parameter is returned only when subscriptions are queried.
subPeriodStringUnit of a subscription period, which complies with the ISO 8601 standard. For example, P1W indicates 1 week, P1M indicates 1 month, P2M indicates 2 months, P6M indicates 6 months, and P1Y indicates 1 year. This parameter is returned only when subscriptions are queried.
subSpecialPriceStringPromotional price of a subscription, including the currency symbol and actual price. The value is in the Currency symbolPrice format, for example, ¥0.15. The price includes the tax. This parameter is returned only when subscriptions are queried.
ProductInfo.fromJson(String source)

Creates a ProductInfo object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

ProductInfoReq

Request object of the obtainProductInfo API.

Public Properties
NameTypeDescription
priceTypeintType of a product to be queried. 0: Consumable 1: Non-consumable 2: Auto-renewable subscription
skuIdsList<String>ID list of products to be queried. Each product ID must exist and be unique in the current app. The product ID is the same as that you set when configuring product information in AppGallery Connect. For details, please refer to Adding a Product.
Public Constructor Summary
ConstructorDescription
ProductInfoReq({int priceType, List<String> skuIds})Default constructor.
ProductInfoReq.fromJson(String source)Creates a ProductInfoReq object from a JSON string.
Public Constructors
ProductInfoReq({int priceType, List<String> skuIds})

Constructor for ProductInfoReq object.

ParameterTypeDescription
priceTypeintType of a product to be queried. 0: Consumable 1: Non-consumable 2: Auto-renewable subscription
skuIdsList<String>ID list of products to be queried. Each product ID must exist and be unique in the current app. The product ID is the same as that you set when configuring product information in AppGallery Connect. For details, please refer to Adding a Product.
ProductInfoReq.fromJson(String source)

Creates a ProductInfoReq object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

ProductInfoResult

Information returned when the obtainProductInfo API is successfully called.

Public Properties
NameTypeDescription
errMsgStringResult code description.
productInfoListList<ProductInfo>List of found products.
returnCodeStringResult code. 0: The query is successful.
statusStatusStatus object that contains the task processing result.
Public Constructor Summary
ConstructorDescription
ProductInfoResult({String errMsg, List<ProductInfo> productInfoList, String returnCode, Status status})Default constructor.
ProductInfoResult.fromJson(String source)Creates a ProductInfoResult object from a JSON string.
Public Constructors
ProductInfoResult({String errMsg, List<ProductInfo> productInfoList, String returnCode, Status status})

Constructor for ProductInfoResult object.

ParameterTypeDescription
errMsgStringResult code description.
productInfoListList<ProductInfo>List of found products.
returnCodeStringResult code. 0: The query is successful.
statusStatusStatus object that contains the task processing result.
ProductInfoResult.fromJson(String source)

Creates a ProductInfoResult object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

PurchaseIntentReq

Request object of the createPurchaseIntent API.

Public Properties
NameTypeDescription
priceTypeintProduct type. 0: Consumable 1: Non-consumable 2: Auto-renewable subscription
productIdStringID of a product to be paid. The product ID is the same as that you set when configuring product information in AppGallery Connect. For details, please refer to Adding a Product.
developerPayloadStringInformation stored on the merchant side. If this parameter is set, the value will be returned in the callback result to the app after successful payment. Note: The value length of this parameter is within (0, 128).
reservedInforStringThis parameter is used to pass the extra fields set by a merchant in a JSON string in the key-value format.
Public Constructor Summary
ConstructorDescription
PurchaseIntentReq({int priceType, String productId, String developerPayload, String reservedInfor})Default constructor.
PurchaseIntentReq.fromJson(String source)Creates a PurchaseIntentReq object from a JSON string.
Public Constructors
PurchaseIntentReq({int priceType, String productId, String developerPayload, String reservedInfor})

Constructor for PurchaseIntentReq object.

ParameterTypeDescription
priceTypeintProduct type.0: consumable1: non-consumable2: auto-renewable subscription
productIdStringID of a product to be paid. The product ID is the same as that you set when configuring product information in AppGallery Connect. For details, please refer to Adding a Product.
developerPayloadStringInformation stored on the merchant side. If this parameter is set, the value will be returned in the callback result to the app after successful payment. Note: The value length of this parameter is within (0, 128).
reservedInforStringThis parameter is used to pass the extra fields set by a merchant in a JSON string in the key-value format.
PurchaseIntentReq.fromJson(String source)

Creates a PurchaseIntentReq object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

PurchaseResultInfo

Returned payment result information.

Public Properties
NameTypeDescription
returnCodeStringResult code. 0: The payment is successful. Other values: The payment failed. For details about the result codes, please refer to Troubleshooting and Common Result Codes.
inAppPurchaseDataInAppPurchaseDataInAppPurchaseData object that contains purchase order details. For details about the parameters contained in the string, please refer to InAppPurchaseData.
inAppDataSignatureStringSignature string generated after purchase data is signed using a private payment key. The signature algorithm is SHA256withRSA. After the payment is successful, the app needs to perform signature verification on the string of InAppPurchaseData using the payment public key. For details about how to obtain the public key, please refer to Querying IAP Information.
errMsgStringResult code description.
rawValueStringUnparsed JSON String of response. NOTE: IAP SDK does not return a JSON response. This field is the response class converted to JSON.
Public Constructor Summary
ConstructorDescription
PurchaseResultInfo({String returnCode, InAppPurchaseData inAppPurchaseData, String inAppDataSignature, String errMsg})Default constructor.
PurchaseResultInfo.fromJson(String source)Creates a PurchaseResultInfo object from a JSON string.
Public Constructors
PurchaseResultInfo({String returnCode, InAppPurchaseData inAppPurchaseData, String inAppDataSignature, String errMsg})

Constructor for PurchaseResultInfo object

ParameterTypeDescription
returnCodeStringResult code. 0: The payment is successful. Other values: The payment failed. For details about the result codes, please refer to Troubleshooting and Common Result Codes.
inAppPurchaseDataInAppPurchaseDataInAppPurchaseData object that contains purchase order details. For details about the parameters contained in the string, please refer to InAppPurchaseData.
inAppDataSignatureStringSignature string generated after purchase data is signed using a private payment key. The signature algorithm is SHA256withRSA. After the payment is successful, the app needs to perform signature verification on the string of InAppPurchaseData using the payment public key. For details about how to obtain the public key, please refer to Querying IAP Information.
errMsgStringResult code description.
PurchaseResultInfo.fromJson(String source)

Creates a PurchaseResultInfo object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

StartIapActivityReq

Request object of startIapActivity API.

Public Properties
NameTypeDescription
typeintType of the page to be redirected to. 2: Subscription management page. 3: Subscription editing page.
productIdStringID of a subscription.
Public Constants
ConstantTypeDescription
TYPE_SUBSCRIBE_MANAGER_ACTIVITYintRedirects your app to the subscription management page of HUAWEI IAP.
TYPE_SUBSCRIBE_EDIT_ACTIVITYintRedirects your app to the subscription editing page of HUAWEI IAP.
Public Constructor Summary
ConstructorDescription
StartIapActivityReq({int type, String productId})Default constructor.
StartIapActivityReq.fromJson(String source)Creates a StartIapActivityReq object from a JSON string.
Public Constructors
StartIapActivityReq({int type, String productId})

Constructor for StartIapActivityReq object.

ParameterTypeDescription
typeintType of the page to be redirected to. 2: Subscription management page. 3: Subscription editing page.
productIdStringID of a subscription
StartIapActivityReq.fromJson(String source)

Creates a StartIapActivityReq object from a JSON string.

ParameterTypeDescription
sourceStringJSON string as a source.

Status

Task processing result.

Public Properties
NameTypeDescription
statusCodeintStatus code. 0: Success. 1: Failure. 404: No resource found. 500: Internal error.
statusMessageStringStatus description.
statusStatusTask processing result.
Public Constructor Summary
ConstructorDescription
Status({int statusCode, String statusMessage, Status status})Default constructor.
Public Constructors
Status({int statusCode, String statusMessage, Status status})

Constructor for Status object.

ParameterTypeDescription
statusCodeintStatus code. 0: Success. 1: Failure. 404: No resource found. 500: Internal error.
statusMessageStringStatus description.
statusStatusTask processing result.

HmsIapResult

Represents an error class for HmsIapResults.

Public Properties
NameTypeDescription
resultCodeStringResult code.
resultMessageStringResult message.
Public Constructor Summary
ConstructorDescription
HmsIapResult({String resultCode, String resultMessage})Default constructor.
Public Constructors
HmsIapResult({String resultCode, String resultMessage})

Constructor for HmsIapResult object.

ParameterTypeDescription
resultCodeStringResult code.
resultMessageStringResult message.

Constants #

HmsIapResults

Click to expand/collapse Constants table
ConstantTypeResult Code (String)Result MessagePossible Solution
ORDER_STATE_SUCCESSHmsIapResult0Success-
ORDER_STATE_FAILEDHmsIapResult-1Common failure result code.If this result code is returned by the purchase request, you are advised to use the obtainOwnedPurchases API to check whether the user has purchased the product.
ORDER_STATE_CANCELHmsIapResult60000The user cancels the payment.Record the order ID and execute the payment process when the user performs the payment operation again.
ORDER_STATE_PARAM_ERRORHmsIapResult60001Parameter error (including no parameter).Check whether request parameters are missing and whether the parameter format is correct.
ORDER_STATE_IAP_NOT_ACTIVATEDHmsIapResult60002Huawei IAP is not enabled.To use HUAWEI IAP, you first need to enable the IAP service and also set IAP parameters. For details, please refer to Enabling Services.
ORDER_STATE_PRODUCT_INVALIDHmsIapResult60003Incorrect product information.Sign in to AppGallery Connect. Choose My apps, select an app, and go to Operate > Products > Product Management. In the product list, check whether the product exists or whether all its mandatory information is available.
ORDER_STATE_CALLS_FREQUENTHmsIapResult60004Too frequent API calls.Control the API call frequency.
ORDER_STATE_NET_ERRORHmsIapResult60005Network connection exception.The app displays a message, asking the user to check the network.
ORDER_STATE_PMS_TYPE_NOT_MATCHHmsIapResult60006Inconsistent product.Sign in to AppGallery Connect. Choose My apps, select an app, and go to Operate > Products > Product Management. Find the product in the product list and check its type.
ORDER_STATE_PRODUCT_COUNTRY_NOT_SUPPORTEDHmsIapResult60007Country not supported.Sign in to AppGallery Connect. Choose My apps, select an app, and go to Operate > Products > Product Management. In the product list, check whether the product exists or whether all its mandatory information is available.
ORDER_VR_UNINSTALL_ERRORHmsIapResult60020VR APK is not installed.This code is returned in the VR payment scenario. Install the VR APK first.
ORDER_HWID_NOT_LOGINHmsIapResult60050Huawei ID is not signed in.The sign-in scenario needs to be processed. For the payment and isEnvReady APIs, you can use status to instruct users to sign in. For other APIs, perform operations as needed.
ORDER_PRODUCT_OWNEDHmsIapResult60051User already owns the product.Use the obtainOwnedPurcases API to check whether the user has purchased the product. For a consumable that has been purchased, call the ConsumeOwnedPurchase API to consume the product after it is delivered. After being consumed, the product can be purchased next time. If the product is a non-consumable product or a subscription, the product cannot be purchased again.
ORDER_PRODUCT_NOT_OWNEDHmsIapResult60052User does not owns the product.Use the obtainOwnedPurchases API to check whether the user has purchased the product.
ORDER_PRODUCT_CONSUMEDHmsIapResult60053Product already consumed.Use the obtainOwnedPurchaseRecord API to check whether the product has a consumption record.
ORDER_ACCOUNT_AREA_NOT_SUPPORTEDHmsIapResult60054Huawei IAP does not support country/region.This result code may be returned when HUAWEI IAP is supported by a country or region but there is a service error. In this case, call related APIs again or contact Huawei technical support.
ORDER_NOT_ACCEPT_AGREEMENTHmsIapResult60055Agreement error.Please accept user agreement.
ORDER_HIGH_RISK_OPERATIONSHmsIapResult60056User triggers risk control.-
LOG_IN_ERRORHmsIapResultERR_CAN_NOT_LOG_INCan not log in.The sign-in scenario needs to be processed again.
UNKNOWN_REQUEST_CODEHmsIapResultUNKNOWN_REQUEST_CODEThis request code does not match with any available request codes.Try recalling the API.
ACTIVITY_RESULTHmsIapResultACTIVITY_RESULT_ERRORResult is not OK.Try recalling the API.
IS_SANDBOX_READY_ERRORHmsIapResultIS_SANDBOX_READY_ERRORnullTry recalling the API.
OBTAIN_PRODUCT_INFO_ERRORHmsIapResultOBTAIN_PRODUCT_INFO_ERRORnullTry recalling the API.
PURCHASE_INTENT_EXCEPTIONHmsIapResultPURCHASE_INTENT_EXCEPTIONnullTry recalling the API.
CONSUME_OWNED_PURCHASE_ERRORHmsIapResultCONSUME_OWNED_PURCHASE_ERRORnullTry recalling the API.
OBTAIN_OWNED_PURCHASES_ERRORHmsIapResultOBTAIN_OWNED_PURCHASES_ERRORnullTry recalling the API.
START_IAP_ACTIVITY_ERRORHmsIapResultSTART_IAP_ACTIVITY_ERRORnullTry recalling the API.
PURCHASE_INTENT_RESOLUTIONHmsIapResultPURCHASE_INTENT_RESOLUTION_ERRORnullTry recalling the API.
NO_RESOLUTIONHmsIapResultNO_RESOLUTIONThere is no resolution for error.Try recalling the API.

You can read more and get detailed information about the interfaces described above from developer.huawei.com


4. Configuration and Description #

Preparing for Release #

Before building a release version of your app you may need to customize the proguard-rules.pro obfuscation configuration file to prevent the HMS Core SDK from being obfuscated. Add the configurations below to exclude the HMS Core SDK from obfuscation. For more information on this topic refer to this Android developer guide.

<flutter_project>/android/app/proguard-rules.pro

-ignorewarnings
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-keep class com.hianalytics.android.**{*;}
-keep class com.huawei.updatesdk.**{*;}
-keep class com.huawei.hms.**{*;}

<flutter_project>/android/app/build.gradle

buildTypes {
    debug {
        signingConfig signingConfigs.config
    }
    release {
        signingConfig signingConfigs.config
        // Enables code shrinking, obfuscation and optimization for release builds
        minifyEnabled true
        // Unused resources will be removed, resources defined in the res/raw/keep.xml will be kept.
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

5. Sample Project #

This plugin includes a demo project in the example folder, there you can find more usage examples.


6. Questions or Issues #

If you have questions about how to use HMS samples, try the following options:

  • Stack Overflow is the best place for any programming questions. Be sure to tag your question with huawei-mobile-services.
  • Github is the official repository for these plugins, You can open an issue or submit your ideas.
  • Huawei Developer Forum HMS Core Module is great for general questions, or seeking recommendations and opinions.
  • Huawei Developer Docs is place to official documentation for all HMS Core Kits, you can find detailed documentations in there.

If you run into a bug in our samples, please submit an issue to the GitHub repository.


7. Licensing and Terms #

Huawei IAP Kit Flutter Plugin is licensed under Apache 2.0 license

8
likes
80
pub points
61%
popularity

Publisher

developer.huawei.com

HUAWEI IAP Kit plugin for Flutter. Huawei's In-App Purchases (IAP) service allows you to offer in-app purchases and facilitates in-app payment.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache 2.0 (LICENSE)

Dependencies

flutter

More

Packages that depend on huawei_iap