HMS Core in-app payment service (In-App Purchases, IAP) provides a convenient in-app payment experience and easy access process for applications. After the developer's application integrates the IAP SDK, the developer can call the IAP SDK interface and start the IAP cashier to realize in-app payment. Through the in-app payment service , users can purchase various types of virtual goods within the app, including one-time items (both consumable and non-consumable) and subscription-based items. The in-app payment service supports both client and server development forms. For details, please refer to the following official documents:
In our daily work, we will receive common questions about IAP integration from developers. Here are some sharing and summarization, hoping to provide reference for other developers who encounter similar problems——
- The use of com.huawei.hmf.tasks.Task.
Task<TResult> is a basic abstract class of the underlying framework of HMS Core SDK, by implementing the relevant abstract methods in the Task class. For example, adding one or more listeners will be called when the task is successfully completed. When multiple listeners are added, they will be called in the order in which they were added, and the call will be executed in the main thread.
Because it has been integrated into the project gradle package, it can be used directly without recreating the declaration. We can find it in the gradle file imported in the Project project:
Developers can also refer to the following documents to solve the problem:
- Is it normal to have no accountFlag in the InAppPurchaseData parameter?
There is no accountFlag in the InAppPurchaseData parameter. According to the official documentation of the in-app payment service, the reference API for InAppPurchaseData:
The InAppPurchaseData JSON type is used to store user purchase information, including consumable items, non-consumable items, and subscription items. The parameter accountFlag is a non-required parameter, an optional field, and a non-fixed return. This return value will only be available if the AppTouch application is used.
- The judgment (e instanceof IapApiException) of the parameter (Exception e) in the onFailure of the document createPurchaseIntentWithPrice does not hold.
First, you need to confirm the device and integrated environment information (it is best to update to the latest version): HMS Core version number, version number of the integrated SDK, whether the device is a mobile phone or a smart screen.
Then according to the comments of the official document 60055 error code, it generally means that the user does not agree to the payment agreement. The developer can obtain a Status object from the IapApiException returned in the request interface. The Status contains the IAP protocol page. The application can use the startResolutionForResult method of Status to Launch the agreement page.
The reasons for this problem may also include the following:
(1) The network problem, the network abnormality causes the interface acquisition failure.
(2) Is the IapApiException referenced correctly.
(3) Whether there is a pop-up window when paying, if there is no pop-up window, you need to enable the "background pop-up interface" permission of the device. The settings are as follows: Find the HMS Core application details page--Permission management--"Background pop-up interface"--Select "Always allow" ",retest.
(4) If it is a code problem, please refer to the official Demo implementation and testing of the Developer Alliance for details. Demo download address:
- Application server verification, verification of the purchase token failed.
First of all, the prompt "Failed to verify the purchase token" appears. Please refer to each step of the "Acquiring Application-level AT" document in detail to check whether the acquired AT is an application-level AT. Get application-level AT address documentation:
Then encapsulate the obtained application-level AT, and rebuild the authorization in the request header header. For details, please refer to some documents of the public description:
For more details on in-app payment services, please refer to:
https://developer.huawei.com/consumer/cn/hms/huawei-iap/?ha_source=hms1
Huawei Developer Alliance official website
Get development guidance document
To participate in developer discussions, please go to Reddit community
demo and sample code please go to Github
For integration issues please go to Stack Overflow
for more details >>
Visit Huawei Developer Alliance official website
Get development guidance document
Huawei Mobile Services Open Source Warehouse Address: GitHub , Gitee
Follow us and know the latest technical information of HMS Core for the first time~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。