| API | Description |
|---|---|
| Checks whether the country/region to which the current HUAWEI ID belongs supports Huawei IAP. | |
| Obtains the result indicating whether Huawei IAP is supported. | |
| Checks whether the current HUAWEI ID and the quick game RPK version meet the sandbox testing requirements. | |
| Obtains the result indicating whether the sandbox testing requirements are met. | |
| Queries the details of a user's purchased products, including consumables and non-consumables. | |
| Obtains the details of a user's purchased products. | |
| Queries the details of a product configured in AppGallery Connect. | |
| Obtains the details of a product configured in AppGallery Connect. | |
| Creates orders for purchasing products (consumables and non-consumables) configured in AppGallery Connect. | |
| Obtains the order details of a purchased product. | |
| Consumes a consumable that has been successfully purchased. | |
| Obtains the result of consuming a consumable. |
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. |
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| applicationID | String | Yes | Unique ID allocated to a created quick game. For details, please refer to Obtaining the App ID. |
Obtains the result indicating whether Huawei IAP is supported.
| Parameter | Type | Description |
|---|---|---|
| code | Number | Return code. Code 0 indicates success. |
| data | String | Return code description. |
function isEnvReady (){
var params = {isEnvReadyReq: {"applicationID": "101***1"}}
HwFastappObject.isEnvReady(JSON.stringify(params));
}
HwFastappObject.onIsEnvReadyResult = function onIsEnvReadyResult (str){
alert("onIsEnvReadyResult:"+JSON.stringify(str));
var text = document.getElementById("text");
text.innerHTML = JSON.stringify(str);
}Checks whether the current HUAWEI ID and the 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. |
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| applicationID | String | Yes | Unique ID allocated to a created quick game. For details, please refer to Obtaining the App ID. |
Obtains the result indicating whether the sandbox testing requirements are met.
| Parameter | Type | Description |
|---|---|---|
| code | Number | Return code. If the value is 0, please refer to Parameters in the success callback function. |
| data | String | Return code description. |
| Parameter | Type | Description |
|---|---|---|
| returnCode | Number | Return code of the query result. |
| 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. 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. |
function isSandboxActivated (){
var params = {isSandboxActivatedReq: {"applicationID": "101315751",}}
HwFastappObject.isSandboxActivated(JSON.stringify(params));
}
HwFastappObject.onIsSandboxActivatedResult = function onIsSandboxActivatedResult (str){
alert("onIsSandboxActivatedResult:"+JSON.stringify(str));
var text = document.getElementById("text");
text.innerHTML = JSON.stringify(str);
}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 | Information about all purchased products that are not consumed. For details, please refer to Parameters in ownedPurchasesReq. |
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| applicationID | String | Yes | Unique ID allocated to a created quick game. For details, please refer to Obtaining the App ID. |
| priceType | Number | Yes | Product type.
|
| publicKey | String | Yes | Payment public key obtained when IAP is enabled. For details, please refer to Obtaining the Payment Public Key. |
| continuationToken | String | No | Data location flag for a query in pagination mode. This parameter is not required for the initial query. If there is a large amount of data requiring multiple queries, pass the value of continuationToken returned in the success response from the previous query. |
| Parameter | Type | Description |
|---|---|---|
| code | Number | Result code.
|
| data | String | Result code description. |
| Parameter | Type | Description |
|---|---|---|
| returnCode | Number | Return code of the query result. |
| errMsg | String | Result code description. |
| itemList | Array | ID list of products purchased by a user, which is returned as a string array. |
| inAppPurchaseDataList | Array | Details list of products purchased by a user, which is returned as a string array. Each string element in the array is in JSON format. For details, please refer to Parameters in inAppPurchaseData. CAUTION: 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 of 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 Result Returned by the Quick Game Engine. |
| continuationToken | String | Data continuation token. 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. |
| Parameter | Type | Description |
|---|---|---|
| data | Object | Result message. |
| code | Number |
function obtainOwnedPurchases() {
var priceType = document.getElementById('priceType')
var params = {
ownedPurchasesReq: {
priceType: priceType.value,
applicationID: '101***1',
publicKey: 'MIIBojANBgkqhkiG9w0BAQEFAAO****gMBAAE='
}
}
HwFastappObject.obtainOwnedPurchases(JSON.stringify(params))
}
HwFastappObject.onObtainOwnedPurchasesResult = function onObtainOwnedPurchasesResult(str) {
alert('onObtainOwnedPurchasesResult:' + JSON.stringify(str))
var appData = JSON.parse(str.data)
inAppPurchaseData = appData.inAppPurchaseDataList
var text = document.getElementById('text')
alert('obtainOwnedPurchases inAppPurchaseData:' + JSON.stringify(inAppPurchaseData))
text.innerHTML = JSON.stringify(str)
}Queries the details of a product configured in AppGallery Connect. If you use 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 details. For details, please refer to Parameters in productInfoReq. |
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| applicationID | String | Yes | Unique ID allocated to a created quick game. For details, please refer to Obtaining the App ID. |
| priceType | Number | Yes | Product type.
|
| productIds | Array | Yes | Product ID. |
Obtains the details of a product configured in AppGallery Connect.
| Parameter | Type | Description |
|---|---|---|
| code | Number | Result code.
|
| data | String | Result code description. |
| Parameter | Type | Description |
|---|---|---|
| returnCode | Number | Return code of the query result. |
| errMsg | String | Result code description. |
| productInfoList | Array | List of products that are successfully found. For details, please refer to Parameters in productInfo. |
| 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 US$1.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 meet 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. |
| originalMicroPrice | String | No | Original price in micro unit of a product. The price equals the original product price multiplied by 1,000,000. |
| originalLocalPrice | String | No | Original product price, including the currency unit and actual price of a product. The value is in the Currency symbolPrice format, for example, ¥0.15. The price includes the tax. |
| Parameter | Type | Description |
|---|---|---|
| data | Object | Result message. |
| code | Number |
function obtainProductInfo() {
var priceType = document.getElementById('priceType')
var productId = document.getElementById('productId')
var params = {
productInfoReq: { priceType: priceType.value, productIds: productId.value, applicationID: '101315751' }
}
HwFastappObject.obtainProductInfo(JSON.stringify(params))
}
HwFastappObject.onObtainProductInfoResult = function onObtainProductInfoResult(str) {
alert('onObtainProductInfoResult:' + JSON.stringify(str))
var text = document.getElementById('text')
text.innerHTML = JSON.stringify(str)
}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. Obtaining prices from your own server is not advised. Otherwise, there may be price inconsistency when prices are adjusted due to exchange rate changes.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| purchaseIntentReq | JSON | Yes | Request for purchasing a product. For details, please refer to Parameters in purchaseIntentReq. |
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| applicationID | String | Yes | Unique ID allocated to a created quick game. For details, please refer to Obtaining the App ID. |
| publicKey | String | Yes | Payment public key obtained when IAP is enabled. For details, please refer to Obtaining the Payment Public Key. |
| productId | String | Yes | ID of a product to be paid for. 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 | Merchant-side reserved information. If a value exists, the value will be returned in the callback result to the app after successful payment. |
| Parameter | Type | Description |
|---|---|---|
| code | Number | Result code.
|
| data | String | Result code description. |
| Parameter | Type | Description |
|---|---|---|
| returnCode | Number | Return code. |
| errMsg | String | Return code description. |
| inAppDataSignature | String | Signature string of 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 inAppPurchaseData JSON string using the payment public key. For details, please refer to Verifying the Result Returned by the Quick Game Engine. |
| inAppPurchaseData | String | JSON string of purchase order details. For details, please refer to Parameters in inAppPurchaseData. |
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| applicationId | String | Yes | App ID. |
| autoRenewing | Boolean | Yes | Indicates whether a subscription is set to auto-renew. The value is always false. |
| orderId | String | No | Order ID from the Huawei IAP server, which uniquely identifies a transaction and is generated by the Huawei IAP server during payment. |
| kind | Number | Yes | Product type.
|
| packageName | String | No | Package name in Quick App Center. |
| productId | String | Yes | Product ID. Each product must have a unique ID, which is maintained in the PMS. |
| productName | String | No | Product name. |
| purchaseTime | String | No | Purchase timestamp of a product, which is the number of milliseconds from 00:00:00 on January 1, 1970 to the purchase time. |
| purchaseState | String | Yes | Transaction status.
|
| developerPayload | String | No | Merchant-side reserved information, which you pass when calling the payment API. |
| developerChallenge | String | No | Challenge defined when an app initiates a consumption request, which uniquely identifies the consumption request. |
| consumptionState | String | No | Consumption status.
|
| purchaseToken | String | No | 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. NOTE: This parameter uniquely identifies the mapping between a product and a user. The value currently contains 92 characters and may be expanded in the future. If the value needs to be stored, you are advised to reserve 128 characters. |
| purchaseType | Number | No | Purchase type. This parameter is not returned for normal purchase.
|
| currency | String | No | Pricing currency. The value must comply with the ISO 4217 standard. |
| price | Number | No | 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.
|
| Parameter | Type | Description |
|---|---|---|
| data | Object | Result message. |
| code | Number |
function createPurchaseIntent() {
var priceType = document.getElementById('priceType')
var productId = document.getElementById('productId')
var params = {
purchaseIntentReq: {
// Replace it with a valid app ID.
applicationID: '101***751',
productId: productId.value,
priceType: priceType.value,
developerPayload: 'testPurchase',
// Replace it with a valid payment public key.
publicKey:'MIIBojANBgk*****************************************************cEeKlAgMBAAE='
}
}
HwFastappObject.createPurchaseIntent(JSON.stringify(params))
}
HwFastappObject.onCreatePurchaseIntentResult = function onCreatePurchaseIntentResult(str) {
alert('onCreatePurchaseIntentResult:' + JSON.stringify(str))
var text = document.getElementById('text')
text.innerHTML = JSON.stringify(str)
}Consumes a consumable after it is successfully delivered. You need to send the purchase token of the delivered product to your server. In this way, even if the consumption fails, you can obtain data from your server for comparison, thus preventing exceptions.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| consumeOwnedPurchaseReq | JSON | Yes | Request for consuming a product. For details, please refer to Parameters in consumeOwnedPurchaseReq. |
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| applicationID | String | Yes | Unique ID allocated to a created quick game. For details, 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 range is (0,64). |
| purchaseToken | String | Yes | Purchase token, which is generated by the Huawei IAP server during payment and returned to the app through InAppPurchaseData. The app passes this parameter for the Huawei IAP server to update the order status and then deliver the product. |
| publicKey | String | Yes | Payment public key obtained when IAP is enabled. For details, please refer to Obtaining the Payment Public Key. |
| Parameter | Type | Description |
|---|---|---|
| code | Number | Result code.
|
| data | String | Result code description. |
| Parameter | Type | Description |
|---|---|---|
| returnCode | Number | Return code. |
| errMsg | String | Return code description. |
| consumePurchaseData | String | Consumption result data. For details, please refer to Parameters in consumePurchaseData. |
| dataSignature | String | Signature string signed using the payment private key. |
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| applicationId | String | Yes | Unique ID allocated to a created quick game. For details, please refer to Obtaining the App ID. |
| autoRenewing | Boolean | Yes | Indicates whether a subscription is set to auto-renew. The value is always false. |
| orderId | String | Yes | Order ID from the Huawei IAP server, which uniquely identifies a transaction and is generated by the Huawei IAP server during payment. |
| packageName | String | Yes | Package name in Quick App Center. |
| productId | String | Yes | Product ID. |
| purchaseTime | Number | Yes | Purchase timestamp of a product, which is the number of milliseconds from 00:00:00 on January 1, 1970 to the purchase time. |
| purchaseState | Number | Yes | Order status.
|
| developerPayload | String | No | Merchant-side reserved information, which is passed by the app during payment. |
| purchaseToken | String | Yes | 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 | 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 | Product price, which is 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 meet the ISO 3166 standard, for example, US, CN, and MY. |
| responseCode | String | Yes | Result code. Value 0 indicates success. |
| responseMessage | String | No | Response message. |
| Parameter | Type | Description |
|---|---|---|
| data | Object | Result message. |
| code | Number |
function consumeOwnedPurchase() {
// inAppPurchaseData is inAppPurchaseDataList returned by HwFastappObject.onObtainOwnedPurchasesResult.
if (inAppPurchaseData) {
for (j = 0, len = inAppPurchaseData.length; j < len; j++) {
var purchaseToken = JSON.parse(inAppPurchaseData[j]).purchaseToken
var params = {
consumeOwnedPurchaseReq: {
"applicationID": "100***021", "developerPayload": "testPurchase", "purchaseToken": purchaseToken,
"publicKey": "MIIBojANBgkq**************************************Y0ePClRherT7LYuiA7AgMBAAE="
}
}
HwFastappObject.consumeOwnedPurchase(JSON.stringify(params));
}
}
}
HwFastappObject.onConsumeOwnedPurchaseResult = function onConsumeOwnedPurchaseResult(str) {
if (str.code === 0) {
console.log("Consume success")
return
}
if (str.code === 60053) {
console.log("Goods have been consumed and cannot be consumed again")
} else {
console.log("Consume fail")
}
}<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title id="title">Consumables</title>
<script type="text/javascript">
var success = -1;
var inAppPurchaseData = ""
var purchaseState = ""
function callandroid() {
console.log("GX showFloatWindow ");
var params = { "appid": "100798021" }
HwFastappObject.showFloatWindow(JSON.stringify(params));
}
function callandroid1() {
console.log("GX hideFloatWindow ");
var params = { "appid": "100798021" }
HwFastappObject.hideFloatWindow(JSON.stringify(params));
}
function GamesignIn() {
var params = { "appid": "100798021", "forceLogin": 1 }
HwFastappObject.gameLogin(JSON.stringify(params));
}
HwFastappObject.onGameLoginResult = function onGameLoginResult(str) {
if (str.code == 0) {
success = 0;
console.log("GX game login success" + JSON.stringify(str))
}
var text = document.getElementById("text");
//text.innerHTML = JSON.stringify(str);
//text.innerHTML = JSON.stringify(str);
//alert("onGameLoginResult"+JSON.stringify(str))
}
function isEnvReady() {
var params = { isEnvReadyReq: { "applicationID": "100798021" } }
HwFastappObject.isEnvReady(JSON.stringify(params));
}
HwFastappObject.onIsEnvReadyResult = function onIsEnvReadyResult(str) {
//var text = document.getElementById("text");
//text.innerHTML = JSON.stringify(str);
//text.innerHTML = str;
console.log("GX", "onIsEnvReadyResult =" + JSON.stringify(str));
//alert("onIsEnvReadyResult:"+JSON.stringify(str));
}
function isSandboxActivated() {
var params = { isSandboxActivatedReq: { "applicationID": "100798021", } }
HwFastappObject.isSandboxActivated(JSON.stringify(params));
}
HwFastappObject.onIsSandboxActivatedResult = function onIsSandboxActivatedResult(str) {
//alert("onIsSandboxActivatedResult:"+JSON.stringify(str));
//var text = document.getElementById("text");
//text.innerHTML = JSON.stringify(str);
//text.innerHTML = JSON.stringify(str);
console.log("GX", "onIsSandboxActivatedResult =" + JSON.stringify(str));
}
//
function obtainOwnedPurchases() {
var priceType = document.getElementById("priceType")
var params = {
ownedPurchasesReq: {
"priceType": 0, "applicationID": "100798021",
"publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAkDhrGKHUDGDqGfKTcfHmpiPdPuZocwF7tl0UAuBsHSqdStm8OQX5bYkxrpTqF64gLn8dON60WRjAqbz1t/vO0jbvLWX/n3rvONIfbk4J4skgXBVPoe69XXgaOzT02/wnAE6aINgMz4ez9PZ3ValbtIAdvJ9qS2fb18B+OEw8kfWt5H4vWbBCdTIj0OlkAA4BsTNo6jY7gVfacCDD2y+MbPagFcR7pspQW53pBZCQ+cov1bQFEnf1ay5SFN7PRCruf8Wuqd6PJci4Zsz5YzRWi7eWn+M+uRyg+8NjiBPKL1xhK1yUtu+vg9W0jy4GdX4fzyVxAa31utMNpqL9M/tiVlnegY70GW46U6d1+c0aIuq5kSfN6smhgDx+UxDeCgAxF6mgIneSb5q9gQf0feFqcMx1nNAL1JkXSt51+f8C2OjRioOmyR566ahQvZLjGRY7F2F1XACAIhg/WPqNBMtrzHh3mOvNHOgz9MQBB4wbZQWveHY0ePClRherT7LYuiA7AgMBAAE="
}
}
HwFastappObject.obtainOwnedPurchases(JSON.stringify(params));
}
HwFastappObject.onObtainOwnedPurchasesResult = function onObtainOwnedPurchasesResult(str) {
//alert("onObtainOwnedPurchasesResult:"+JSON.stringify(str));
console.log(JSON.stringify(str))
//The purchaseState field needs to be parsed from the string of InAppPurchaseData,
//and when purchaseState is 0, the transaction is successful
var appData = JSON.parse(str.data)
inAppPurchaseData = appData.inAppPurchaseDataList //array
let purseDataSignArray = appData.inAppSignature;
let publicKey = "XXX"
if (inAppPurchaseData) {
for (j = 0, len = inAppPurchaseData.length; j < len; j++) {
var purchaseState = JSON.parse(inAppPurchaseData[j]).purchaseState
//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.
doCheckSign(purchaseState, inAppPurchaseData[j], purseDataSignArray[j], publicKey);
}
}
}
function doCheckSign(purchaseState, inAppPurchaseData, inAppSignature, publicKey) {
// to do your quick game's server,Set this result to true for convenience here
let result = true;
if (result) {
doCheckPurchaseState(purchaseState);
}
}
function doCheckPurchaseState(purchaseState) {
//pay success
if (purchaseState === 0) {
console.log("Consumeables have been successfully paid without having to purchase them again.")
consumeOwnedPurchase();
return
}
//pay fail
if (purchaseState === 1 || purchaseState === 2) {
console.log("The transaction has been cancelled or refunded")
return
}
}
function obtainProductInfo() {
var priceType = document.getElementById("priceType")
var productId = document.getElementById("productId")
var params = { productInfoReq: { "priceType": 0, "productIds": "Product1", "applicationID": "100798021", } }
HwFastappObject.obtainProductInfo(JSON.stringify(params));
}
HwFastappObject.onObtainProductInfoResult = function onObtainProductInfoResult(str) {
//alert("onObtainProductInfoResult:"+JSON.stringify(str));
//var text = document.getElementById("text");
//text.innerHTML = JSON.stringify(str);
//text.innerHTML = str;
console.log("GX", "onObtainProductInfoResult =" + JSON.stringify(str));
}
function createPurchaseIntent() {
var params = {
purchaseIntentReq: {
"applicationID": "100798021", "productId": "Product1", "priceType": 0, "developerPayload": "testPurchase",
"publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAkDhrGKHUDGDqGfKTcfHmpiPdPuZocwF7tl0UAuBsHSqdStm8OQX5bYkxrpTqF64gLn8dON60WRjAqbz1t/vO0jbvLWX/n3rvONIfbk4J4skgXBVPoe69XXgaOzT02/wnAE6aINgMz4ez9PZ3ValbtIAdvJ9qS2fb18B+OEw8kfWt5H4vWbBCdTIj0OlkAA4BsTNo6jY7gVfacCDD2y+MbPagFcR7pspQW53pBZCQ+cov1bQFEnf1ay5SFN7PRCruf8Wuqd6PJci4Zsz5YzRWi7eWn+M+uRyg+8NjiBPKL1xhK1yUtu+vg9W0jy4GdX4fzyVxAa31utMNpqL9M/tiVlnegY70GW46U6d1+c0aIuq5kSfN6smhgDx+UxDeCgAxF6mgIneSb5q9gQf0feFqcMx1nNAL1JkXSt51+f8C2OjRioOmyR566ahQvZLjGRY7F2F1XACAIhg/WPqNBMtrzHh3mOvNHOgz9MQBB4wbZQWveHY0ePClRherT7LYuiA7AgMBAAE="
}
}
HwFastappObject.createPurchaseIntent(JSON.stringify(params));
}
function createPurchaseIntent1() {
var params = {
purchaseIntentReq: {
"applicationID": "100798021", "productId": "Product4", "priceType": 0, "developerPayload": "testPurchase",
"publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAkDhrGKHUDGDqGfKTcfHmpiPdPuZocwF7tl0UAuBsHSqdStm8OQX5bYkxrpTqF64gLn8dON60WRjAqbz1t/vO0jbvLWX/n3rvONIfbk4J4skgXBVPoe69XXgaOzT02/wnAE6aINgMz4ez9PZ3ValbtIAdvJ9qS2fb18B+OEw8kfWt5H4vWbBCdTIj0OlkAA4BsTNo6jY7gVfacCDD2y+MbPagFcR7pspQW53pBZCQ+cov1bQFEnf1ay5SFN7PRCruf8Wuqd6PJci4Zsz5YzRWi7eWn+M+uRyg+8NjiBPKL1xhK1yUtu+vg9W0jy4GdX4fzyVxAa31utMNpqL9M/tiVlnegY70GW46U6d1+c0aIuq5kSfN6smhgDx+UxDeCgAxF6mgIneSb5q9gQf0feFqcMx1nNAL1JkXSt51+f8C2OjRioOmyR566ahQvZLjGRY7F2F1XACAIhg/WPqNBMtrzHh3mOvNHOgz9MQBB4wbZQWveHY0ePClRherT7LYuiA7AgMBAAE="
}
}
HwFastappObject.createPurchaseIntent(JSON.stringify(params));
}
HwFastappObject.onCreatePurchaseIntentResult = function onCreatePurchaseIntentResult(str) {
// var text = document.getElementById("text");
// text.innerHTML = JSON.stringify(str);
console.log("GX", "onCreatePurchaseIntentResult =" + JSON.stringify(str));
if (str.code === 0) {
console.log("GX pay success")
obtainOwnedPurchases();
}
if (str.code === 60051 || str.code === -1) {
obtainOwnedPurchases();
}
}
function consumeOwnedPurchase() {
console.log(inAppPurchaseData)
if (inAppPurchaseData) {
for (j = 0, len = inAppPurchaseData.length; j < len; j++) {
var purchaseToken = JSON.parse(inAppPurchaseData[j]).purchaseToken
var params = {
consumeOwnedPurchaseReq: {
"applicationID": "100798021", "developerPayload": "testPurchase", "purchaseToken": purchaseToken,
"publicKey": "MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAkDhrGKHUDGDqGfKTcfHmpiPdPuZocwF7tl0UAuBsHSqdStm8OQX5bYkxrpTqF64gLn8dON60WRjAqbz1t/vO0jbvLWX/n3rvONIfbk4J4skgXBVPoe69XXgaOzT02/wnAE6aINgMz4ez9PZ3ValbtIAdvJ9qS2fb18B+OEw8kfWt5H4vWbBCdTIj0OlkAA4BsTNo6jY7gVfacCDD2y+MbPagFcR7pspQW53pBZCQ+cov1bQFEnf1ay5SFN7PRCruf8Wuqd6PJci4Zsz5YzRWi7eWn+M+uRyg+8NjiBPKL1xhK1yUtu+vg9W0jy4GdX4fzyVxAa31utMNpqL9M/tiVlnegY70GW46U6d1+c0aIuq5kSfN6smhgDx+UxDeCgAxF6mgIneSb5q9gQf0feFqcMx1nNAL1JkXSt51+f8C2OjRioOmyR566ahQvZLjGRY7F2F1XACAIhg/WPqNBMtrzHh3mOvNHOgz9MQBB4wbZQWveHY0ePClRherT7LYuiA7AgMBAAE="
}
}
HwFastappObject.consumeOwnedPurchase(JSON.stringify(params));
}
}
}
HwFastappObject.onConsumeOwnedPurchaseResult = function onConsumeOwnedPurchaseResult(str) {
console.log("GX", "onConsumeOwnedPurchaseResult =" + JSON.stringify(str));
if (str.code === 0) {
console.log("Consume success")
return
}
if (str.code === 60053) {
console.log("Goods have been consumed and cannot be consumed again")
} else {
console.log("Consume fail")
}
}
function formateTime(time) {
if (time) {
let unixTimestamp = new Date(time);
return unixTimestamp.toLocaleString();
}
}
function Back() {
window.location.href = "index.html";
}
</script>
</head>
<body>
<p>Consumables</p>
<style>
#text {
border: 1px solid #00F;
width: 200px;
word-wrap: break-word
}
input {
font-size: 40px;
width: 800px;
height: 60px;
text-align: center;
background: #5255fc;
color: #FFF;
line-height: 60px;
margin-left: auto;
margin-right: auto
}
p {
font-size: 80px;
width: 1080px;
height: 100px;
text-align: center
}
.container {
text-align: center;
margin-left: auto;
}
</style>
<div class="container">
<input type="button" id="button3" value="Buy Some" onclick="createPurchaseIntent()" /></br></br>
<input type="button" id="button3" value="Buy More" onclick="createPurchaseIntent1()" /></br></br>
<input type="button" value="Back" onclick="Back()" /> </br></br>
</div>
<li id="li" style="list-style-type:none"></li>
</div>
</body>
</html> <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title id="title">NonConsumables</title>
<script type="text/javascript">
var success = -1;
var inAppPurchaseData = ""
var purchaseState= ""
function callandroid(){
console.log("GX showFloatWindow ");
var params = {"appid":"100798021"}
HwFastappObject.showFloatWindow(JSON.stringify(params));
}
function callandroid1(){
console.log("GX hideFloatWindow ");
var params = {"appid":"100798021"}
HwFastappObject.hideFloatWindow(JSON.stringify(params));
}
function GamesignIn(){
var params = {"appid":"100798021","forceLogin":1}
HwFastappObject.gameLogin(JSON.stringify(params));
}
HwFastappObject.onGameLoginResult = function onGameLoginResult(str){
if (str.code == 0) {
success = 0;
console.log("GX game login success"+JSON.stringify(str))
}
var text = document.getElementById("text");
//text.innerHTML = JSON.stringify(str);
//text.innerHTML = JSON.stringify(str);
//alert("onGameLoginResult"+JSON.stringify(str))
}
function isEnvReady (){
var params = {isEnvReadyReq: {"applicationID": "100798021"}}
HwFastappObject.isEnvReady(JSON.stringify(params));
}
HwFastappObject.onIsEnvReadyResult = function onIsEnvReadyResult (str){
//var text = document.getElementById("text");
//text.innerHTML = JSON.stringify(str);
//text.innerHTML = str;
console.log("GX","onIsEnvReadyResult ="+JSON.stringify(str));
//alert("onIsEnvReadyResult:"+JSON.stringify(str));
}
function isSandboxActivated (){
var params = {isSandboxActivatedReq: {"applicationID": "100798021",}}
HwFastappObject.isSandboxActivated(JSON.stringify(params));
}
HwFastappObject.onIsSandboxActivatedResult = function onIsSandboxActivatedResult (str){
//alert("onIsSandboxActivatedResult:"+JSON.stringify(str));
//var text = document.getElementById("text");
//text.innerHTML = JSON.stringify(str);
//text.innerHTML = JSON.stringify(str);
console.log("GX","onIsSandboxActivatedResult ="+JSON.stringify(str));
}
//
function obtainOwnedPurchases (){
var priceType = document.getElementById("priceType")
var params = { ownedPurchasesReq: {"priceType": 1,"applicationID": "100798021",
"publicKey":"MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAkDhrGKHUDGDqGfKTcfHmpiPdPuZocwF7tl0UAuBsHSqdStm8OQX5bYkxrpTqF64gLn8dON60WRjAqbz1t/vO0jbvLWX/n3rvONIfbk4J4skgXBVPoe69XXgaOzT02/wnAE6aINgMz4ez9PZ3ValbtIAdvJ9qS2fb18B+OEw8kfWt5H4vWbBCdTIj0OlkAA4BsTNo6jY7gVfacCDD2y+MbPagFcR7pspQW53pBZCQ+cov1bQFEnf1ay5SFN7PRCruf8Wuqd6PJci4Zsz5YzRWi7eWn+M+uRyg+8NjiBPKL1xhK1yUtu+vg9W0jy4GdX4fzyVxAa31utMNpqL9M/tiVlnegY70GW46U6d1+c0aIuq5kSfN6smhgDx+UxDeCgAxF6mgIneSb5q9gQf0feFqcMx1nNAL1JkXSt51+f8C2OjRioOmyR566ahQvZLjGRY7F2F1XACAIhg/WPqNBMtrzHh3mOvNHOgz9MQBB4wbZQWveHY0ePClRherT7LYuiA7AgMBAAE="}}
HwFastappObject.obtainOwnedPurchases(JSON.stringify(params));
}
HwFastappObject.onObtainOwnedPurchasesResult = function onObtainOwnedPurchasesResult (str){
//alert("onObtainOwnedPurchasesResult:"+JSON.stringify(str));
console.log(JSON.stringify(str))
// Parse the purchaseState field from the InAppPurchaseData string. If the value of purchaseState is 0, the transaction is successful.
var appData = JSON.parse(str.data)
inAppPurchaseData = appData.inAppPurchaseDataList //array
let purseDataSignArray = appData.inAppSignature;
let publicKey="XXX"
//text.innerHTML = str1;
console.log("GX","onObtainOwnedPurchasesResult =inAppPurchaseDataList"+JSON.stringify(inAppPurchaseData));
var strdata=""
if(inAppPurchaseData){
for(j = 0,len=inAppPurchaseData.length; j < len; j++) {
var purchaseState=JSON.parse(inAppPurchaseData[j]).purchaseState
doCheckSign(inAppPurchaseData[j], purseDataSignArray[j], publicKey);
doCheckPurchaseState(purchaseState);
console.log("OrderId"+JSON.parse(inAppPurchaseData[j]).orderId)
console.log("PurchaseTime"+formateTime(JSON.parse(inAppPurchaseData[j]).purchaseTime))
console.log("ProductId"+JSON.parse(inAppPurchaseData[j]).productId)
console.log("ProductName"+JSON.parse(inAppPurchaseData[j]).productName)
console.log("Price"+JSON.parse(inAppPurchaseData[j]).price/100)
console.log("PurchaseState"+JSON.parse(inAppPurchaseData[j]).purchaseState)
if(purchaseState===0){
console.log("Purchased")
}else{
console.log("Purchase Failure")
}
var a = JSON.parse(inAppPurchaseData[j]).orderId;
var b = formateTime(JSON.parse(inAppPurchaseData[j]).purchaseTime);
var c = JSON.parse(inAppPurchaseData[j]).productId;
var d = JSON.parse(inAppPurchaseData[j]).productName;
var e = JSON.parse(inAppPurchaseData[j]).price/100;
var f= JSON.parse(inAppPurchaseData[j]).purchaseState;
var g
if(f===0){
g="Purchased"
}else{
g="Purchase Failure"
}
strdata+='<li style="font-size:40px;text-align:left;background:#5255fc;color: #FFFFFF;line-height:60px;margin-left:auto; margin-right:auto">'+"Order ID: "+a+'</br>'+"Purchase time: "+b+'</br>'+"Product ID: "+c+'</br>'+"Product name:"+d+'</br>'+"Product price: "+e+"RMB"+'</br>'+"Purchase status: "+g+'</br>'+'</li>'+'</br>'+'</br>'+'</br>'
}
}
document.getElementById('li').innerHTML = strdata
}
function doCheckPurchaseState(purchaseState){
//alert(purchaseState)
if(purchaseState===0){
console.log("Subscription goods have been successfully paid without having to purchase them again.")
//consumeOwnedPurchase();
return
}
if(purchaseState===1||purchaseState===2){
console.log("The transaction has been cancelled or refunded")
return
}
}
function doCheckSign(inAppPurchaseData, inAppSignature, publicKey) {
}
function obtainProductInfo (){
var priceType = document.getElementById("priceType")
var productId = document.getElementById("productId")
var params = { productInfoReq: {"priceType": 1,"productIds": "Product2","applicationID": "100798021",}}
HwFastappObject.obtainProductInfo(JSON.stringify(params));
}
HwFastappObject.onObtainProductInfoResult = function onObtainProductInfoResult (str){
//alert("onObtainProductInfoResult:"+JSON.stringify(str));
//var text = document.getElementById("text");
//text.innerHTML = JSON.stringify(str);
//text.innerHTML = str;
console.log("GX","onObtainProductInfoResult ="+JSON.stringify(str));
}
function createPurchaseIntent (){
var params = { purchaseIntentReq: {"applicationID": "100798021","productId": "Product2","priceType": 1,"developerPayload": "testPurchase1",
"publicKey":"MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAkDhrGKHUDGDqGfKTcfHmpiPdPuZocwF7tl0UAuBsHSqdStm8OQX5bYkxrpTqF64gLn8dON60WRjAqbz1t/vO0jbvLWX/n3rvONIfbk4J4skgXBVPoe69XXgaOzT02/wnAE6aINgMz4ez9PZ3ValbtIAdvJ9qS2fb18B+OEw8kfWt5H4vWbBCdTIj0OlkAA4BsTNo6jY7gVfacCDD2y+MbPagFcR7pspQW53pBZCQ+cov1bQFEnf1ay5SFN7PRCruf8Wuqd6PJci4Zsz5YzRWi7eWn+M+uRyg+8NjiBPKL1xhK1yUtu+vg9W0jy4GdX4fzyVxAa31utMNpqL9M/tiVlnegY70GW46U6d1+c0aIuq5kSfN6smhgDx+UxDeCgAxF6mgIneSb5q9gQf0feFqcMx1nNAL1JkXSt51+f8C2OjRioOmyR566ahQvZLjGRY7F2F1XACAIhg/WPqNBMtrzHh3mOvNHOgz9MQBB4wbZQWveHY0ePClRherT7LYuiA7AgMBAAE="}}
HwFastappObject.createPurchaseIntent(JSON.stringify(params));
}
function createPurchaseIntent1 (){
var params = { purchaseIntentReq: {"applicationID": "100798021","productId": "Product5","priceType": 1,"developerPayload": "testPurchase1",
"publicKey":"MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAkDhrGKHUDGDqGfKTcfHmpiPdPuZocwF7tl0UAuBsHSqdStm8OQX5bYkxrpTqF64gLn8dON60WRjAqbz1t/vO0jbvLWX/n3rvONIfbk4J4skgXBVPoe69XXgaOzT02/wnAE6aINgMz4ez9PZ3ValbtIAdvJ9qS2fb18B+OEw8kfWt5H4vWbBCdTIj0OlkAA4BsTNo6jY7gVfacCDD2y+MbPagFcR7pspQW53pBZCQ+cov1bQFEnf1ay5SFN7PRCruf8Wuqd6PJci4Zsz5YzRWi7eWn+M+uRyg+8NjiBPKL1xhK1yUtu+vg9W0jy4GdX4fzyVxAa31utMNpqL9M/tiVlnegY70GW46U6d1+c0aIuq5kSfN6smhgDx+UxDeCgAxF6mgIneSb5q9gQf0feFqcMx1nNAL1JkXSt51+f8C2OjRioOmyR566ahQvZLjGRY7F2F1XACAIhg/WPqNBMtrzHh3mOvNHOgz9MQBB4wbZQWveHY0ePClRherT7LYuiA7AgMBAAE="}}
HwFastappObject.createPurchaseIntent(JSON.stringify(params));
}
HwFastappObject.onCreatePurchaseIntentResult = function onCreatePurchaseIntentResult (str){
// var text = document.getElementById("text");
// text.innerHTML = JSON.stringify(str);
console.log("GX","onCreatePurchaseIntentResult ="+JSON.stringify(str));
if (str.code ===0){
console.log("Pay success")
}
if(str.code===60051||str.code===-1){
alert("You have purchased it and can use it permanently. You do not need to purchase it again.")
}
}
function consumeOwnedPurchase (){
//alert("purchaseToken"+JSON.parse(inAppPurchaseData).purchaseToken)
var purchaseToken=JSON.parse(inAppPurchaseData).purchaseToken
var params = { consumeOwnedPurchaseReq: {"applicationID": "100798021","developerPayload":"testPurchase","purchaseToken":purchaseToken,
"publicKey":"MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAkDhrGKHUDGDqGfKTcfHmpiPdPuZocwF7tl0UAuBsHSqdStm8OQX5bYkxrpTqF64gLn8dON60WRjAqbz1t/vO0jbvLWX/n3rvONIfbk4J4skgXBVPoe69XXgaOzT02/wnAE6aINgMz4ez9PZ3ValbtIAdvJ9qS2fb18B+OEw8kfWt5H4vWbBCdTIj0OlkAA4BsTNo6jY7gVfacCDD2y+MbPagFcR7pspQW53pBZCQ+cov1bQFEnf1ay5SFN7PRCruf8Wuqd6PJci4Zsz5YzRWi7eWn+M+uRyg+8NjiBPKL1xhK1yUtu+vg9W0jy4GdX4fzyVxAa31utMNpqL9M/tiVlnegY70GW46U6d1+c0aIuq5kSfN6smhgDx+UxDeCgAxF6mgIneSb5q9gQf0feFqcMx1nNAL1JkXSt51+f8C2OjRioOmyR566ahQvZLjGRY7F2F1XACAIhg/WPqNBMtrzHh3mOvNHOgz9MQBB4wbZQWveHY0ePClRherT7LYuiA7AgMBAAE="}}
HwFastappObject.consumeOwnedPurchase(JSON.stringify(params));
}
HwFastappObject.onConsumeOwnedPurchaseResult = function onConsumeOwnedPurchaseResult (str){
// alert("onConsumeOwnedPurchaseResult :"+JSON.stringify(str));
// var text = document.getElementById("text");
// text.innerHTML = JSON.stringify(str);
console.log("GX","onConsumeOwnedPurchaseResult ="+JSON.stringify(str));
if(str.code ===0){
console.log("Consume success")
return
}
if(str.code ===60053){
console.log("Goods have been consumed and cannot be consumed again")
}
}
function formateTime(time) {
if (time) {
let unixTimestamp = new Date(time);
return unixTimestamp.toLocaleString();
}
}
function Back(){
window.location.href="index.html";
}
</script>
</head>
<body>
<p>NonConsumables</p>
<style>
#text{ border:1px solid #00F; width:200px;word-wrap:break-word}
input {font-size:40px;width:800px;height:60px;text-align:center;background:#5255fc;color: #FFF;line-height:60px;margin-left:auto; margin-right:auto}
p{font-size:80px;width:1080px;height:100px;text-align:center}
.container{text-align:center;margin-left: auto;}
</style>
<div class="container">
<input type="button" id="button3" value="Permanent VIP Purchase" onclick="createPurchaseIntent()"/></br></br>
<input type="button" id="button3" value="Permanent Skin Purchase" onclick="createPurchaseIntent1()"/></br></br>
<input type="button" id="button3" value="PurchaseRecord" onclick="obtainOwnedPurchases()"/></br></br>
<input type="button" value="Back" onclick="Back()" /> </br></br>
</div>
<li id="li" style="list-style-type:none"></li>
<!-- <div type="text" id="text" style="font-size:40px;width:1080px;height:1660px">test</div> -->
</div>
</body>
</html> 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. |