We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
quickApp ReferencesQuick AppAPIHMS CoreIAP 3.0

IAP 3.0

NOTICE

This function depends on the services provided by the IAP SDK. The SDK may collect personal data of users. Before using this function in a quick app, inform users that personal data will be collected and guide them to read the privacy statement.

NOTE

This document describes only the definition of APIs. For details about how and when to call these APIs, please refer to Integrating IAP.

API Declaration

Add the following configuration to the features attribute in the manifest.json file:

Collapse
Word wrap
Dark theme
Copy code
  1. {"name": "service.pay"}

Module Import

Add the following configuration to the script element on the page where the API will be called:

Collapse
Word wrap
Dark theme
Copy code
  1. import pay from '@service.pay'

Or

Collapse
Word wrap
Dark theme
Copy code
  1. var pay = require("@service.pay")

Application Scope

Expand

Item

Description

Applicable devices

Mobile phones, tablets, and Vision products

Applicable regions

Global

Definition

Expand

API

Description

pay.getProvider(OBJECT)

Obtains the service provider.

pay.isEnvReady(OBJECT)

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

pay.isSandboxActivated(OBJECT)

Checks whether the signed-in HUAWEI ID and the RPK version meet the requirements of the sandbox testing.

pay.obtainOwnedPurchases(OBJECT)

Queries information about all purchased products, including consumables, non-consumables, and subscriptions.

pay.obtainProductInfo(OBJECT)

Obtains product details configured in AppGallery Connect.

pay.createPurchaseIntent(OBJECT)

Creates an order for purchasing a product configured in AppGallery Connect.

pay.consumeOwnedPurchase(OBJECT)

Consumes a consumable after the payment is successful.

pay.obtainOwnedPurchaseRecord(OBJECT)

Obtains the consumption history of a consumable or all subscription receipts of a subscription.

pay.startIapActivity(OBJECT)

Displays IAP-related screens.

pay.getProvider(OBJECT)

Description

Obtains the service provider.

Returns

Character string, which is the code of the service provider (for example, the English brand name of the vendor), is returned. If the service does not exist, an empty string is returned. If so, do not call other APIs of the service. Otherwise, an exception will occur.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. pay.getProvider();

pay.isEnvReady(OBJECT)

Description

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

OBJECT parameters

Expand

Parameter

Type

Mandatory

Description

isEnvReadyReq

json

Yes

Checks whether requests from IAP are supported. For details, please refer to isEnvReadyReq parameter description.

success

function

No

Callback upon success.

fail

function

No

Callback upon failure.

complete

function

No

Callback upon completion.

isEnvReadyReq parameters

Expand

Parameter

Type

Mandatory

Description

applicationID

string

Yes

Unique ID allocated to a quick app created by the vendor alliance. For details about how to obtain the ID, please refer to Obtaining the App ID.

Parameters returned by success

Expand

Parameter

Type

Description

returnCode

number

Result code. The value 0 indicates success.

Parameters returned by fail

Expand

Parameter

Type

Description

data

string

Error description. Check the error type before obtaining the error code.

code

number

Error code.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. pay.isEnvReady({
  2. isEnvReadyReq: {
  3. "applicationID": "101315751"
  4. },
  5. success: function (data) {
  6. console.debug("isEnvReady data =", JSON.stringify(data));
  7. prompt.showToast({
  8. message: "Env ready!"
  9. })
  10. },
  11. fail: function (data, code) {
  12. console.log("isEnvReady fail data =" + data, "code =" + code);
  13. prompt.showToast({
  14. message: "isEnvReady fail!"
  15. })
  16. }
  17. })

pay.isSandboxActivated(OBJECT)

Description

Checks whether the signed-in HUAWEI ID meets the requirements of the sandbox testing.

Parameters

Expand

Parameter

Type

Mandatory

Description

isSandboxActivatedReq

json

Yes

Indicates whether the signed-in HUAWEI ID meets the sandbox testing requirements. For details, please refer to isSandboxActivatedReq parameters.

success

function

No

Callback upon success.

fail

function

No

Callback upon failure.

complete

function

No

Callback upon completion.

isSandboxActivatedReq parameters

Expand

Parameter

Type

Mandatory

Description

applicationID

string

Yes

Unique ID allocated to a quick app created by the vendor alliance. For details about how to obtain the ID, please refer to Obtaining the App ID.

Parameters returned by success

Expand

Parameter

Type

Description

returnCode

number

Result code.

errMsg

string

Result code description.

isSandboxUser

boolean

Indicates whether a sandbox account is used.

isSandboxApk

boolean

Indicates whether Quick App Center meets the sandbox testing requirements. The value true is always returned.

versionInApk

string

Version information of Quick App Center.

versionFrMarket

string

Information about the latest app version on Quick App Center.

Parameters returned by fail

Expand

Parameter

Type

Description

data

string

Error description. Check the error type before obtaining the error code.

code

number

Error code.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. pay.isSandboxActivated({
  2. isSandboxActivatedReq: {
  3. "applicationID": "101315751",
  4. },
  5. success: function (data) {
  6. console.debug("isSandboxActivated data =", JSON.stringify(data));
  7. prompt.showToast({
  8. message: "isSandboxActivated success!"
  9. })
  10. },
  11. fail: function (data, code) {
  12. console.log("isSandboxActivated fail data =" + JSON.stringify(data), "code =" + code);
  13. prompt.showToast({
  14. message: "isSandboxActivated fail!"
  15. })
  16. }
  17. })

pay.obtainOwnedPurchases(OBJECT)

Description

Queries information about all purchased products, including consumables, non-consumables, and subscriptions.

  • If the information about consumables is returned, the products might not be delivered due to some exceptions. In this case, your app needs to check whether the products are delivered. If not, the app needs to deliver them and call the pay.consumeOwnedPurchase API to consume them.
  • If the information about non-consumables is returned, the non-consumables do not need to be consumed.
  • If the information about subscriptions is returned, all existing subscription relationships of the user in the app are returned. The subscription relationships are as follows:

- Renewal (normal use and normal renewal in the next period)

- Expiring (expiration instead of renewal when the next period starts)

- Expired (The subscribed service is unavailable but can still be found in the subscription history.)

OBJECT parameters

Expand

Parameter

Type

Mandatory

Description

ownedPurchasesReq

json

Yes

Queries information about all subscribed products that are not used. For details, please refer to ownedPurchasesReq parameters.

success

function

No

Callback upon success.

fail

function

No

Callback upon failure.

complete

function

No

Callback upon completion.

ownedPurchasesReq parameters

Expand

Parameter

Type

Mandatory

Description

applicationID

string

Yes

Unique ID allocated to a quick app created by the vendor alliance. For details about how to obtain the ID, please refer to Obtaining the App ID.

priceType

number

Yes

Product type.

  • 0: consumable
  • 1: non-consumable
  • 2: subscription

publicKey

string

Yes

Payment public key obtained when Payment Service is enabled. For details about how to obtain the key, please refer to Obtaining the Payment Public Key.

continuationToken

string

No

Data location flag for a query in pagination mode. This parameter does not need to be passed during the first query. If the data needs to be queried in batches, pass the value of continuationToken returned by success in the last query.

Parameters returned by success

Expand

Parameter

Type

Description

returnCode

number

Result code.

errMsg

string

Result code description.

itemList

array

ID list of purchased products returned as a string array.

inAppPurchaseDataList

array

Purchased in-app product information returned as a string array. Each string element in the array is in JSON format.

inAppSignature

array

Signature string that contains the purchase data (inAppPurchaseDataList) signed using the payment private key. The signature algorithm is SHA256withRSA. Each signature string maps a product in inAppPurchaseDataList. That is, the first signature string in inAppSignature maps the first product record in inAppPurchaseDataList; the second string maps the second product record, and so on. Signature verification is required for each JSON string in inAppPurchaseDataList. If the verification fails, the app needs to obtain the product information again. For details about signature verification, please refer to Verifying the Signature in the Result.

continuationToken

string

Data locating 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 the currently received continuationToken. If product query is still incomplete, the app needs to call the method again until no continuationToken is returned, indicating that all products are returned.

placedInappPurchaseDataList

array

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 InAppPurchaseData. Subscription switchover refers to the switch from one product in one period to another product in the same subscription group in the next period. In this case, the relationship between the first product and the user is canceled, and another relationship between the second product and the user is established. In this case, the method returns the subscription relationship information about the second product. The value of this parameter is returned only when priceType is set to 2 and the user has performed a subscription switchover.

placedInappSignatureList

array

This parameter matches the signature string of the subscription relationship in placedInappPurchaseDataList. Signature verification is required for each JSON string in placedInappPurchaseDataList. If the verification fails, the app needs to obtain the subscription relationship again. For details about signature verification, please refer to Verifying the Signature in the Result. The value of this parameter is returned only when priceType is set to 2 and the user has performed a subscription switchover.

Result codes returned by fail

Expand

Parameter

Type

Description

data

string

Error description. Check the error type before obtaining the error code.

code

number

Error code.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. pay.obtainOwnedPurchases({
  2. ownedPurchasesReq: {
  3. "priceType": 0,
  4. "applicationID": "101315751",
  5. "publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAnLLFO6c8d1x6jdbZ8PkNtrLtRMiFaRqWZgEjC4Vj9QXnPCmDZoPO5A5TSwzlWjYL5ktbbDnZC6Vfp8VI8nTMm8DvbGsJ+1ihru31vG1gqvUgOaXESqBhdpMrKFEgNBV8zlalLpcCU6Gayd8QJCxXRPcUisHLTQFJHjTMOWmvOcKiSxt1VmG3dvfWVkoMeKyerZy4qHEWM/asJihPZATBQ7puMC/kOh6i8V2gv4w/74KWifpBr3J5RN+PK6E7yWUqIALFTnN5vOIif2HELvgt+S6uaGpRydhSwu1xtV7bPtXQY20ollYo4BUi+AvM16iBCa1+1Mdw0y6Y9gZAtpHRK1Pf+yea4aoY4y/bZ6EX21wucvbzxexDcBkGn0DVvNHKr3usmUmq/yfMMmDPqPujv3iDWKFENfL4Agugo7I8etCF8vVYDOT5J8gXupgGLiritkfALZD8HgNZADyM+NnvQBJrdeVoHxCYoQMCS2hySPf2AaZWT7PzVAeGidLcEeKlAgMBAAE="
  6. },
  7. success: function (data) {
  8. console.debug("obtainOwnedPurchases data =", JSON.stringify(data));
  9. prompt.showToast({
  10. message: "obtainOwnedPurchases success!"
  11. })
  12. },
  13. fail: function (data, code) {
  14. console.log("obtainOwnedPurchases fail data =" + data, "code =" + code);
  15. prompt.showToast({
  16. message: "obtainOwnedPurchases fail!"
  17. })
  18. }
  19. })

pay.obtainProductInfo(OBJECT)

Description

Obtains product details configured in AppGallery Connect. Avoid obtaining product information from your own server. Otherwise, price information may be inconsistent between your app and the checkout page of IAP.

OBJECT parameters

Expand

Parameter

Type

Mandatory

Description

productInfoReq

json

Yes

Request for obtaining product details. For details, please refer to productInfoReq parameters.

success

function

No

Callback upon success.

fail

function

No

Callback upon failure.

complete

function

No

Callback upon completion.

productInfoReq parameters

Expand

Parameter

Type

Mandatory

Description

applicationID

string

Yes

Unique ID allocated to a quick app created by the vendor alliance. For details about how to obtain the ID, please refer to Obtaining the App ID.

priceType

number

Yes

Product type.

  • 0: consumable
  • 1: non-consumable
  • 2: subscription

productIds

array

Yes

Product ID.

Parameters returned by success

Expand

Parameter

Type

Description

returnCode

number

Result code.

errMsg

string

Result code description.

productInfoList

array

List of products that are queried successfully. The value is an array containing the productInfo object.

productInfo description

Expand

Parameter

Type

Mandatory

Description

productId

string

Yes

Product ID.

priceType

number

Yes

Product type.

  • 0: consumable
  • 1: non-consumable
  • 2: subscription

price

string

Yes

Displayed price of a product.

microsPrice

number

Yes

Product price in micro unit, which equals the actual product price multiplied by 1,000,000.

For example, if the actual price of a product is USD1.99, the product price in micro unit is 1,990,000 (1.99 x 1,000,000).

currency

string

Yes

Currency used to pay for a product. The value must comply with the ISO 4217 standard, for example, USD, CNY, and MYR.

productName

string

Yes

Product name, which is set during product information configuration and displayed on the checkout page.

productDesc

string

Yes

Product description, which is set during product information configuration.

subPeriod

string

No

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

NOTE

This parameter is returned only when subscriptions are queried.

subSpecialPrice

string

No

Promotional price of a subscription, including the currency unit and actual price of the product. The value is in the Currency unit Price format. The currency unit and price are separated using a space character, for example, CNY 0.15. The price does not include the tax.

NOTE

This parameter is returned only when subscriptions are queried.

subSpecialPriceMicros

number

No

Subscription price in micro unit.

NOTE

This parameter is returned only when subscriptions are queried.

subSpecialPeriod

string

No

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

NOTE

This parameter is returned only when subscriptions are queried.

subSpecialPeriodCycles

string

No

Number of promotional 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 Promotional Prices.

NOTE

This parameter is returned only when subscriptions are queried.

subsFreeTrialPeriod

string

No

Free 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 Promotional Prices.

NOTE

This parameter is returned only when subscriptions are queried.

subsGroupId

string

No

ID of the subscription group to which a subscription belongs.

NOTE

This parameter is returned only when subscriptions are queried.

subsGroupTitle

string

No

Description of the subscription group to which a subscription belongs.

NOTE

This parameter is returned only when subscriptions are queried.

subsProductLevel

string

No

Level of a subscription in its subscription group.

NOTE

This parameter is returned only when subscriptions are queried.

originalMicroPrice

string

No

Obtains the original price in micro unit of a product. The price equals the original product price multiplied by 1,000,000.

originalLocalPrice

string

No

Original price of a product, including the currency unit and actual price of the product. The value is in the Currency symbolPrice format, for example, ¥0.15. The price includes the tax.

status

int

No

Obtains the product status.

  • 0: valid.
  • 1: deleted. Products in this state cannot be renewed or subscribed to.
  • 3: removed. New subscriptions are not allowed, but users who have subscribed to it can still renew the subscription.
    NOTE

    This parameter is not required for querying non-subscriptions.

Result codes returned by fail

Expand

Parameter

Type

Description

data

string

Error description. Check the error type before obtaining the error code.

code

number

Error code.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. pay.obtainProductInfo({
  2. productInfoReq: {
  3. "priceType": 1,
  4. "productIds": ["dy1","dmy00","lcole"],
  5. "applicationID": "101315751",
  6. },
  7. success: function (data) {
  8. console.debug("obtainProductInfo =" + JSON.stringify(data));
  9. prompt.showToast({
  10. message: "obtainProductInfo success!"
  11. })
  12. },
  13. fail: function (data, code) {
  14. console.log("obtainProductInfo fail data =" + JSON.stringify(data), "code =" + code);
  15. prompt.showToast({
  16. message: "obtainProductInfo fail!"
  17. })
  18. }
  19. })

pay.createPurchaseIntent(OBJECT)

Description

Creates an order for purchasing a product configured in AppGallery Connect.

After creating a product in AppGallery Connect, you can call this API to open the 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 API to obtain product details from Huawei instead of your own server.

OBJECT parameters

Expand

Parameter

Type

Mandatory

Description

purchaseIntentReq

json

Yes

Purchase request. For details, please refer to purchaseIntentReq parameters.

success

function

No

Callback upon success.

fail

function

No

Callback upon failure.

complete

function

No

Callback upon completion.

purchaseIntentReq parameters

Expand

Parameter

Type

Mandatory

Description

applicationID

string

Yes

Unique ID allocated to a quick app created by the vendor alliance. For details about how to obtain the ID, please refer to Obtaining the App ID.

publicKey

string

Yes

Payment public key obtained when Payment Service is enabled. For details about how to obtain the key, please refer to Obtaining the Payment Public Key.

productId

string

Yes

ID of a product to be paid. The product ID is the same as that you configure in the product information in AppGallery Connect.

priceType

string

Yes

Product type.

  • 0: consumable
  • 1: non-consumable
  • 2: subscription

developerPayload

string

No

Information stored on the merchant side. If a value exists, the value will be returned in the callback result to the app after successful payment.

Parameters returned by success

Expand

Parameter

Type

Description

returnCode

number

Result code.

errMsg

string

Result code description.

inAppDataSignature

string

Signature string that contains the purchase data (inAppPurchaseData) signed using the app private key. The signature algorithm is SHA256withRSA. After the payment is successful, the app needs to verify the JSON string of inAppPurchaseData using the payment public key. For details, please refer to Verifying the Signature in the Result.

inAppPurchaseData

string

JSON string of purchase order details. For details, please refer to inAppPurchaseData parameters.

inAppPurchaseData parameters

Expand

Parameter

Type

Mandatory

Description

applicationId

string

Yes

App ID.

autoRenewing

boolean

Yes

  • For consumables or non-consumables, the value is always false.
  • For subscriptions, the value true indicates that the subscription is in active state and will be automatically renewed on the next renewal date.
  • For subscriptions, the value false indicates that the user has canceled the subscription. The user can access the subscribed content only before the next renewal date, unless automatic renewal is enabled.

If a grace period is applicable, this value remains true for the subscription during the grace period. The next settlement date is automatically postponed every day until the grace period ends or the user changes the payment method.

orderId

string

No

Obtains the order ID from Huawei IAP server, which uniquely identifies a transaction and is generated by IAP server during payment.

kind

number

Yes

Product type.

  • 0: consumable
  • 1: non-consumable
  • 2: subscription

packageName

string

No

Package name on Quick App Center.

productId

string

Yes

Product ID. Each product must have a unique ID, which is maintained in PMS.

productName

string

No

Product name.

purchaseTime

string

No

Timestamp of the purchase time, which is the number of milliseconds from 00:00:00 on January 1, 1970 to the purchase time.

purchaseState

string

Yes

Transaction status. The options are as follows:

  • -1: initialized
  • 0: purchased
  • 1: canceled
  • 2: refunded

developerPayload

string

No

Information stored on the merchant side, which is passed by the app when the payment API is called.

developerChallenge

string

No

Challenge defined when an app initiates a consumption request, which uniquely identifies the consumption request.

NOTE

This parameter is available only for non-subscriptions.

consumptionState

string

No

Consumption status.

  • 0: not consumed
  • 1: consumed

purchaseToken

string

No

Obtains the purchase token, which uniquely identifies the mapping between a product and a user. It is generated by Huawei IAP server when the payment is complete.

NOTE

This parameter uniquely identifies the mapping between a product and a user. It does not change when the subscription is renewed. Currently, the value contains 92 characters and its length may be expanded. If the value needs to be stored, you are advised to reserve 128 characters.

purchaseType

number

No

Purchase type. This parameter is not returned during normal purchases.

  • 0: in the sandbox
  • 1: in the promotional period (currently unsupported)

currency

string

No

Currency. The value must comply with the ISO 4217 standard.

price

number

No

Obtains the value that is equal to the actual price of a product multiplied by 100.

country

string

Yes

Country or region code, which is used to identify a country or region. The value must comply with the ISO 3166 standard.

payType

string

No

Payment method.

  • 0: HUAWEI Points
  • 3: credit card
  • 4: Alipay
  • 6: DCB
  • 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

The following parameters are returned only for query of subscriptions.

lastOrderId

string

Yes

ID of the last renewal order, which is generated by IAP server during fee deduction. The parameter value is the same as that of orderId when a subscription is purchased for the first time.

productGroup

string

No

ID of the subscription group to which a subscription belongs.

purchaseTime

number

No

Timestamp of the purchase time, which is the number of milliseconds from 00:00:00 on January 1, 1970 to the purchase time. If the purchase is not complete, this parameter is left empty.

oriPurchaseTime

number

No

Timestamp of the first fee deduction time, which is the number of milliseconds from 00:00:00 on January 1, 1970 to the first successful fee deduction time.

subscriptionId

string

Yes

Subscription ID.

oriSubscriptionId

string

No

Original subscription ID. If a value exists, the current subscription is switched from another one. The value can be associated with the information about the original subscription.

quantity

number

No

Purchase quantity.

daysLasted

number

No

Days of a paid subscription, excluding the free trial period and promotional period.

numOfPeriods

number

No

Number of successful standard renewal periods (that is, renewal periods without promotion). If the value is 0 or does not exist, no renewal has been performed successfully.

numOfDiscount

number

No

Number of periods for successful renewal after promotion.

expirationDate

number

No

Timestamp of the subscription expiration time. For an automatic renewal receipt where the fee has been deducted successfully, this parameter indicates the renewal or expiration time. If the value is a past time, the subscription has expired.

expirationIntent

number

No

Reason why a subscription expires. The options are as follows:

  • 1: canceled by a user
  • 2: product unavailable
  • 3: abnormal user signing information
  • 4: billing error
  • 5: price increase disagreed with by a user
  • 6: unknown error

If multiple exceptions occur at the same time, the exception with the highest priority is returned (the highest priority is 1 and the lowest is 6).

retryFlag

number

No

Indicates whether the system still tries to renew an expired subscription.

  • 0: no
  • 1: yes

introductoryFlag

number

No

Indicates whether a subscription is in the renewal period after promotion. The options are as follows:

  • 0: no
  • 1: yes

trialFlag

number

No

Indicates whether a subscription is in the free trial period. The options are as follows:

  • 0: no
  • 1: yes

cancelTime

number

No

Timestamp of the subscription cancellation time. A value is returned when a user: (1) makes a complaint and cancels a subscription through the customer service personnel; (2) performs subscription upgrade or crossgrade that immediately takes effect and cancels the previous receipt of the original subscription.

NOTE

If a receipt is canceled, the purchase is not complete.

cancelReason

number

No

Cause of subscription cancellation. The options are as follows:

  • 2: A user performs subscription upgrade or crossgrade.
  • 1: A user encounters a problem within the app and cancels the subscription.
  • 0: other causes. For example, a user mistakenly purchases a subscription and has to cancel it.
    NOTE

    If this parameter is left empty but the cancelTime parameter has a value, the cancellation is caused by an operation such as upgrade.

renewStatus

number

No

Renewal status. The options are as follows:

  • 1: The subscription will automatically renew at the end of the current subscription period.
  • 0: The user has canceled subscription renewal. For auto-renewable subscriptions, this parameter is valid for both valid and expired subscriptions. However, it does not represent users' subscription status.

Generally, when the value is 0, the app can provide other subscription options for the user, for example, recommending another subscription at a lower level in the same group. The value 0 indicates that a user proactively cancels the subscription.

priceConsentStatus

number

Optional

User opinion on the price increase of a product.

  • 1: The user has agreed with the price increase.
  • 0: The user does not respond to the price increase. After the subscription expires, it becomes invalid.

renewPrice

number

No

Price used upon the next renewal. It is provided as a reference for users when the priceConsentStatus parameter is returned.

subIsvalid

boolean

No

  • true: 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.
    NOTE

    If a user has canceled a subscription, the value of subIsvalid remains true until the subscription expires.

cancelledSubKeepDays

number

No

Number of days for retaining a subscription relationship after the subscription is canceled. (In these days, the user can resume the subscription anytime as needed.)

resumeTime

number

No

Time when a paused subscription is resumed.

Parameters returned by fail

Expand

Parameter

Type

Description

data

string

Error description. Check the error type before obtaining the error code.

code

number

Error code.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. pay.createPurchaseIntent({
  2. purchaseIntentReq: {
  3. "applicationID": "101315751",
  4. "productId": "dmy001",
  5. "priceType": 0,
  6. "developerPayload": "testPurchase",
  7. "publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAnLLFO6c8d1x6jdbZ8PkNtrLtRMiFaRqWZgEjC4Vj9QXnPCmDZoPO5A5TSwzlWjYL5ktbbDnZC6Vfp8VI8nTMm8DvbGsJ+1ihru31vG1gqvUgOaXESqBhdpMrKFEgNBV8zlalLpcCU6Gayd8QJCxXRPcUisHLTQFJHjTMOWmvOcKiSxt1VmG3dvfWVkoMeKyerZy4qHEWM/asJihPZATBQ7puMC/kOh6i8V2gv4w/74KWifpBr3J5RN+PK6E7yWUqIALFTnN5vOIif2HELvgt+S6uaGpRydhSwu1xtV7bPtXQY20ollYo4BUi+AvM16iBCa1+1Mdw0y6Y9gZAtpHRK1Pf+yea4aoY4y/bZ6EX21wucvbzxexDcBkGn0DVvNHKr3usmUmq/yfMMmDPqPujv3iDWKFENfL4Agugo7I8etCF8vVYDOT5J8gXupgGLiritkfALZD8HgNZADyM+NnvQBJrdeVoHxCYoQMCS2hySPf2AaZWT7PzVAeGidLcEeKlAgMBAAE="
  8. },
  9. success: function (data) {
  10. that.inAppPurchaseData = data;
  11. console.debug("createPurchaseIntent success =" + JSON.stringify(data));
  12. prompt.showToast({
  13. message: "createPurchaseIntent success!"
  14. })
  15. },
  16. fail: function (data, code) {
  17. console.log("createPurchaseIntent fail data =" + data, "code =" + code);
  18. prompt.showToast({
  19. message: "createPurchaseIntent fail!"
  20. })
  21. }
  22. })

pay.consumeOwnedPurchase(OBJECT)

Description

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

  1. If you consume a product before delivery, the following exception may occur: When the consumption API is called, the consumption is successfully executed on the server but the result is not returned to the device due to network exceptions. As a result, the product is not delivered to the device. This exception is difficult to handle, so you are advised to consume the product after the delivery.
  2. Send the token of the delivered product to your app server. Even if the consumption fails, you can obtain data from your server for comparison. You are advised to check your app server before delivery to ensure that each involved purchase token has not been used, that is, no involved product is delivered.

OBJECT parameters

Expand

Parameter

Type

Mandatory

Description

consumeOwnedPurchaseReq

json

Yes

Request for consuming a product. For details, please refer to consumeOwnedPurchaseReq parameters.

success

function

No

Callback upon success.

fail

function

No

Callback upon failure.

complete

function

No

Callback upon completion.

consumeOwnedPurchaseReq parameters

Expand

Parameter

Type

Mandatory

Description

applicationID

json

Yes

Unique ID allocated to a quick app created by the vendor alliance. For details about how to obtain the ID, please refer to Obtaining the App ID.

developerChallenge

string

No

Custom challenge, which uniquely identifies a consumption request. After the consumption is successful, the challenge is recorded in the purchase information and returned. The value length is within (0, 64).

purchaseToken

string

No

Purchase token, which is generated by Huawei IAP server during payment and returned to the app through InAppPurchaseData. The app passes this parameter for Huawei IAP server to update the order status and then deliver the product.

publicKey

string

Yes

Payment public key obtained when Payment Service is enabled. For details about how to obtain the key, please refer to Obtaining the Payment Public Key.

Parameters returned by success

Expand

Parameter

Type

Description

returnCode

Number

Result code.

errMsg

string

Result code description.

consumePurchaseData

string

JSON string that contains consumption result data.

dataSignature

string

Signature string for consumePurchaseData based on the payment private key.

consumePurchaseData parameters

Expand

Parameter

Type

Mandatory

Description

applicationId

string

Yes

Unique ID allocated to a quick app created by the vendor alliance. For details about how to obtain the ID, please refer to Obtaining the App ID.

autoRenewing

boolean

Yes

Indicates whether a subscription is automatically renewed.

  • true: yes
  • false: no

orderId

string

Yes

Obtains the order ID from Huawei IAP server, which uniquely identifies a transaction and is generated by IAP server during payment.

packageName

string

Yes

Package name on Quick App Center.

productId

string

Yes

Product ID.

purchaseTime

number

Yes

Timestamp of the purchase time, which is the number of milliseconds from 00:00:00 on January 1, 1970 to the purchase time.

purchaseState

number

Yes

Order status. The options are as follows:

  • -1: initialized and invisible
  • 0: purchased
  • 1: canceled
  • 2: refunded

developerPayload

string

No

Information stored on the merchant side, which is passed by the app during payment.

purchaseToken

string

Yes

Obtains the purchase token, which uniquely identifies the mapping between a product and a user. It is generated by Huawei IAP server when the payment is complete.

developerChallenge

string

No

Challenge defined when an app initiates a consumption request, which uniquely identifies the consumption request.

consumptionState

number

Yes

Consumption status.

  • 0: not consumed
  • 1: consumed

currency

string

Yes

Currency. The value must comply with the ISO 4217 standard, for example, USD, CNY, and MYR.

price

number

Yes

100 times of the actual product price (accurate to two decimal places). For example, if the actual product price is 5.00, the value of this parameter is 500 (5.00 x 100).

country

string

Yes

Country or region code of a user service area. The value must comply with the ISO 3166 standard. For example, US is used for the United States of America, CN for the Chinese mainland, and MY for Malaysia.

responseCode

string

Yes

Result code. The value 0 indicates success.

responseMessage

string

No

Response.

Parameters returned by fail

Expand

Parameter

Type

Description

data

string

Error description. Check the error type before obtaining the error code.

code

number

Error code.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. pay.consumeOwnedPurchase({
  2. consumeOwnedPurchaseReq: {
  3. "applicationID": "101315751",
  4. "developerPayload": "testPurchase",
  5. "purchaseToken": "0000017297d6a4faa22aaa2fa705e96247231b89ec228b3fd05e378b70e4c7d023a9c972c540e3d0x434e.1.101315751",
  6. "publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAnLLFO6c8d1x6jdbZ8PkNtrLtRMiFaRqWZgEjC4Vj9QXnPCmDZoPO5A5TSwzlWjYL5ktbbDnZC6Vfp8VI8nTMm8DvbGsJ+1ihru31vG1gqvUgOaXESqBhdpMrKFEgNBV8zlalLpcCU6Gayd8QJCxXRPcUisHLTQFJHjTMOWmvOcKiSxt1VmG3dvfWVkoMeKyerZy4qHEWM/asJihPZATBQ7puMC/kOh6i8V2gv4w/74KWifpBr3J5RN+PK6E7yWUqIALFTnN5vOIif2HELvgt+S6uaGpRydhSwu1xtV7bPtXQY20ollYo4BUi+AvM16iBCa1+1Mdw0y6Y9gZAtpHRK1Pf+yea4aoY4y/bZ6EX21wucvbzxexDcBkGn0DVvNHKr3usmUmq/yfMMmDPqPujv3iDWKFENfL4Agugo7I8etCF8vVYDOT5J8gXupgGLiritkfALZD8HgNZADyM+NnvQBJrdeVoHxCYoQMCS2hySPf2AaZWT7PzVAeGidLcEeKlAgMBAAE="
  7. },
  8. success: function (data) {
  9. console.debug("consumeOwnedPurchase data =", JSON.stringify(data));
  10. prompt.showToast({
  11. message: "consumeOwnedPurchase success!"
  12. })
  13. },
  14. fail: function (data, code) {
  15. console.log("consumeOwnedPurchase fail data =" + JSON.stringify(data), "code =" + code);
  16. prompt.showToast({
  17. message: "consumeOwnedPurchase fail!"
  18. })
  19. }
  20. })

pay.obtainOwnedPurchaseRecord(OBJECT)

Description

Obtains the consumption history of 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.

OBJECT parameters

Expand

Parameter

Type

Mandatory

Description

ownedPurchasesRecordReq

json

Yes

Request for querying subscribed products. For details, please refer to ownedPurchasesRecordReq parameters.

success

function

No

Callback upon success.

fail

function

No

Callback upon failure.

complete

function

No

Callback upon completion.

ownedPurchasesRecordReq parameters

Expand

Parameter

Type

Mandatory

Description

applicationID

string

Yes

Unique ID allocated to a quick app created by the vendor alliance. For details about how to obtain the ID, please refer to Obtaining the App ID.

priceType

number

Yes

Product type.

  • 0: consumable
  • 1: non-consumable
  • 2: auto-renewable subscription

publicKey

string

Yes

Payment public key obtained when Payment Service is enabled. For details about how to obtain the key, please refer to Obtaining the Payment Public Key.

continuationToken

string

No

Data location flag for a query in pagination mode. This parameter does not need to be passed during the first query. If the number of records queried for the first time exceeds 200, this parameter is returned after the query and needs be contained in the second query.

Parameters returned by success

Expand

Parameter

Type

Description

returnCode

number

Result code.

errMsg

string

Result code description.

itemList

array

ID list of purchased products returned as a string array.

inAppPurchaseDataList

array

Purchased in-app product information returned as a string array. Each string element in the array is in JSON format.

inAppSignature

array

Signature string that contains the purchase data (inAppPurchaseDataList) signed using the payment private key. The signature algorithm is SHA256withRSA. Each signature string maps a product in inAppPurchaseDataList. That is, the first signature string in inAppSignature maps the first product record in inAppPurchaseDataList; the second string maps the second product record, and so on. Signature verification is required for each JSON string in inAppPurchaseDataList. If the verification fails, the app needs to obtain the product information again. For details about signature verification, please refer to Verifying the Signature in the Result.

continuationToken

string

Data locating 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 the currently received continuationToken. If product query is still incomplete, the app needs to call the method again until no continuationToken is returned, indicating that all products are returned.

placedInappPurchaseDataList

array

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 InAppPurchaseData. Subscription switchover refers to the switch from one product in one period to another product in the same subscription group in the next period. In this case, the relationship between the first product and the user is canceled, and another relationship between the second product and the user is established. In this case, the method returns the subscription relationship information about the second product. The value of this parameter is returned only when priceType is set to 2 and the user has performed a subscription switchover.

placedInappSignatureList

array

This parameter matches the signature string of the subscription relationship in placedInappPurchaseDataList. Signature verification is required for each JSON string in placedInappPurchaseDataList. If the verification fails, the app needs to obtain the subscription relationship again. For details about signature verification, please refer to Verifying the Signature in the Result. The value of this parameter is returned only when priceType is set to 2 and the user has performed a subscription switchover.

Parameters returned by fail

Expand

Parameter

Type

Description

data

string

Error description. Check the error type before obtaining the error code.

code

number

Error code.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. pay.obtainOwnedPurchaseRecord({
  2. ownedPurchasesRecordReq: {
  3. "applicationID": "101315751",
  4. "priceType": 2,
  5. "publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAnLLFO6c8d1x6jdbZ8PkNtrLtRMiFaRqWZgEjC4Vj9QXnPCmDZoPO5A5TSwzlWjYL5ktbbDnZC6Vfp8VI8nTMm8DvbGsJ+1ihru31vG1gqvUgOaXESqBhdpMrKFEgNBV8zlalLpcCU6Gayd8QJCxXRPcUisHLTQFJHjTMOWmvOcKiSxt1VmG3dvfWVkoMeKyerZy4qHEWM/asJihPZATBQ7puMC/kOh6i8V2gv4w/74KWifpBr3J5RN+PK6E7yWUqIALFTnN5vOIif2HELvgt+S6uaGpRydhSwu1xtV7bPtXQY20ollYo4BUi+AvM16iBCa1+1Mdw0y6Y9gZAtpHRK1Pf+yea4aoY4y/bZ6EX21wucvbzxexDcBkGn0DVvNHKr3usmUmq/yfMMmDPqPujv3iDWKFENfL4Agugo7I8etCF8vVYDOT5J8gXupgGLiritkfALZD8HgNZADyM+NnvQBJrdeVoHxCYoQMCS2hySPf2AaZWT7PzVAeGidLcEeKlAgMBAAE="
  6. },
  7. success: function (data) {
  8. console.debug("obtainOwnedPurchaseRecord data =", JSON.stringify(data));
  9. prompt.showToast({
  10. message: "obtainOwnedPurchaseRecord success!"
  11. })
  12. },
  13. fail: function (data, code) {
  14. console.log("obtainOwnedPurchaseRecord fail data =" + JSON.stringify(data), "code =" + code);
  15. prompt.showToast({
  16. message: "obtainOwnedPurchaseRecord fail!"
  17. })
  18. }
  19. })

pay.startIapActivity(OBJECT)

Description

Displays IAP-related subscription screens.

  • Subscription editing page
  • Subscription management page

OBJECT parameters

Expand

Parameter

Type

Mandatory

Description

startIapActivityReq

json

Yes

Request for jumping to the subscription page. For details, please refer to startIapActivityReq parameters.

success

function

No

Callback upon success.

fail

function

No

Callback upon failure.

complete

function

No

Callback upon completion.

startIapActivityReq parameters

Expand

Parameter

Type

Mandatory

Description

applicationID

string

Yes

Unique ID allocated to a quick app created by the vendor alliance. For details about how to obtain the ID, please refer to Obtaining the App ID.

type

number

Yes

Redirection page. The options are as follows:

  • 2: subscription management page
  • 3: subscription editing page

subscribeProductId

string

No

ID of a subscribed subscription. This parameter is required when type is set to 3, while it is not required when type is set to 2.

Parameters returned by success

None

Parameters returned by fail

Expand

Parameter

Type

Description

data

string

Error description. Check the error type before obtaining the error code.

code

number

Error code.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. pay.startIapActivity({
  2. startIapActivityReq: {
  3. "applicationID": "101315751",
  4. "type": 2,
  5. "subscribeProductId":"dy1"
  6. },
  7. success: function () {
  8. prompt.showToast({
  9. message: "startIapActivity success!"
  10. })
  11. },
  12. fail: function (data, code) {
  13. console.log("startIapActivity fail data =" + JSON.stringify(data), "code =" + code);
  14. prompt.showToast({
  15. message: "createPurchaseIntent fail!"
  16. })
  17. }
  18. })

Result Codes

Expand

Result Code

Description

200

Common error.

202

Invalid input parameter.

1002

Failed to authenticate the app.

1001

Failed to verify the public key.

Other error codes

For details, please refer to Troubleshooting and Common Result Codes.