[Huawei Developers] Mike-mei:
HMS Core In-App Purchases can be easily integrated into apps to provide a high quality in-app payment experience for users. However, some developers may find that the payment screen of In-App Purchases cannot be opened normally. In this article, I will explain possible causes for this and provide solutions.

Scenario 1: In-App Purchases has been enabled on the Manage APIs page in AppGallery Connect, and the created product has taken effect. However, error code 60002 is recorded in logs.

View attachment 5749115

Cause analysis

The payment public key is required for verifying the SHA256WithRSA signature of the In-App Purchases result. However, the developer has not configured a payment public key.

Solution

Check the following items:

(1) In-App Purchases has been enabled on the Manage APIs page. (The setting takes around half an hour to take effect.)

You can visit the official website to see how to enable the service.

View attachment 5749173

(2) The public key switch is toggled on, and the public key is used correctly.

View attachment 5749175

View attachment 5749177

(3) The corresponding product category has been configured on PMS in AppGallery Connect, and has been activated successfully.

View attachment 5749187

Scenario 2: Error 60051 is reported when the developer opens the subscription editing page in the member center.

View attachment 5749197

According to the official website, error code 60051 indicates that a non-consumable product or subscription cannot be purchased repeatedly.

Cause analysis

After a subscription is completed, there is a refresh action when going back to the member center. An error will be reported if the subscription button is tapped again before the refresh occurs. The product can only be successfully subscribed to if the subscription button is tapped after the refresh. This is because if the refresh action is not triggered in time, cached data of the previous subscription will still exist. If another product is subscribed to immediately after a product is subscribed to, the ID of the previously subscribed product will be passed to the system instead of the newest product. As a result, an error is reported and the subscription editing page cannot be displayed due to product ID mismatch.

Solution:

Modify the timing for triggering the refresh action to prevent product subscription from occurring before the refresh.

Scenario 3: Error code 60003 is reported when a Huawei phone is used for payment debugging, but the product ID is correctly configured on PMS.

View attachment 5749199

Cause analysis

Generally, error code 60003 indicates that the product information configured on PMS is incorrect. You can sign in to AppGallery Connect, click the desired app, go to Operate > Product Management > Products, and check that the corresponding product exists and mandatory information (such as the name, ID, price, type, and status of the product) is configured correctly.

View attachment 5749201

In addition, you can check whether the product ID is correctly configured in the client code and consistent with that in AppGallery Connect. In particular, check that the field passed to the client code is correct.

Check whether the service region of the HUAWEI ID signed in on the Huawei phone supports In-App Purchases. To do this, call the Task<IsEnvReadyResult> isEnvReady() method.

Solution

After troubleshooting, the developer finds that the error is reported because the product ID passed to the client code is inconsistent with that in AppGallery Connect. After correcting the product ID in the client code, the issue is resolved.

View attachment 5749205

Scenario 4: The payment screen is opened successfully when the checkout start API is called for the first time. However, after the payment is canceled, the payment screen fails to open when the API is called again.

View attachment 5749209

Cause analysis

After a consumable product is purchased, the product can be purchased again only after the purchased product is consumed. Otherwise, error codes such as 60051 will be reported.

Solution

Redeliver the consumable product.

You need to trigger the redelivery process when:

The app launches.​

Result code -1 (OrderStatusCode.ORDER_STATE_FAILED) is returned for a purchase request.​

Result code 60051 (OrderStatusCode.ORDER_PRODUCT_OWNED) is returned for a purchase request.​

Result code 1 (OrderStatusCode.ORDER_STATE_DEFAULT_CODE) is returned for a purchase request.​

If the refund callback URL configured in the In-App Purchases configuration page is incorrect, reconfigure it correctly. You can click here for details.

In addition to the payment screen opening failure problem, another common problem is how to determine whether the sandbox environment is entered.

Scenario 5: A sandbox account is used for testing but no sandbox environment popup is displayed. How to check whether a sandbox environment is entered?

Cause analysis

Generally, a popup similar to the following will be displayed when the sandbox environment is entered.

View attachment 5749211

The two mandatory conditions of the sandbox environment are met but still no sandbox environment popup is displayed. Does this mean that the sandbox environment is not entered?

The screenshot below shows relevant logs for the isSandboxActivated method.

View attachment 5749213

According to the logs, the two mandatory conditions of the sandbox environment are met, which are:

The currently signed in HUAWEI ID is a sandbox account.

The version code is greater than that of the online version on AppGallery. (The APK has not been released to AppGallery. Therefore, the version code returned by AppGallery is 0.)

Theoretically, the sandbox environment has been entered. Are there other methods to check whether the sandbox environment is entered?

Solution

Check whether the sandbox environment is entered successfully using the following methods:

a) Check the returned purchase data, as shown in the screenshot below.

View attachment 5749215

If the Huawei order ID specified in payOrderId begins with SandBox, the order is generated in the sandbox environment.

b) Check the payment report.

View attachment 5749217

Check whether the payment report contains this order. If not, the order is generated in the sandbox environment. (Note: Data on the payment report is not updated in real time. If the order is placed on the current day, the developer can check the payment report on the next day to ensure accuracy.)

c) Clear the HMS Core (APK) cache.

You can try to clear the HMS Core (APK) cache. The system determines whether to display the sandbox environment popup based on relevant fields, which may not be updated in time due to the cache. You can go to Settings > Apps & services > Apps > HMS Core on the device to clear the cache.

References

In-App Purchases official website

In-App Purchases development guide