Giter Site home page Giter Site logo

huawei-iap-demo's Introduction

Huawei In-App Purchases (IAP) Demo

The iap_demo App demonstrates Huawei In-App Purchases (IAP) client APIs and usages.

Documentation can be found at this link.

Table of Content

Introduction

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.

Environment requirement

Develop requirement

To be able to develop, build and debug this demo, you will need at least the following environment:

  • a connection to Internet, for downloading package dependencies form Huawei and Google

  • a compatible IDE, Android Studio is recommended.

  • a gradle installation will be downloaded when you use command line gradle wrapper or open downloaded folder in compatible IDE

  • an Android SDK installation, API version 28 or above is recommended.

Runtime requirement

To be able to run this demo, you will need an Android device with EMUI 5.0 or above, Android 4.4 and above, with Huawei Mobile Service (HMS) pre-installed.

If the HMS is missing, the device will prompt you to install or upgrade HMS first on calling IAP SDK.

Installation

  1. Clone or download this project and open the downloaded folder in Android Studio or compatible IDE.

  2. Use IDE's functionality to install configured project on to your device.

Configuration

This demo come with pre-configured agconnect-services.json, HMS dependencies, signing keys and in-app products. These pre-configured settings are for demo purpose only, please refer to the Documentation for guide of adopting Huawei IAP.

Tutorial

Once you start the demo, you should be able to see the following page.

demo home page

Disclaimer: The demo only demonstrates the purchase procedure, and it does not have a real use of purchased products.

Purchasing consumable product

The demo provides gem as an example of consumable product.

  1. 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.)

    consumable demo page
  2. Tap 5 gems, the demo will call the createPurchaseIntent API, and jump to the checkout page which is provided by IAP Service.

    consumable payment selection
  3. 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.

    gem purchase result

    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.

  4. Tap History, the demo will call the obtainOwnedPurchaseRecord API to obtain the purchase history.

    consumable purchase history

Purchasing non-consumable product

The demo provides hidden level as an example of non-consumable product.

  1. 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.

  2. 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).

    hidden level not purchased
  3. After the purchase finishes (Or you have purchased the hidden level before), the demo will display the hidden level as purchased.

    hidden level have been purchased

Purchasing auto-renewable subscription service

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.)

  1. 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.

    subscription homepage with active subscription
  2. Tap one of BUY buttons, the demo will start the purchase procedure by calling createPurchaseIntent.

    subscription payment selection

    Note: currently we only support Alipay for subscription payment.

  3. You will be prompted to authorize automatic fee deduction agreement. Once purchase succeed, IAP Service will display the purchase result.

    subscription payment selection
  4. Tap Manage Subscription, the demo will jump to subscription manage page. The page will list all subscribed products, including expired subscriptions.

    subscription manage
  5. 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.

    edit subscription

Code Examples

Query purchased products

Query the user's ordered product information according to the query type.

The products include consumable products, non-consumable products and auto-renewable subscription products.

When the type set to subscription, obtainOwnedPurchase returns subscriptions that the user has in this application, including the following subscription status:

  • Renewal (normal state, subscription will be renewed in the next cycle)

  • Expires (the renewal has been canceled, after this cycle becomes expired, there will be no renewal for the next cycle)

  • Expired (subscription is invalid, but can still be found in the subscription history)

For more detail, please refer to IapRequestHelper.java.

Make Purchases

Make purchase according to the purchase type and product ID type.

The products include consumable products, non-consumable products, and auto-renewable subscription products.

For more detail, please refer to IapRequestHelper.java.

Jump to subscription management and detail pages

Your application can jump to the Manage Subscription Page and Subscription Details Page via url schemes.

If the parameter sku is empty, the app will jump to the management subscription page. The page displays the list of products that the current user has subscribed to in your application.

If the parameter sku is not empty, it jumps to the subscription details page. The detail page will also display other product information for the same product subscription group.

For more detail, please refer to IapRequestHelper.java.

Licensing

This demo is licensed under the Apache License, version 2.0.

huawei-iap-demo's People

Contributors

bryantvu avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.