HMS In-App Purchases | Solar2D

Kayahan Başkeser
Huawei Developers
Published in
2 min readFeb 14, 2021

--

Hi everyone,

In this article, I will mention how to use HMS In-App Purchases on Solar2D.

For HMS SDK for in-app payment, the package name must end with “.HUAWEI” or “.huawei” (case sensitive).

First of all, we should create a Solar2D project and import plugin to “build.settings” file. If you do not have enough information about HMS Solar2D plugin integration, I recommend you to read this article. HMS Solar2D Plugin Integration

Let’s start after completing the HMS integration.

First we need to import plugin to build.settings file.

And we need to specify minSdkVersion in build.settings file for HMS In-App Purchases.

Note : Don`t forget to place agconnect-services.json file in main.lua directory.

After all the configuration processes, you must define the plugin in main.lua.

We should call all methods through huaweiIAP object. And you can take result informations from listener function.

Methods in the Plugin

isEnvReady

Checks whether the currently signed-in HUAWEI ID is located in a country or region where HUAWEI IAP is available.

isSandboxActivated

Checks whether the signed-in HUAWEI ID and the app APK version meet the requirements of the sandbox testing.

obtainOwnedPurchases

Queries information about all purchased products, including consumables, non-consumables, and subscriptions.

obtainProductInfo

Obtains product details configured in AppGallery Connect. You need to give the productId as a parameter to method.

createPurchaseIntent

Creates orders for products managed by the PMS (Product management system), including consumables, non-consumables, and subscriptions.

consumeOwnedPurchases

Consumes a consumable after the consumable is delivered to a user who has completed payment.

verifySignature

Verification operation is performed using the signature and product information and public key of the purchased product.

obtainOwnedPurchaseRecord

Obtains the consumption history of a consumable or all subscription receipts of a subscription.

startIapActivity

Displays pages of HUAWEI IAP, including:

  • Subscription editing page
  • Subscription management page

And you can examine the sample project from the following repository.

References

--

--