Intelligent Assistant
Chat with our virtual assistant to get answers promptly.
This function depends on the services provided by the IAP SDK. The IAP SDK may collect personal data of players. Before using this function in a quick game, notify players that their personal data will be collected and guide them to read the corresponding privacy policy in detail.
| Applicable Device | Mobile phones and tablets |
|---|---|
| Applicable Region | Global |
| API | Description |
|---|---|
| Checks whether the country/region to which the current HUAWEI ID belongs supports Huawei IAP. | |
| Checks whether the HUAWEI ID and the quick game RPK version meet the sandbox testing requirements. | |
| Queries the data of a user's purchased products, including consumables and non-consumables. | |
| Queries the details of a product configured in AppGallery Connect. | |
| Creates orders for purchasing products (consumables and non-consumables) configured in AppGallery Connect. | |
| Consumes a consumable that has been successfully purchased. |
Checks whether the country/region to which the current HUAWEI ID belongs supports IAP.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| isEnvReadyReq | json | Yes | Indicates whether requests from Huawei IAP are supported. For details, please refer to Parameters in isEnvReadyReq. |
| success | function | No | Callback function triggered upon a successful API call. For details, please refer to Parameters in the success callback function. |
| fail | function | No | Callback function triggered upon a failed API call. For details, please refer to Parameters in the fail callback function. |
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| applicationID | string | Yes | Unique ID allocated to a created quick game. For details about how to obtain the app ID, please refer to Obtaining the App ID. |
| Parameter | Type | Description |
|---|---|---|
| returnCode | number | Return code. If the current user's HUAWEI ID supports IAP, the return code is 0. |
| Parameter | Type | Description |
|---|---|---|
| data | string | Result message. |
| code | number |
- qg.isEnvReady({
- isEnvReadyReq: {
- // Replace it with a valid app ID.
- "applicationID": "101***751"
- },
- success: function (data) {
- console.log("isEnvReady data =", JSON.stringify(data));
- },
- fail: function (data, code) {
- console.log("isEnvReady fail data =" + data, "code =" + code);
- }
- })
Checks whether the signed-in HUAWEI ID and quick game RPK version meet the sandbox testing requirements.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| isSandboxActivatedReq | json | Yes | Indicates whether the signed-in HUAWEI ID meets the sandbox testing requirements. For details, please refer to Parameters in isSandboxActivatedReq. |
| success | function | No | Callback function triggered upon a successful API call. For details, please refer to Parameters in the success callback function. |
| fail | function | No | Callback function triggered upon a failed API call. For details, please refer to Parameters in the fail callback function. |
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| applicationID | string | Yes | Unique ID allocated to a created quick game. For details about how to obtain the app ID, please refer to Obtaining the App ID. |
| Parameter | Type | Description |
|---|---|---|
| returnCode | number | Return code. |
| errMsg | string | Return code description. |
| isSandboxUser | boolean | Indicates whether a sandbox account is used. |
| isSandboxApk | boolean | Indicates whether the APK version of a quick game client, such as Quick App Center or Petal Lite Games, meets the sandbox testing requirements. The value is always true. |
| versionInApk | string | Version information of a quick game client. |
| versionFrMarket | string | Latest quick game version information on AppGallery. |
| Parameter | Type | Description |
|---|---|---|
| data | string | Result message. |
| code | number |
- qg.isSandboxActivated({
- isSandboxActivatedReq: {
- // Replace it with a valid app ID.
- "applicationID": "101***751",
- },
- success: function (data) {
- console.log("isSandboxActivated data =", JSON.stringify(data));
- },
- fail: function (data, code) {
- console.log("isSandboxActivated fail data =" + JSON.stringify(data), "code =" + code);
- }
- })
Queries the data of a user's purchased products. Only one type of product can be obtained per API call.
| Type of Product to Be Queried | Return Result |
|---|---|
| Consumable | Data of the purchased but not consumed products. In this case, you need to:
|
| Non-consumable | Data of all products purchased by a user. |
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| ownedPurchasesReq | json | Yes | Queries data of the purchased but not consumed products. For details, please refer to Parameters in ownedPurchasesReq. |
| success | function | No | Callback function triggered upon a successful API call. For details, please refer to Parameters in the success callback function. |
| fail | function | No | Callback function triggered upon a failed API call. For details, please refer to Parameters in the fail callback function. |
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| applicationID | string | Yes | Unique ID allocated to a created quick game. For details about how to obtain the app ID, please refer to Obtaining the App ID. |
| priceType | number | Yes | Product type.
|
| publicKey | string | Yes | Public key obtained when you enable the IAP service. For details, please refer to Obtaining the Payment Public Key. |
| continuationToken | string | No | Data continuation token. This parameter is not required for the first request. |
| Parameter | Type | Description |
|---|---|---|
| returnCode | number | Return code. |
| errMsg | string | Return code description. |
| itemList | array | Product ID list. |
| inAppPurchaseDataList | array | Product information list. For details about each product, please refer to Parameters in inAppPurchaseData. NOTICE Set the minimum platform version number minPlatformVersion in the manifest file to a value greater than or equal to 1103. If the platform version number is greater than or equal to 1078, the data returned in the array is a JSON string. If the platform version number is lower than 1078, the data returned in the array is of the object type. |
| inAppSignature | array | Signature string corresponding to each product in inAppPurchaseDataList.
|
| continuationToken | string | Data continuation token. If a user has a large number of products and continuationToken is returned, the app must continue to call this method and pass the current continuationToken until continuationToken is not returned. |
| Parameter | Type | Description |
|---|---|---|
| data | string | Result message. |
| code | number |
- qg.obtainOwnedPurchases({
- ownedPurchasesReq: {
- "priceType": 0,
- // Replace it with a valid app ID.
- "applicationID": "101***751",
- // Replace it with a valid payment public key.
- "publicKey": "MIIBojANBgkqhkiG9w0BAQ**********************GidLcEeKlAgMBAAE"
- },
- success: function (data) {
- console.log("obtainOwnedPurchases data =", JSON.stringify(data));
- },
- fail: function (data, code) {
- console.log("obtainOwnedPurchases fail data =" + data, "code =" + code);
- }
- })
Queries the details of a product configured in AppGallery Connect. If you use Huawei's Product Management System (PMS) to set product prices, you can call this API to obtain product details from the PMS. This ensures that the product information, such as prices, displayed in your app is consistent with what users see on the Huawei Pay checkout page, preventing any discrepancies between the two.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| productInfoReq | json | Yes | Request for obtaining product information. For details, please refer to Parameters in productInfoReq. |
| success | function | No | Callback function triggered upon a successful API call. For details, please refer to Parameters in the success callback function. |
| fail | function | No | Callback function triggered upon a failed API call. For details, please refer to Parameters in the fail callback function. |
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| applicationID | string | Yes | Unique ID allocated to a created quick game. For details about how to obtain the app ID, please refer to Obtaining the App ID. |
| priceType | number | Yes | Product type.
|
| productIds | array | Yes | Product ID list. |
| Parameter | Type | Description |
|---|---|---|
| returnCode | number | Return code. |
| errMsg | string | Return code description. |
| productInfoList | array | Product details. For details, please refer to Parameters in productInfo. |
| Parameter | Type | Description |
|---|---|---|
| productId | string | Product ID. |
| priceType | number | Product type.
|
| price | string | Displayed price of a product (tax included). The format is Currency Price, for example, EUR 0.15. In some countries/regions, the format is Currency symbolPrice, for example, ¥0.15 in the Chinese mainland. NOTE If a promotional price has been set for a product, the promotional price will be returned. |
| microsPrice | number | Product price in micro unit. 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 US$1.99, the product price in micro unit is 1,990,000 (1.99 x 1,000,000). |
| currency | string | Currency in which a product is purchased. |
| productName | string | Product name. |
| productDesc | string | Product description. |
| originalMicroPrice | string | Original product price in micro unit. Product price in micro unit, which equals the original product price multiplied by 1,000,000. For example, if the original price of a product is US$1.99, the product price in micro unit is 1,990,000 (1.99 x 1,000,000). |
| originalLocalPrice | string | Original price of a product (tax included). The format is Currency Price, for example, EUR 0.15. In some countries/regions, the format is Currency symbolPrice, for example, ¥0.15 in the Chinese mainland. |
| Parameter | Type | Description |
|---|---|---|
| data | string | Result message. |
| code | number |
- qg.obtainProductInfo({
- productInfoReq: {
- "priceType": 1,
- "productIds": ["dy1","dmy00","lcole"],
- // Replace it with a valid app ID.
- "applicationID": "101***751",
- },
- success: function (data) {
- console.log("obtainProductInfo =" + JSON.stringify(data));
-
- },
- fail: function (data, code) {
- console.log("obtainProductInfo fail data =" + JSON.stringify(data), "code =" + code);
-
- }
- })
Opens the Huawei Pay checkout page to display the product, price, and payment method after the product is created in AppGallery Connect. Huawei can adjust product prices as foreign exchange rates change. To ensure product price consistency, call obtainProductInfo to retrieve product details. Avoid fetching prices from your own server to prevent discrepancies when prices are adjusted due to exchange rate changes.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| purchaseIntentReq | json | Yes | Request information for initiating an in-app purchase. For details, please refer to Parameters in purchaseIntentReq. |
| success | function | No | Callback function triggered upon a successful API call. For details, please refer to Parameters in the success callback function. |
| fail | function | No | Callback function triggered upon a failed API call. For details, please refer to Parameters in the fail callback function. |
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| applicationID | string | Yes | Unique ID allocated to a created quick game. For details about how to obtain the app ID, please refer to Obtaining the App ID. |
| publicKey | string | Yes | Public key obtained when you enable the IAP service. For details, please refer to Obtaining the Payment Public Key. |
| productId | string | Yes | ID of the product pending payment. |
| priceType | number | Yes | Product type.
|
| developerPayload | string | No | Merchant-side reserved information. The length range is [0,256]. If a value is passed, it will be returned to the app in the callback triggered when the payment is successful. |
| Parameter | Type | Description |
|---|---|---|
| returnCode | number | Return code. |
| errMsg | string | Return code description. |
| inAppDataSignature | string | Signature string generated using the private key for the purchased product. The signing algorithm used is SHA256withRSA. After the payment is successful, use the payment public key to verify the signature of the purchase data. For details about the signature verification method, please refer to Verifying the Result Returned by the Quick Game Engine. |
| inAppPurchaseData | string | Purchase order details. For details, please refer to Parameters in inAppPurchaseData. |
| Parameter | Type | Description |
|---|---|---|
| applicationId | number | App ID. |
| autoRenewing | boolean | Indicates whether a subscription is set to auto-renew. The value is always false. |
| orderId | string | Order ID in Huawei Pay, which is generated after the payment is successful. |
| kind | number | Product type.
|
| packageName | string | Client package name. |
| productId | string | Product ID. |
| productName | string | Product name. |
| purchaseTime | number | Product purchase timestamp. Number of milliseconds from 00:00:00 on January 1, 1970 to the time when the product was purchased. |
| purchaseState | number | Transaction status.
|
| developerPayload | string | Merchant-side reserved information, which is passed when the API is called. |
| developerChallenge | string | Challenge defined when an app requests to consume a product, which uniquely identifies the consumption request. After the consumption is successful, the challenge is recorded in the purchase information and returned. If the challenge is the same as an existing one, it indicates a repeated consumption request. In this case, the same challenge will be returned unchanged. |
| consumptionState | number | Consumption status.
|
| purchaseToken | string | Purchase token containing 92 characters, which identifies the mapping between a product and a user. It is generated by the Huawei IAP server when the payment is complete. If the value needs to be stored, you are advised to reserve 128 characters. |
| purchaseType | number | Purchase type.
NOTE This parameter is not returned during normal purchases. |
| currency | string | Currency in which a product is purchased. For the Chinese mainland, the value is CNY. For other countries/regions, please refer to Supported Countries/Regions. |
| price | number | Displayed price of a product. |
| country | string | Country/Region code. For the Chinese mainland, the value is CN. For other countries/regions, please refer to Supported Countries/Regions. |
| payType | string | Payment method.
|
| Parameter | Type | Description |
|---|---|---|
| data | string | Result message. |
| code | number |
- qg.createPurchaseIntent({
- purchaseIntentReq: {
- // Replace it with a valid app ID.
- "applicationID": "101***751",
- "productId": "dmy001",
- "priceType": 0,
- "developerPayload": "testPurchase",
- // Replace it with a valid payment public key.
- "publicKey": "MIIBojANBgkqhkiG***********************T7PzVAeGidLcEeKlAgMBAAE"
- },
- success: function (data) {
- that.inAppPurchaseData = data;
- console.log("createPurchaseIntent success =" + JSON.stringify(data));
- },
- fail: function (data, code) {
- console.log("createPurchaseIntent fail data =" + data, "code =" + code);
- }
- })
Consumes a consumable after it is successfully delivered. You need to send the purchase token of the delivered product to your server. Even if the consumption fails, you can obtain data from your server for comparison.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| consumeOwnedPurchaseReq | json | Yes | Request for consuming a product. For details, please refer to Parameters in consumeOwnedPurchaseReq. |
| success | function | No | Callback function triggered upon a successful API call. For details, please refer to Parameters in the success callback function. |
| fail | function | No | Callback function triggered upon a failed API call. For details, please refer to Parameters in the fail callback function. |
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| applicationID | string | Yes | Unique ID allocated to a created quick game. For details about how to obtain the app ID, please refer to Obtaining the App ID. |
| developerChallenge | string | No | Challenge defined when an app requests to consume a product. After the consumption is successful, the challenge is recorded in the purchase information and returned. The value contains a maximum of 64 characters. If the challenge is the same as an existing one, it indicates a repeated consumption request. In this case, the same challenge will be returned unchanged. |
| purchaseToken | string | Yes | ID of a product purchased by a user. This parameter is generated by the IAP server, included in Parameters in inAppPurchaseData, and returned to the app. After the IAP server updates the order status, the product is delivered. |
| publicKey | string | Yes | Public key obtained when you enable the IAP service. For details, please refer to Obtaining the Payment Public Key. |
| Parameter | Type | Description |
|---|---|---|
| returnCode | number | Return code. |
| errMsg | string | Return code description. |
| consumePurchaseData | string | Consumption result. For details, please refer to Parameters in consumePurchaseData. |
| dataSignature | string | Signature string generated using the IAP private key. |
| Parameter | Type | Description |
|---|---|---|
| applicationId | number | Unique ID allocated to a created quick game. |
| autoRenewing | boolean | Indicates whether a subscription is set to auto-renew. The value is always false. |
| orderId | string | Order ID in Huawei Pay, which is generated after the payment is successful. |
| packageName | string | Client package name. |
| productId | string | Product ID. |
| purchaseTime | number | Product purchase timestamp. Number of milliseconds from 00:00:00 on January 1, 1970 to the time when the product was purchased. |
| purchaseState | number | Order status.
|
| developerPayload | string | Merchant-side reserved information, which is passed when the API is called. |
| purchaseToken | string | Purchase token, which uniquely identifies the mapping between a product and a user. It is generated by the Huawei IAP server when the payment is complete. |
| developerChallenge | string | Challenge defined when an app requests to consume a product, which uniquely identifies the consumption request. After the consumption is successful, the challenge is recorded in the purchase information and returned. If the challenge is the same as an existing one, it indicates a repeated consumption request. In this case, the same challenge will be returned unchanged. |
| consumptionState | number | Consumption status.
|
| currency | string | Currency in which a product is purchased. |
| price | number | Displayed price of a product (tax included). The format is Currency Price, for example, EUR 0.15. In some countries/regions, the format is Currency symbolPrice, for example, ¥0.15 in the Chinese mainland. |
| country | string | Country/Region code. For the Chinese mainland, the value is CN. For other countries/regions, please refer to Supported Countries/Regions. |
| responseCode | string | Return code. Value 0 indicates success. |
| responseMessage | string | Return code description. |
| Parameter | Type | Description |
|---|---|---|
| data | string | Result message. |
| code | number |
- qg.consumeOwnedPurchase({
- consumeOwnedPurchaseReq: {
- // Replace it with a valid app ID.
- "applicationID": "101***751",
- "developerPayload": "testPurchase",
- // Replace it with a valid purchase token.
- "purchaseToken": "0000017297d6a4f*****************e3d0x434e.1.101315751",
- // Replace it with a valid payment public key.
- "publicKey": "MIIBojANBgkqhkiG9w***********************0BAQZWT7PzVAeGidLcEeKlAgMBAAE"
- },
- success: function (data) {
- console.log("consumeOwnedPurchase data =", JSON.stringify(data));
- },
- fail: function (data, code) {
- console.log("consumeOwnedPurchase fail data =" + JSON.stringify(data), "code =" + code);
- }
- })
For more result codes, please refer to Result Codes.
| Result Code | Description |
|---|---|
| 200 | Common error. |
| 202 | The input parameter is incorrect. |
| 1002 | Failed to authenticate the app. |
| 1001 | Failed to verify the public key. |
- isEnvReady() {
- console.log("isEnvReady start");
- let that = this;
- qg.isEnvReady({
- isEnvReadyReq: {
- "applicationID": "102107863",
- },
- success: function (data) {
- console.log("isEnvReady data =", JSON.stringify(data));
- that.obtainOwnedPurchases();
- that.obtainConsumeProductInfo();
- that.payForConsable();
- },
- fail: function (data, code) {
- console.log("isEnvReady fail data =" + JSON.stringify(data), "code =" + code);
- }
- });
- },
-
- obtainOwnedPurchases(token) {
- console.log("obtainOwnedPurchases token=" + token);
- var that = this;
- qg.obtainOwnedPurchases({
- ownedPurchasesReq: {
- "applicationID": "102107863",
- "priceType": 0,
- continuationToken: token,
- // Payment public key generated when you enable IAP on HUAWEI Developers.
- "publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAhK0+5cD+BBG5vPS3loMtpjidjDSau3U5Bxtm2ecR3DV1WVBAIDU3Vmn45mWS8Ww9zMWKPmyAF1w0/tkIV6hZimnKA5pMB3+nYXwHSABxrvD9KxPTF287M4y3zgHNtN/Zky0E3KF68L2C4ik8ToQHzwNMdPTM1SVkzhaDrhZV3WgkpFk7CnpPGhd6Tee5Bz10ZtjS+FFPOPZXekNoTHOrnF+BBpd6TWYV2tAzLWCH0gySgSg/SUMS/MCx8yTJuDtwkYmwLZa8+4vehwq+ANx7qncIrjo6aH3B2vxECXeVKJUnWzDEMVyfl6nZ/FDMjdisPW4OXHwegY9rvK2YTJd8h1h4IozuJ5R8JUKFEaGJmZ9KJJxV+NQvtNEwfa8rZ0CX6BlXhkYxaiGFIrHW3siLYxn7LpjBNKgKHnuNuuzWZb5WVEKmYHixpBReK6XSmybx8t+yddhaCe1kQC93b3kLyr9ulO79QffZdTFwl1a2fRFDSAIAPteeG8S+MG7iACz7AgMBAAE=",// Payment public key obtained when you enable IAP on HUAWEI Developers.
- },
- success: function (data) {
- that.parseOwnedPurchases(data);
- },
- fail: function (data, code) {
- console.log("obtainOwnedPurchases fail data =" + JSON.stringify(data), "code =" + code);
- }
- });
- },
-
- parseOwnedPurchases(data) {
- console.log("parseOwnedPurchases data =", JSON.stringify(data));
- var that = this;
- let purseDataArray = data.inAppPurchaseDataList; //jsonString array
- console.log("parseOwnedPurchases purseDataArray =", JSON.stringify(purseDataArray));
-
- let purseDataSignArray = data.inAppSignature;
- if (purseDataArray) {
- for (var j = 0, len = purseDataArray.length; j < len; j++) {
- // console.log("inAppPurchaseData[j]" + JSON.stringify(inAppPurchaseDataList[j]))
- // console.log("obtainOwnedPurchases data.inAppSignature=" + data.inAppSignature)
- // console.log("obtainOwnedPurchases publicKey" + publicKey)
- var purchaseState = JSON.parse(purseDataArray[j]).purchaseState;
- var purchaseToken = JSON.parse(purseDataArray[j]).purchaseToken;
- console.log("purchaseState" + purchaseState);
- console.log("purchaseToken" + purchaseToken);
- //console.log(purchaseState)
- // Verify the signature of product details before the delivery.
- // You can send a verification request to the Huawei IAP server to further verify the order.
- that.checkSign(purseDataArray[j], data.inAppSignature,JSON.parse(purseDataArray[j]).purchaseToken);
- }
- }
- if (data.continuationToken) {
- console.log("parseOwnedPurchases data.continuationToken");
- that.obtainOwnedPurchases(data.continuationToken);
- }
- },
-
- obtainConsumeProductInfo() {
- var that = this;
- qg.obtainProductInfo({
- productInfoReq: {
- "applicationID": "102107863",
- "priceType": 1,
- "productIds": "2022112302",
- "publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAhK0+5cD+BBG5vPS3loMtpjidjDSau3U5Bxtm2ecR3DV1WVBAIDU3Vmn45mWS8Ww9zMWKPmyAF1w0/tkIV6hZimnKA5pMB3+nYXwHSABxrvD9KxPTF287M4y3zgHNtN/Zky0E3KF68L2C4ik8ToQHzwNMdPTM1SVkzhaDrhZV3WgkpFk7CnpPGhd6Tee5Bz10ZtjS+FFPOPZXekNoTHOrnF+BBpd6TWYV2tAzLWCH0gySgSg/SUMS/MCx8yTJuDtwkYmwLZa8+4vehwq+ANx7qncIrjo6aH3B2vxECXeVKJUnWzDEMVyfl6nZ/FDMjdisPW4OXHwegY9rvK2YTJd8h1h4IozuJ5R8JUKFEaGJmZ9KJJxV+NQvtNEwfa8rZ0CX6BlXhkYxaiGFIrHW3siLYxn7LpjBNKgKHnuNuuzWZb5WVEKmYHixpBReK6XSmybx8t+yddhaCe1kQC93b3kLyr9ulO79QffZdTFwl1a2fRFDSAIAPteeG8S+MG7iACz7AgMBAAE=",// Payment public key obtained when you enable IAP on HUAWEI Developers.
- },
- success: function (data) {
- console.log("obtainProductInfo =" + JSON.stringify(data));
- },
- fail: function (data, code) {
- console.log("obtainProductInfo fail data =" + JSON.stringify(data), "code =" + code);
- }
- });
- },
-
- checkSign(signData, signStr, token) {
- console.log("checkSign sign signContent=" + signData + ", token=" + token);
- console.log("checkSign sign =" + signStr);
- // Verify the purchase result signature. For convenience, set result to true.
- let result = true;
- if (result) {
- let purchaseState = JSON.parse(signData).purchaseState;
- this.confirmTransct(token, purchaseState);
- }
- },
-
- confirmTransct(token, purchaseState) {
- console.log("confirmTransct:token:" + token);
- console.log("confirmTransct: purchaseState:" + purchaseState);
- // Check whether the order has been successfully paid based on the purchaseState field in inAppPurchaseData. After the payment is successful, the corresponding offering or service is provided, and the delivery confirmation request is sent to Huawei IAP.
- if (purchaseState !== 0) {
- return;
- }
- // Consume a consumable after it is delivered to a user who has completed payment.
- qg.consumeOwnedPurchase({
- consumeOwnedPurchaseReq: {
- "purchaseToken": token,
- "applicationID": "102107863",
- "publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAhK0+5cD+BBG5vPS3loMtpjidjDSau3U5Bxtm2ecR3DV1WVBAIDU3Vmn45mWS8Ww9zMWKPmyAF1w0/tkIV6hZimnKA5pMB3+nYXwHSABxrvD9KxPTF287M4y3zgHNtN/Zky0E3KF68L2C4ik8ToQHzwNMdPTM1SVkzhaDrhZV3WgkpFk7CnpPGhd6Tee5Bz10ZtjS+FFPOPZXekNoTHOrnF+BBpd6TWYV2tAzLWCH0gySgSg/SUMS/MCx8yTJuDtwkYmwLZa8+4vehwq+ANx7qncIrjo6aH3B2vxECXeVKJUnWzDEMVyfl6nZ/FDMjdisPW4OXHwegY9rvK2YTJd8h1h4IozuJ5R8JUKFEaGJmZ9KJJxV+NQvtNEwfa8rZ0CX6BlXhkYxaiGFIrHW3siLYxn7LpjBNKgKHnuNuuzWZb5WVEKmYHixpBReK6XSmybx8t+yddhaCe1kQC93b3kLyr9ulO79QffZdTFwl1a2fRFDSAIAPteeG8S+MG7iACz7AgMBAAE=",// Payment public key obtained when you enable IAP on HUAWEI Developers.
- },
- success: function (data) {
- console.log("consumeOwnedPurchase data =", JSON.stringify(data));
- },
- fail: function (data, code) {
- console.log("consumeOwnedPurchase fail data =" + JSON.stringify(data), "code =" + code);
- }
- });
- },
-
- payForConsable() {
- var that = this;
- qg.createPurchaseIntent({
- purchaseIntentReq: {
- "applicationID": "102107863",
- "priceType": 0,
- "productId": "2022112801",
- "publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAhK0+5cD+BBG5vPS3loMtpjidjDSau3U5Bxtm2ecR3DV1WVBAIDU3Vmn45mWS8Ww9zMWKPmyAF1w0/tkIV6hZimnKA5pMB3+nYXwHSABxrvD9KxPTF287M4y3zgHNtN/Zky0E3KF68L2C4ik8ToQHzwNMdPTM1SVkzhaDrhZV3WgkpFk7CnpPGhd6Tee5Bz10ZtjS+FFPOPZXekNoTHOrnF+BBpd6TWYV2tAzLWCH0gySgSg/SUMS/MCx8yTJuDtwkYmwLZa8+4vehwq+ANx7qncIrjo6aH3B2vxECXeVKJUnWzDEMVyfl6nZ/FDMjdisPW4OXHwegY9rvK2YTJd8h1h4IozuJ5R8JUKFEaGJmZ9KJJxV+NQvtNEwfa8rZ0CX6BlXhkYxaiGFIrHW3siLYxn7LpjBNKgKHnuNuuzWZb5WVEKmYHixpBReK6XSmybx8t+yddhaCe1kQC93b3kLyr9ulO79QffZdTFwl1a2fRFDSAIAPteeG8S+MG7iACz7AgMBAAE=",// Payment public key obtained when you enable IAP on HUAWEI Developers.
- },
- success: function (data) {
- that.inAppPurchaseData = data.inAppPurchaseData;
- console.log("createPurchaseIntent success =" + JSON.stringify(data));
- var sign = data.inAppDataSignature;
- let signData = data.inAppPurchaseData;
- let type = typeof signData;
- console.log("createPurchaseIntent type= " + type);
- let token = JSON.parse(JSON.stringify(signData)).purchaseToken;
- console.log("createPurchaseIntent token= " + token);
- that.checkSign(JSON.stringify(signData), sign, token);
- },
- fail: function (data, code) {
- console.log("createPurchaseIntent fail data =" + JSON.stringify(data), "code =" + code);
- if (code === 60051 || code === -1) {
- // If the information about consumables is returned, the consumables might not be delivered due to some exceptions.
- // In this case, your app needs to check whether the consumables are delivered. If not, the app needs to deliver
- // them and call the pay.consumeOwnedPurchase API to consume them.
- that.obtainOwnedPurchases();
- }
- }
- });
- },
- isEnvReady() {
- console.log("isEnvReady start");
- let that = this;
- qg.isEnvReady({
- isEnvReadyReq: {
- "applicationID": "102107863",
- },
- success: function (data) {
- console.log("isEnvReady data =", JSON.stringify(data));
- that.payForNonConsable();
- },
- fail: function (data, code) {
- console.log("isEnvReady fail data =" + JSON.stringify(data), "code =" + code);
- }
- });
- },
-
- payForNonConsable() {
- let that = this;
- qg.createPurchaseIntent({
- purchaseIntentReq: {
- "applicationID": "102107863",
- "priceType": 1,
- "productId": "2022112302",
- "publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAhK0+5cD+BBG5vPS3loMtpjidjDSau3U5Bxtm2ecR3DV1WVBAIDU3Vmn45mWS8Ww9zMWKPmyAF1w0/tkIV6hZimnKA5pMB3+nYXwHSABxrvD9KxPTF287M4y3zgHNtN/Zky0E3KF68L2C4ik8ToQHzwNMdPTM1SVkzhaDrhZV3WgkpFk7CnpPGhd6Tee5Bz10ZtjS+FFPOPZXekNoTHOrnF+BBpd6TWYV2tAzLWCH0gySgSg/SUMS/MCx8yTJuDtwkYmwLZa8+4vehwq+ANx7qncIrjo6aH3B2vxECXeVKJUnWzDEMVyfl6nZ/FDMjdisPW4OXHwegY9rvK2YTJd8h1h4IozuJ5R8JUKFEaGJmZ9KJJxV+NQvtNEwfa8rZ0CX6BlXhkYxaiGFIrHW3siLYxn7LpjBNKgKHnuNuuzWZb5WVEKmYHixpBReK6XSmybx8t+yddhaCe1kQC93b3kLyr9ulO79QffZdTFwl1a2fRFDSAIAPteeG8S+MG7iACz7AgMBAAE=",// Payment public key obtained when you enable IAP on HUAWEI Developers.
- },
- success: function (data) {
- console.log("payForNonConsable createPurchaseIntent success =" + JSON.stringify(data));
- var sign = data.inAppDataSignature;
- let signData = data.inAppPurchaseData;
- let token = JSON.parse(JSON.stringify(signData)).purchaseToken;
- this.checkSign(JSON.stringify(signData), sign, token);
- },
- fail: function (data, code) {
- console.log("payForNonConsable createPurchaseIntent fail data =" + JSON.stringify(data), "code =" + code);
- if (code === 60051 || code === -1) {
- that.obtainOwnedPurchases();
- }
- }
- });
- },
-
- checkSign(signData, signStr, token) {
- console.log("checkSign sign signContent=" + signData + ", token=" + token);
- console.log("checkSign sign =" + signStr);
- // Set this result to true for convenience here.
- let result = true;
- if (result) {
- // After a payment is complete, the developer needs to determine whether the order has been successfully paid
- // based on the purchaseState field in inAppPurchaseData.After the payment is successful,
- // the corresponding offering or service is provided, and the delivery confirmation request is sent to Huawei IAP.
- let purchaseState = JSON.parse(signData).purchaseState;
- this.confirmTransct(token, purchaseState);
- }
- },
-
- confirmTransct(token, purchaseState) {
- console.log("confirmTransct:token:" + token);
- console.log("confirmTransct: purchaseState:" + purchaseState);
- if (purchaseState == 0) {
- console.log("You have purchased it and can use it permanently. You do not need to purchase it again.");
- }
- },
-
- obtainOwnedPurchases(ptype, token) {
- console.log("obtainOwnedPurchases ptype=" + ptype + ", token=" + token);
- var that = this;
- qg.obtainOwnedPurchases({
- ownedPurchasesReq: {
- "applicationID": "102107863",
- "priceType": 1,
- continuationToken: token,
- // Payment public key generated when you enable IAP on HUAWEI Developers.
- "publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAhK0+5cD+BBG5vPS3loMtpjidjDSau3U5Bxtm2ecR3DV1WVBAIDU3Vmn45mWS8Ww9zMWKPmyAF1w0/tkIV6hZimnKA5pMB3+nYXwHSABxrvD9KxPTF287M4y3zgHNtN/Zky0E3KF68L2C4ik8ToQHzwNMdPTM1SVkzhaDrhZV3WgkpFk7CnpPGhd6Tee5Bz10ZtjS+FFPOPZXekNoTHOrnF+BBpd6TWYV2tAzLWCH0gySgSg/SUMS/MCx8yTJuDtwkYmwLZa8+4vehwq+ANx7qncIrjo6aH3B2vxECXeVKJUnWzDEMVyfl6nZ/FDMjdisPW4OXHwegY9rvK2YTJd8h1h4IozuJ5R8JUKFEaGJmZ9KJJxV+NQvtNEwfa8rZ0CX6BlXhkYxaiGFIrHW3siLYxn7LpjBNKgKHnuNuuzWZb5WVEKmYHixpBReK6XSmybx8t+yddhaCe1kQC93b3kLyr9ulO79QffZdTFwl1a2fRFDSAIAPteeG8S+MG7iACz7AgMBAAE=",// Payment public key obtained when you enable IAP on HUAWEI Developers.
- },
- success: function (data) {
- that.parseOwnedPurchases(ptype, data);
- },
- fail: function (data, code) {
- console.log("obtainOwnedPurchases fail data =" + JSON.stringify(data), "code =" + code);
- }
- });
- },
-
- parseOwnedPurchases(ptype, data) {
- console.log("parseOwnedPurchases data =", JSON.stringify(data));
- let purseDataArray = data.inAppPurchaseDataList; //jsonString array
-
- let purseDataSignArray = data.inAppSignature;
- if (purseDataArray) {
- for (var j = 0, len = purseDataArray.length; j < len; j++) {
- // console.log("inAppPurchaseData[j]" + JSON.stringify(inAppPurchaseDataList[j]))
- // console.log("obtainOwnedPurchases data.inAppSignature=" + data.inAppSignature)
- // console.log("obtainOwnedPurchases publicKey" + publicKey)
- var purchaseState = JSON.parse(purseDataArray[j]).purchaseState;
- var purchaseToken = JSON.parse(purseDataArray[j]).purchaseToken;
- console.log("purchaseState" + purchaseState);
- console.log("purchaseToken" + purchaseToken);
- //console.log(purchaseState)
- // Verify the signature of product details before the delivery.
- // You can send a verification request to the Huawei IAP server to further verify the order.
- that.checkSign(purseDataArray[j], data.inAppSignature,JSON.parse(purseDataArray[j]).purchaseToken);
- }
- }
- if (data.continuationToken) {
- this.obtainOwnedPurchases(ptype, data.continuationToken);
- }
- },