Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
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.
This document describes only the definition of APIs. For details about how and when to call these APIs, please refer to Integrating IAP.
Add the following configuration to the features attribute in the manifest.json file:
- {"name": "service.pay"}
Add the following configuration to the script element on the page where the API will be called:
- import pay from '@service.pay'
Or
- var pay = require("@service.pay")
Item | Description |
|---|---|
Applicable devices | Mobile phones, tablets, and Vision products |
Applicable regions | Global |
API | Description |
|---|---|
Obtains the service provider. | |
Checks whether the currently signed-in HUAWEI ID is located in a country or region where IAP is available. | |
Checks whether the signed-in HUAWEI ID and the RPK version meet the requirements of the sandbox testing. | |
Queries information about all purchased products, including consumables, non-consumables, and subscriptions. | |
Obtains product details configured in AppGallery Connect. | |
Creates an order for purchasing a product configured in AppGallery Connect. | |
Consumes a consumable after the payment is successful. | |
Obtains the consumption history of a consumable or all subscription receipts of a subscription. | |
Displays IAP-related screens. |
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
- pay.getProvider();
Description
Checks whether the currently signed-in HUAWEI ID is located in a country or region where IAP is available.
OBJECT parameters
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
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
Parameter | Type | Description |
|---|---|---|
returnCode | number | Result code. The value 0 indicates success. |
Parameters returned by fail
Parameter | Type | Description |
|---|---|---|
data | string | Error description. Check the error type before obtaining the error code. |
code | number | Error code. |
Sample code
- pay.isEnvReady({
- isEnvReadyReq: {
- "applicationID": "101315751"
- },
- success: function (data) {
- console.debug("isEnvReady data =", JSON.stringify(data));
- prompt.showToast({
- message: "Env ready!"
- })
- },
- fail: function (data, code) {
- console.log("isEnvReady fail data =" + data, "code =" + code);
- prompt.showToast({
- message: "isEnvReady fail!"
- })
- }
- })
Description
Checks whether the signed-in HUAWEI ID meets the requirements of the sandbox testing.
Parameters
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
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
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
Parameter | Type | Description |
|---|---|---|
data | string | Error description. Check the error type before obtaining the error code. |
code | number | Error code. |
Sample code
- pay.isSandboxActivated({
- isSandboxActivatedReq: {
- "applicationID": "101315751",
- },
- success: function (data) {
- console.debug("isSandboxActivated data =", JSON.stringify(data));
- prompt.showToast({
- message: "isSandboxActivated success!"
- })
- },
- fail: function (data, code) {
- console.log("isSandboxActivated fail data =" + JSON.stringify(data), "code =" + code);
- prompt.showToast({
- message: "isSandboxActivated fail!"
- })
- }
- })
Description
Queries information about all purchased products, including consumables, non-consumables, and subscriptions.
- 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
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
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.
|
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
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
Parameter | Type | Description |
|---|---|---|
data | string | Error description. Check the error type before obtaining the error code. |
code | number | Error code. |
Sample code
- pay.obtainOwnedPurchases({
- ownedPurchasesReq: {
- "priceType": 0,
- "applicationID": "101315751",
- "publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAnLLFO6c8d1x6jdbZ8PkNtrLtRMiFaRqWZgEjC4Vj9QXnPCmDZoPO5A5TSwzlWjYL5ktbbDnZC6Vfp8VI8nTMm8DvbGsJ+1ihru31vG1gqvUgOaXESqBhdpMrKFEgNBV8zlalLpcCU6Gayd8QJCxXRPcUisHLTQFJHjTMOWmvOcKiSxt1VmG3dvfWVkoMeKyerZy4qHEWM/asJihPZATBQ7puMC/kOh6i8V2gv4w/74KWifpBr3J5RN+PK6E7yWUqIALFTnN5vOIif2HELvgt+S6uaGpRydhSwu1xtV7bPtXQY20ollYo4BUi+AvM16iBCa1+1Mdw0y6Y9gZAtpHRK1Pf+yea4aoY4y/bZ6EX21wucvbzxexDcBkGn0DVvNHKr3usmUmq/yfMMmDPqPujv3iDWKFENfL4Agugo7I8etCF8vVYDOT5J8gXupgGLiritkfALZD8HgNZADyM+NnvQBJrdeVoHxCYoQMCS2hySPf2AaZWT7PzVAeGidLcEeKlAgMBAAE="
- },
- success: function (data) {
- console.debug("obtainOwnedPurchases data =", JSON.stringify(data));
- prompt.showToast({
- message: "obtainOwnedPurchases success!"
- })
- },
- fail: function (data, code) {
- console.log("obtainOwnedPurchases fail data =" + data, "code =" + code);
- prompt.showToast({
- message: "obtainOwnedPurchases fail!"
- })
- }
- })
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
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
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.
|
productIds | array | Yes | Product ID. |
Parameters returned by success
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
Parameter | Type | Mandatory | Description |
|---|---|---|---|
productId | string | Yes | Product ID. |
priceType | number | Yes | Product type.
|
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.
|
Result codes returned by fail
Parameter | Type | Description |
|---|---|---|
data | string | Error description. Check the error type before obtaining the error code. |
code | number | Error code. |
Sample code
- pay.obtainProductInfo({
- productInfoReq: {
- "priceType": 1,
- "productIds": ["dy1","dmy00","lcole"],
- "applicationID": "101315751",
- },
- success: function (data) {
- console.debug("obtainProductInfo =" + JSON.stringify(data));
- prompt.showToast({
- message: "obtainProductInfo success!"
- })
- },
- fail: function (data, code) {
- console.log("obtainProductInfo fail data =" + JSON.stringify(data), "code =" + code);
- prompt.showToast({
- message: "obtainProductInfo fail!"
- })
- }
- })
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
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
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.
|
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
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
Parameter | Type | Mandatory | Description |
|---|---|---|---|
applicationId | string | Yes | App ID. |
autoRenewing | boolean | Yes |
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.
|
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:
|
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.
|
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.
|
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.
|
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:
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.
|
introductoryFlag | number | No | Indicates whether a subscription is in the renewal period after promotion. The options are as follows:
|
trialFlag | number | No | Indicates whether a subscription is in the free trial period. The options are as follows:
|
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:
|
renewStatus | number | No | Renewal status. The options are as follows:
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.
|
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 |
|
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
Parameter | Type | Description |
|---|---|---|
data | string | Error description. Check the error type before obtaining the error code. |
code | number | Error code. |
Sample code
- pay.createPurchaseIntent({
- purchaseIntentReq: {
- "applicationID": "101315751",
- "productId": "dmy001",
- "priceType": 0,
- "developerPayload": "testPurchase",
- "publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAnLLFO6c8d1x6jdbZ8PkNtrLtRMiFaRqWZgEjC4Vj9QXnPCmDZoPO5A5TSwzlWjYL5ktbbDnZC6Vfp8VI8nTMm8DvbGsJ+1ihru31vG1gqvUgOaXESqBhdpMrKFEgNBV8zlalLpcCU6Gayd8QJCxXRPcUisHLTQFJHjTMOWmvOcKiSxt1VmG3dvfWVkoMeKyerZy4qHEWM/asJihPZATBQ7puMC/kOh6i8V2gv4w/74KWifpBr3J5RN+PK6E7yWUqIALFTnN5vOIif2HELvgt+S6uaGpRydhSwu1xtV7bPtXQY20ollYo4BUi+AvM16iBCa1+1Mdw0y6Y9gZAtpHRK1Pf+yea4aoY4y/bZ6EX21wucvbzxexDcBkGn0DVvNHKr3usmUmq/yfMMmDPqPujv3iDWKFENfL4Agugo7I8etCF8vVYDOT5J8gXupgGLiritkfALZD8HgNZADyM+NnvQBJrdeVoHxCYoQMCS2hySPf2AaZWT7PzVAeGidLcEeKlAgMBAAE="
- },
- success: function (data) {
- that.inAppPurchaseData = data;
- console.debug("createPurchaseIntent success =" + JSON.stringify(data));
- prompt.showToast({
- message: "createPurchaseIntent success!"
- })
- },
- fail: function (data, code) {
- console.log("createPurchaseIntent fail data =" + data, "code =" + code);
- prompt.showToast({
- message: "createPurchaseIntent fail!"
- })
- }
- })
Description
Consumes a consumable after the consumable is successfully delivered to a user who has completed payment.
OBJECT parameters
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
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
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
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.
|
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:
|
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.
|
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
Parameter | Type | Description |
|---|---|---|
data | string | Error description. Check the error type before obtaining the error code. |
code | number | Error code. |
Sample code
- pay.consumeOwnedPurchase({
- consumeOwnedPurchaseReq: {
- "applicationID": "101315751",
- "developerPayload": "testPurchase",
- "purchaseToken": "0000017297d6a4faa22aaa2fa705e96247231b89ec228b3fd05e378b70e4c7d023a9c972c540e3d0x434e.1.101315751",
- "publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAnLLFO6c8d1x6jdbZ8PkNtrLtRMiFaRqWZgEjC4Vj9QXnPCmDZoPO5A5TSwzlWjYL5ktbbDnZC6Vfp8VI8nTMm8DvbGsJ+1ihru31vG1gqvUgOaXESqBhdpMrKFEgNBV8zlalLpcCU6Gayd8QJCxXRPcUisHLTQFJHjTMOWmvOcKiSxt1VmG3dvfWVkoMeKyerZy4qHEWM/asJihPZATBQ7puMC/kOh6i8V2gv4w/74KWifpBr3J5RN+PK6E7yWUqIALFTnN5vOIif2HELvgt+S6uaGpRydhSwu1xtV7bPtXQY20ollYo4BUi+AvM16iBCa1+1Mdw0y6Y9gZAtpHRK1Pf+yea4aoY4y/bZ6EX21wucvbzxexDcBkGn0DVvNHKr3usmUmq/yfMMmDPqPujv3iDWKFENfL4Agugo7I8etCF8vVYDOT5J8gXupgGLiritkfALZD8HgNZADyM+NnvQBJrdeVoHxCYoQMCS2hySPf2AaZWT7PzVAeGidLcEeKlAgMBAAE="
- },
- success: function (data) {
- console.debug("consumeOwnedPurchase data =", JSON.stringify(data));
- prompt.showToast({
- message: "consumeOwnedPurchase success!"
- })
- },
- fail: function (data, code) {
- console.log("consumeOwnedPurchase fail data =" + JSON.stringify(data), "code =" + code);
- prompt.showToast({
- message: "consumeOwnedPurchase fail!"
- })
- }
- })
Description
Obtains the consumption history of a consumable or all subscription receipts of a subscription.
OBJECT parameters
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
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.
|
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
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
Parameter | Type | Description |
|---|---|---|
data | string | Error description. Check the error type before obtaining the error code. |
code | number | Error code. |
Sample code
- pay.obtainOwnedPurchaseRecord({
- ownedPurchasesRecordReq: {
- "applicationID": "101315751",
- "priceType": 2,
- "publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAnLLFO6c8d1x6jdbZ8PkNtrLtRMiFaRqWZgEjC4Vj9QXnPCmDZoPO5A5TSwzlWjYL5ktbbDnZC6Vfp8VI8nTMm8DvbGsJ+1ihru31vG1gqvUgOaXESqBhdpMrKFEgNBV8zlalLpcCU6Gayd8QJCxXRPcUisHLTQFJHjTMOWmvOcKiSxt1VmG3dvfWVkoMeKyerZy4qHEWM/asJihPZATBQ7puMC/kOh6i8V2gv4w/74KWifpBr3J5RN+PK6E7yWUqIALFTnN5vOIif2HELvgt+S6uaGpRydhSwu1xtV7bPtXQY20ollYo4BUi+AvM16iBCa1+1Mdw0y6Y9gZAtpHRK1Pf+yea4aoY4y/bZ6EX21wucvbzxexDcBkGn0DVvNHKr3usmUmq/yfMMmDPqPujv3iDWKFENfL4Agugo7I8etCF8vVYDOT5J8gXupgGLiritkfALZD8HgNZADyM+NnvQBJrdeVoHxCYoQMCS2hySPf2AaZWT7PzVAeGidLcEeKlAgMBAAE="
- },
- success: function (data) {
- console.debug("obtainOwnedPurchaseRecord data =", JSON.stringify(data));
- prompt.showToast({
- message: "obtainOwnedPurchaseRecord success!"
- })
- },
- fail: function (data, code) {
- console.log("obtainOwnedPurchaseRecord fail data =" + JSON.stringify(data), "code =" + code);
- prompt.showToast({
- message: "obtainOwnedPurchaseRecord fail!"
- })
- }
- })
Description
Displays IAP-related subscription screens.
OBJECT parameters
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
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:
|
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
Parameter | Type | Description |
|---|---|---|
data | string | Error description. Check the error type before obtaining the error code. |
code | number | Error code. |
Sample code
- pay.startIapActivity({
- startIapActivityReq: {
- "applicationID": "101315751",
- "type": 2,
- "subscribeProductId":"dy1"
- },
- success: function () {
- prompt.showToast({
- message: "startIapActivity success!"
- })
- },
- fail: function (data, code) {
- console.log("startIapActivity fail data =" + JSON.stringify(data), "code =" + code);
- prompt.showToast({
- message: "createPurchaseIntent fail!"
- })
- }
- })
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. |