English | 中文
The iap_demo App demonstrates Huawei In-App Purchases (IAP) client APIs and usages.
Documentation can be found at this link.
Huawei In-App Purchases provides 3 types of product: consumable, non-consumable and auto-renewable subscription.
Consumable : Consumables are product that can be consumed once. When consumed, it's depleted and can be purchased again.
Non-consumable : Non-consumables can be only purchased once and do not expire.
Auto-renewable subscription : Once purchased, Users can access to value-added functions or content in a specified period of time. The subscriptions will automatically renew on a recurring basis until users decide to cancel.
This demo app provides all 3 types of product to demonstrate the procedure and capability of Huawei IAP.
Disclaimer: The demo only demonstrates the purchase procedure, and it does not have a real use of purchased products.
You also can use HMS Toolkit to quickly integrate the kit and run the demo project, as well as debug the app using a remote device for free. For details, please visit https://developer.huawei.com/consumer/en/doc/development/Tools-Guides/getting-started-0000001077381096.
Check whether the Android studio development environment is ready. Open the sample code project directory with file "build.gradle" in Android Studio.
Finish the configuration in AppGallery Connect. See details: Configuring AppGallery Connect
Add your products on the AppGallery Connect. See details: Configuring In-App Product Information
To build this demo, please first import the demo in the Android Studio.
Configure the sample code:
build.gradle
file.build.gradle
file, and change the value of applicationId to your app package name.Run the sample on your Android device or emulator.
Once you start the demo, you should be able to see the following page.
The demo provides gem as an example of consumable product.
Tap Consumable products, you should be able to see the home page for consumable demo.
The demo will call the obtainProductInfo
API, to query the detail of managed products.
(And also retries consumeOwnedPurchase
, see below.)
Tap 5 gems, the demo will call the createPurchaseIntent
API,
and jump to the checkout page which is provided by IAP Service.
Once payment finishes, the consumable demo will increase user's gems counter
and call consumeOwnedPurchase
API to notify Huawei IAP Service that user has consumed the purchase.
Note: If an exception (such as network error or process termination) occurs
after a successful payment, the demo app will attempt to update the gem count
when you re-enter the page. (Using obtainOwnedPurchases
API to obtain consumable
purchases and consumeOwnedPurchase
to retry consuming purchases)
Note: In production you should validate the result on server side (deliver the purchase)
before calling consumeOwnedPurchase
.
Tap History, the demo will call the obtainOwnedPurchaseRecord
API to obtain the purchase history.
The demo provides hidden level as an example of non-consumable product.
Tap the Non-consumable product, you should be able to see the home page for non-consumable demo.
The demo will call the obtainOwnedPurchases
API to obtain purchased non-consumable product.
Assuming you have not purchased the hidden level, you will see the following screenshot. Tap hidden level to start the purchase procedure (which is the same as purchasing consumable product).
After the purchase finishes (Or you have purchased the hidden level before), the demo will display the hidden level as purchased.
The demo provides Service-One and Service-Two as examples of subscription group, each contains 2 options of auto-renewable subscription.
(For more detail of subscription and subscription group, see related documentation.)
Tap the Auto-renewable subscription, you should be able to see the home page for auto-renewable subscription demo.
The demo will call the obtainOwnedPurchase
API to obtain purchased subscription product.
Active subscription will be displayed as ACTIVE.
Tap one of BUY buttons, the demo will start the purchase procedure by calling createPurchaseIntent
.
Note: currently we only support Alipay for subscription payment.
You will be prompted to authorize automatic fee deduction agreement. Once purchase succeed, IAP Service will display the purchase result.
Tap Manage Subscription, the demo will jump to subscription manage page. The page will list all subscribed products, including expired subscriptions.
Tap Happy Subscribe on Subscription manage page, you will be able to edit subscription and choose other subscription options in same subscription group, or tap UNSUBSCRIBE to cancel the subscription. The subscription will remain valid until the expire date.
If you want to evaluate more about HMS Core, r/HMSCore on Reddit is for you to keep up with latest news about HMS Core, and to exchange insights with other developers.
If you have questions about how to use HMS samples, try the following options:
huawei-mobile-services
.If you run into a bug in our samples, please submit an issue to the Repository. Even better you can submit a Pull Request with a fix.
This demo is licensed under the Apache License, version 2.0.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. Open source ecosystem
2. Collaboration, People, Software
3. Evaluation model