This document describes only the definition of APIs. For details about how and when to call these APIs, please refer to Integrating IAP 2.0.
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. | |
Completes payment. | |
Pays for a product maintained in AppGallery Connect. | |
Obtains product details from Huawei PMS. Avoid obtaining product information from your own server. Otherwise, price information may be inconsistent between your app and the checkout page of IAP. | |
Queries information about non-consumable product orders of the current user. | |
Queries order details. All orders that call the pay API can be queried for review when orders are lost. | |
Checks whether Huawei Pay is supported. | |
Starts online payment using Huawei Pay. |
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
Completes payment.
OBJECT parameters
Parameter | Type | Mandatory | Description |
|---|---|---|---|
orderInfo | json | Yes | Order information. For details, please refer to orderInfo parameters. |
success | function | No | Callback upon success. |
fail | function | No | Callback upon failure. |
complete | function | No | Callback upon completion. |
orderInfo parameters
Parameter | Type | Mandatory | Signed | Description |
|---|---|---|---|---|
productName | string(0,50) | Yes | Yes | Product name customized by a merchant. This name will be displayed to the user for confirmation. The value cannot contain the following special characters: # " & / ? $ ^ *:) \ < > , | % + |
productDesc | string(0,100) | Yes | Yes | Product description customized by a merchant. The value cannot contain the following special characters: # " & / ? $ ^ *:) \ < > , | % + |
applicationID | string(0,100) | Yes | Yes | App ID obtained from HUAWEI Developers. |
requestId | string(0,32) | Yes | Yes | Order ID generated by the merchant. The merchant order ID is generated by your app before payment and is used as the unique identifier of one payment request. The IAP server returns the value of requestId in the server callback. This parameter contains letters and digits, and is the unique identifier of an order. |
amount | string | Yes | Yes | Product payment amount. This amount will be displayed to the user for confirmation. CAUTION:
|
merchantId | string | Yes | Yes | Merchant ID. The value is the payment ID obtained from HUAWEI Developers. |
serviceCatalog | string | Yes | No | Product type.
Set this parameter to X6 for games and X5 for apps. An incorrect product type will affect risk control. Ensure that you pass a correct product type. |
merchantName | string(0,50) | Yes | No | Merchant name. The value is the company name obtained from HUAWEI Developers. |
sdkChannel | int | Yes | Yes | Channel information. The options are as follows:
Set this parameter to 3 for games and 1 for apps. |
url | string(0,255) | No | Yes | Payment result callback URL. After Huawei server receives the value of this parameter, it checks settings of HUAWEI Developers for a callback URL defined for the app. If such a URL has been defined, the defined URL is used. Otherwise, the URL indicated by this parameter will be used as the callback URL after the payment. Note: The URL must be valid with up to 255 characters. The URL cannot end with a backslash (\) and must exclude get parameters. Examples: Correct: https://domain.com/path Incorrect: https://domain.com/path?key=value |
currency | string | No | Yes | Currency used for payment. Example: USD, CNY, or MYR, which must comply with ISO 4217. For details, please refer to ISO 4217 Currency Codes. If this parameter is not set, the default value CNY is used. |
country | string | No | Yes | Country/Region code. Example: US, CN, or MY, which must comply with ISO 3166. For details, please refer to ISO 3166 Country Codes. If this parameter is not set, the default value CN is used. |
urlver | string | No | Yes | Payment result callback version. You can leave this parameter empty, or set it to 2. If the value is not 2, the payment will fail. |
extReserved | string(0,128) | No | No | Information stored on the merchant side. The value cannot contain the following special characters: # " & / ? $ ^ *:) \ < > , | % + If this parameter has a value, the value will be returned by the callback API of Huawei IAP server. |
sign | string | Yes | No |
|
expireTime | string | No | Yes | Timeout interval of an order in your quick app. This parameter is available only for payments by scanning a QR code. Do not use this parameter. |
partnerIDs | string | No | Yes | List of payment receiving account IDs, which is a JSON array. Do not use this parameter. |
validTime | int | No | No | Order validity period in your quick app. This parameter indicates the maximum stay time of an order on the payment page, in seconds. If this validity period is exceeded, an error will occur if payment is to make, indicating that the order is invalid. After the user confirms the failure, the payment page will exit, and a result code will be returned to the app. The value of this parameter cannot be shorter than 60s (default value). Otherwise, the default value will be used. If this parameter is not passed, no validity period will be set on the IAP server. Do not use this parameter. |
publicKey | string | Yes | No | Public key, which is obtained when IAP is enabled on HUAWEI Developers. For details about how to obtain the public key, please refer to Using APIs of IAP 2.0. |
Parameters returned by success
Parameter | Type | Description |
|---|---|---|
result | string | Payment result. |
Result codes returned by fail
Parameter | Type | Description |
|---|---|---|
code | number | Status code. |
data | string | Message content. |
The failure result code varies depending on the vendor. The specific result code needs to be negotiated with the payment API of the vendor.
Sample code
pay.pay({
orderInfo: {
"amount": 0.01, // Product price.
"applicationID": "100389777", // App ID obtained from HUAWEI Developers.
"productDesc": "Product description",
"productName": "Product name",
"serviceCatalog": "X5", // Set this parameter to X6 for games and X5 for apps.
"merchantId": "900086001817", // Payment ID obtained from HUAWEI Developers.
"merchantName": "Merchant name", // Merchant name.
"sign": "xxxxxxxxxxxxxxxx", // Signature.
"requestId": "xxxxxxxxxxxxxx", // Request ID, which uniquely identifies a payment request and is generated before payment. The IAP server returns the value of requestId without change in the API callback.
"urlver": "2", // The fixed value is 2.
"sdkChannel": 1, // Set this parameter to 3 for games and 1 for apps.
"publicKey": "MIIBIjANBgkqhkiG9w0BZZJgtNpEi0wIDAQAB" // Public key, which is obtained when IAP is enabled on HUAWEI Developers.
},
success: function (ret) {
prompt.showToast({
message: "Payment result:" + JSON.stringify(ret)
})
},
fail: function (erromsg, errocode) {
prompt.showToast({
message: 'pay fail --- ' + errocode + ':' + erromsg
});
}
}) Description
Pays for a product maintained in AppGallery Connect.
OBJECT parameters
Parameter | Type | Mandatory | Signed | Description |
|---|---|---|---|---|
applicationID | string | Yes | Yes | App ID, which is the unique identifier allocated by HUAWEI Developers to an app after the app is created. |
productNo | string | Yes | Yes | PMS code of a purchased product, used to obtain product details (such as price) from PMS. Refer to getProductDetails for how product details are obtained. If a product cannot be found in PMS, the payment will fail and the value of PayResult:returnCode will be PRODUCT_NOT_EXIST (defined in PayStatusCodes). |
requestId | string | Yes | Yes | Payment order ID on the merchant side, which uniquely identifies a payment request. The payment order ID is generated by you and consists of letters and digits. It cannot contain Chinese characters and special characters including # " & / ? $ ^ * : ) \ < > , | . The payment order ID must be unique in the request. When an order is canceled or the order payment fails, the generated payment order ID cannot be reused. The IAP server returns the value of requestId without change in the API callback. |
merchantId | string | Yes | Yes | Merchant ID, which is the payment ID allocated by HUAWEI Developers to you. |
serviceCatalog | string | Yes | No | Product type. Set this parameter to X6 for games and X5 for apps. An incorrect product type will affect risk control. Ensure that you pass a correct product type. |
merchantName | string | Yes | No | Merchant name. Set this parameter to the company name configured during developer registration. |
sdkChannel | int | Yes | Yes | Channel information. Set this parameter to 3 for quick games. The options are as follows:
|
url | string | No | Yes | Payment result callback URL. After Huawei server receives the value of this parameter, it checks settings of HUAWEI Developers for a callback URL defined for the app. If such a URL has been defined, the defined URL is used. Otherwise, the URL indicated by this parameter will be used as the callback URL after the payment. CAUTION: The URL must be valid with up to 255 characters. The URL cannot end with a backslash (\) and must exclude get parameters. A multi-level domain name is supported, but the domain name cannot contain special characters such as an underscore (_). Example: Correct: https://test.sdkapp.chuangyunet.com/Pay/path Incorrect: https://test.sdk_app.chuangyunet.com/Pay/path?key=value |
urlver | string(100) | No | Yes | Payment result callback version. You can leave this parameter empty, or set it to 2. If the value is not 2, the payment will fail. |
publicKey | string(50) | Yes | No | Public key, which is obtained when IAP is enabled on HUAWEI Developers. For details about how to obtain the public key, please refer to Using APIs of IAP 2.0. |
extReserved | string(128) | No | No | Information stored on the merchant side. The value cannot contain the following special characters: # " & / ? $ ^ * : ) \ < > , | % + If this parameter has a value, the value will be returned by the callback API of Huawei IAP server. |
sign | string | Yes | No |
|
success | function | No | No | Callback upon success. |
fail | function | No | No | Callback upon failure. |
complete | function | No | No | Callback upon completion. |
Parameters returned by success
Parameter | Type | Description |
|---|---|---|
returnCode | int | Result code. |
errMsg | string | Result code description. |
merchantId | string | Merchant ID, which is the payment ID allocated by HUAWEI Developers to you. |
orderID | string | Payment order ID generated by the IAP server. |
microsAmount | long | Product price in micro unit. The value equals the real 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 | Currency. The value must comply with the ISO 4217 standard, for example, USD, CNY, and MYR. |
country | string | Country/Region code. The value must comply with the ISO 3166 standard, for example, US, CN, and MY. |
time | string | Payment completion timestamp. |
requestId | string | Payment order ID on the merchant side, which is consistent with the value of requestId in the request. |
productNo | string | ID of the purchased product. |
sign | string | Signature of the preceding data. |
Parameters returned by fail
Parameter | Type | Description |
|---|---|---|
code | number | Status code. |
data | string | Status code description. |
Sample code
productPay:function(){
pay.productPay({
"merchantId": "890086000000001051",
"applicationID": "101234327",
"requestId": this.requestid,
"productNo": "yull",
"serviceCatalog":"1",
"sdkChannel":1,
"urlver": "2", "publicKey":"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtTOTA354idE76xHbVdEMUwDaOc6UFc6l2Mz+RAbNBtdpkLWc2VJGSDLEAKjRpk5D4v2ZIZrTB1PMfiWQYIWcHMiUrKn2Eak55IyaQzg1jbBfxKE5Q4czdRUqt/2Djvyk7+nZCicQf++G1thPwLamFcgFP2dXY3R4koSRb0dyfjomnp5rJ+gZsOnLQxItoNrKpbvvVLSl73QIlzaqEv3HO5s6WPj2Zv+cP9JN2fQY6psKey7Tpys1i2N9x0BnXCviTahOvMtzV1b/5hVYKiw34l/ZugQhTpGvjFemjZQ2jkY8MgJYlqc4e17aCr2JyT2c600FB0mPXKmOf8fSLAKl9wIDAQAB",
"sign": this.sign, // Signature.
success: function (ret) {
prompt.showToast({
message: "productPay" + JSON.stringify(ret)
})
},
fail: function (erromsg, errocode) {
prompt.showToast({ message: 'productPay fail --- ' + errocode + ':' + erromsg });
}
})
}, Description
Obtains product details from Huawei PMS. 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 |
|---|---|---|---|
applicationID | string | Yes | App ID obtained from HUAWEI Developers. |
requestId | string | Yes | Request ID, which is generated by your app and used to uniquely identify a product query request. |
merchantId | string | Yes | Merchant ID, which is the payment ID allocated by HUAWEI Developers to you. |
productNos | string | Yes | ID list of products to be queried. Use vertical bars (|) to separate multiple product IDs. Up to 20 products can be queried at a time. The product ID is the same as that you configure in the product information in AppGallery Connect. For details, please refer to Creating an In-App Product. |
success | function | No | Callback upon success. |
fail | function | No | Callback upon failure. |
complete | function | No | Callback upon completion. |
Parameters returned by success
Parameter | Type | Description |
|---|---|---|
requestId | string | Product query request ID, which is the same as the value of requestId in the request. Your app can use this parameter to identify the query request to which the callback result belongs. |
productList | list<productdetail> | List of products that are queried successfully. The value is an array containing the ProductDetail object. |
failList | productfailobject | List of products that fail to be queried. The value is an array containing the ProductFailObject object. |
ProductDetail parameters
Parameter | Type | Description |
|---|---|---|
productNo | string | ID of a product that is queried successfully. |
microsPrice | long | 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). |
price | string | Displayed price of a product, including the currency unit and actual price of the product. The value is in the Currency unit Price format, for example, CNY 0.15. |
currency | string | Currency used to pay for a product. The value must comply with the ISO 4217 standard, for example, USD, CNY, and MYR. |
country | string | Country/Region code. The value must comply with the ISO 3166 standard, for example, US, CN, and MY. |
productName | string | Product name, which is set during product information configuration. |
productDesc | string | Product description, which is set during product information configuration. |
ProductFailObject parameters
Parameter | Type | Description |
|---|---|---|
productNo | string | ID of a product that fails to be queried. |
code | int | Error code for the query failure. For details, please refer to Error Codes. |
msg | string | Query failure description. |
Parameters returned by fail
Parameter | Type | Description |
|---|---|---|
code | number | Status code. |
data | string | Status code description. |
Sample code
getProductDetails:function(){
pay.getProductDetails({
"merchantId": "890086000000001051",
"applicationID": "101234327",
"requestId": "123",
"productNos": "grtyrtyr|yuFan",
success: function (ret) {
prompt.showToast({
message: "getProductDetails" + JSON.stringify(ret)
})
},
fail: function (erromsg, errocode) {
prompt.showToast({ message: 'getProductDetails fail --- ' + errocode + ':' + erromsg });
}
})
}, Description
Queries information about non-consumable product orders of the current user.
OBJECT parameters
Parameter | Type | Mandatory | Signed | Description |
|---|---|---|---|---|
merchantId | string | Yes | Yes | Merchant ID, which is the payment ID allocated by HUAWEI Developers to you. |
appId | string | Yes | Yes | App ID, which is the unique identifier allocated by HUAWEI Developers to an app after the app is created. |
priceType | string | Yes | Yes | Price type. The parameter has a fixed value of 3, which indicates non-consumables in the app. |
productId | string | No | Yes | PMS code of the purchased product. If this parameter is not passed, the information about all non-consumables is queried. |
ts | long | Yes | Yes | Timestamp, which is the number of milliseconds from 00:00:00 on January 1, 1970 to the current time. |
publicKey | string | Yes | No | Public key, which is obtained when IAP is enabled on HUAWEI Developers. For details about how to obtain the public key, please refer to Using APIs of IAP 2.0. |
pageNo | long | Yes | Yes | Number of the page for which record count is queried. By default, 100 records are queried for each page. |
sign | string | Yes | No |
|
success | function | No | No | Callback upon success. |
fail | function | No | No | Callback upon failure. |
complete | function | No | No | Callback upon completion. |
Parameters returned by success
Parameter | Type | Description |
|---|---|---|
rtnCode | string | Result code. |
pageCount | long | Number of pages. |
purchaseInfoList | list<purchaseinfo> | List of the queried non-consumable orders. |
sign | string | Signature string. |
ProductFailObject parameters
Parameter | Type | Description |
|---|---|---|
requestId | string | Order ID on the merchant side. |
merchantId | string | Merchant ID of the order. |
appId | string | App ID. |
productId | string | ID of a non-consumable. |
tradeTime | string | Payment completion time, in yyyy-MM-dd HH:mm:ss format. |
Parameters returned by fail
Parameter | Type | Description |
|---|---|---|
code | number | Status code. |
data | string | Status code description. |
Sample code
pagetPurchaseInfo:function(){
var that = this;
pay.getPurchaseInfo({
"merchantId": "890086000000001051",
"appId": "101234327",
"requestId": this.requestid,
"priceType": "3",
"productId":"yuFan",
"pageNo":1,
"ts": that.ts,
"publicKey":"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtTOTA354idE76xHbVdEMUwDaOc6UFc6l2Mz+RAbNBtdpkLWc2VJGSDLEAKjRpk5D4v2ZIZrTB1PMfiWQYIWcHMiUrKn2Eak55IyaQzg1jbBfxKE5Q4czdRUqt/2Djvyk7+nZCicQf++G1thPwLamFcgFP2dXY3R4koSRb0dyfjomnp5rJ+gZsOnLQxItoNrKpbvvVLSl73QIlzaqEv3HO5s6WPj2Zv+cP9JN2fQY6psKey7Tpys1i2N9x0BnXCviTahOvMtzV1b/5hVYKiw34l/ZugQhTpGvjFemjZQ2jkY8MgJYlqc4e17aCr2JyT2c600FB0mPXKmOf8fSLAKl9wIDAQAB",
"sign": this.sign, // Signature.
success: function (ret) {
prompt.showToast({
message: "getPurchaseInfo" + JSON.stringify(ret)
})
},
fail: function (erromsg, errocode) {
prompt.showToast({ message: 'getPurchaseInfo fail --- ' + errocode + ':' + erromsg });
}
})
}, Description
Queries order details. All orders that call the pay API can be queried for review when orders are lost.
OBJECT parameters
Parameter | Type | Mandatory | Signed | Description |
|---|---|---|---|---|
merchantId | string | Yes | Yes | Merchant ID, which is the payment ID allocated by HUAWEI Developers to you. |
requestId | string | Yes | Yes | ID of the payment order to be queried. The payment order ID is generated by your app during payment to uniquely identify a payment request. After being generated, payment order IDs are maintained by your app. CAUTION: The value cannot contain the following special characters: # " & / ? $ ^ *:) \ < > , | . Chinese characters are not supported. |
keyType | string | Yes | Yes | The fixed value is 1, which indicates the merchant key. |
time | string | Yes | Yes | Timestamp of the current time, which is the number of milliseconds from 00:00:00 on January 1, 1970 to the current time. |
publicKey | string | Yes | No | Public key, which is obtained when IAP is enabled on HUAWEI Developers. For details about how to obtain the public key, please refer to Using APIs of IAP 2.0. |
sign | string | Yes | No |
|
success | function | No | No | Callback upon success. |
fail | function | No | No | Callback upon failure. |
complete | function | No | No | Callback upon completion. |
Parameters returned by success
Parameter | Type | Mandatory | Signed | Description |
|---|---|---|---|---|
returnCode | int | Yes | Yes | Result code. For details, please refer to Error Codes. |
returnDesc | string | Yes | Yes | Result code description. |
requestId | string | No | Yes | Payment order ID generated by the app, which is consistent with the value of requestId in the request. |
orderID | string | No | Yes | Payment order ID generated by the IAP server. |
orderTime | string | No | Yes | Order placement time, in yyyy-MM-dd HH:mm:ss format. |
tradeTime | string | No | Yes | Payment time, in yyyy-MM-dd HH:mm:ss format. |
status | string | No | Yes | Payment status of an order.
|
sign | string | No | No | Signature string of the query response. |
Parameters returned by fail
Parameter | Type | Description |
|---|---|---|
code | number | Status code. |
data | string | Status code description. |
Sample code
getOrderDetail:function(){
var that = this;
pay.getOrderDetail({
"merchantId": "890086000000002287",
"keyType": "1",
"time":that.ts,
"requestId":"20191021073603003",
"publicKey":"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkMcvapcWWD7HGNV/KVF7cGE4EhhZ0J0UaHDGWPYC0w+dZdMRJOXWzeGkgsC8CMsP8H8Dqnhdhy9bH37g70OCb1pKUhfgv6UlSXE5oU6+H2TJhXRt1ZrceAKEe8+mt8eINaF1HD9EHPESz6U4+aCWUtJ0WFeevG+4FbPQ4o2Mb+LmaS+LW5NlKaTpqwnhqFsCvJ6JWSSVGBuFo2+8t0IMC5pscropffd/ySEO9s4u5HjDb76ZUHpILN5h+LcR+CfFpXNoQAPoRTSo/CvdROPpVwvS5RP3tGVYkOa05fwuxxsSF3RvuK5TUcdtnn9oKJ/ENo9hwGht9UbIJy7D3wVbuQIDAQAB",
"sign": this.sign, // Signature.
success: function (ret) {
prompt.showToast({
message: "getOrderDetail" + JSON.stringify(ret)
})
},
fail: function (erromsg, errocode) {
prompt.showToast({ message: 'getOrderDetail fail --- ' + errocode + ':' + erromsg });
}
})
} Description
Checks whether Huawei Pay is supported.
OBJECT parameters
Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
event | string | "ONLINEPAY" | No | If this parameter is not set, the value ONLINEPAY is used. |
success | function | - | Yes | Callback function used when the API is successfully called (that is, Huawei Pay is supported). |
fail | function | - | Yes | Callback function used when the API fails to be called. |
Parameters returned by fail
Parameter | Type | Description |
|---|---|---|
data | string | Error description. |
code | int | Error code. |
Sample code
pay.getWalletStatus({
event: "ONLINEPAY",
success: function (ret) {
prompt.showToast({
message: "getWalletStatus success."
})
},
fail: function (ret, code) {
prompt.showToast({
message: "getWalletStatus failed:" + JSON.stringify(ret) + "; code=" + code
})
}
}) Description
Starts online payment using Huawei Pay.
OBJECT parameters
Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
orderInfo | string | - | Yes | UnionPay order ID, which is obtained by the merchant server from the UnionPay server. |
success | function | - | Yes | Callback function when the payment is successful. |
fail | function | - | Yes | Callback function when the payment fails. |
Parameters returned by success
Parameter | Type | Description |
|---|---|---|
data | string | Payment success result description. |
Parameters returned by fail
Parameter | Type | Description |
|---|---|---|
data | string | Error description. |
code | int | Error code. |
Sample code
pay.startWalletPay({
orderInfo: "534078477796354972220",
success: function (ret) {
prompt.showToast({
message: "startWalletPay success:" + JSON.stringify(ret)
})
},
fail: function (ret, code) {
prompt.showToast({
message: "startWalletPay failed:" + JSON.stringify(ret) + "; code=" + code
})
}
})