Overview

HUAWEI Wallet Kit allows users to claim passes of merchants, including loyalty cards, gift cards, coupons, boarding passes, event tickets, and transit passes, and add them to HUAWEI Wallet. You can provide a button or link in your app for users to add passes to their HUAWEI Wallet and view and manage them.
You need to perform the following operations:

What You Will Create

In this codelab, you will use the created demo project to:
Call the HMS Core Wallet SDK to construct instances so that passes can be added to HUAWEI Wallet.

What You Will Learn

Hardware Requirements

Software Requirements

To integrate HUAWEI Wallet Kit, you must complete the following preparations:

For details, please refer to Preparations for Integrating HUAWEI HMS Core.

Enabling the HUAWEI Wallet Kit API

You have now successfully enabled the HUAWEI Wallet Kit API for your app.

Generating a Public-Private Key Pair

Registering HUAWEI Wallet Kit

Obtaining the Sample Code of the HUAWEI Wallet Kit API

Setting Parameters

Compiling the Sample Code with Maven

Pushing a Model

Configuring Data

Input parameters are configured in the model file (in JSON format) that is stored in target/classes/hmspass. Before running the test method, ensure that the value of passTypeIdentifier in the JSON file is the same as that of Service ID set in Applying for the HUAWEI Wallet Kit Service.
Mandatory parameters:

Parameter

Description

Remarks

passTypeIdentifier

Service ID set in Applying for the HUAWEI Wallet Kit Service.

Its value must be the same as that in the model.

passStyleIdentifier

Model ID, which is defined yourself.

Its value must be the same as that in the model.

organizationPassId

Pass ID in a pass instance, which is unique in your system.

-

serialNumber

Pass instance ID, which is unique in your system.

-

Pushing the Pass Instance

Method 1: Generating a JWE containing complete pass instance information and sending the JWE to the Huawei server
Call the JweTest.generateJWEToAddInstanceAndBindUser method to push a new pass instance to the Huawei server. You need to enter the name of the pass instance JSON file to be read, the RSA private key generated in Applying for Security Components, and the link corresponding to the region where your server is located.

The following is a sample HTTPS link:
https://{walletkit_website_url}/walletkit/consumer/pass/save?jwt={jwe_content}

China

walletpass-drcn.cloud.huawei.com

Russia

walletpass-drru.cloud.huawei.com

Asia, Africa, and Latin America

walletpass-dra.cloud.huawei.com

Europe

walletpass-dre.cloud.huawei.com

Note that the JWE contained in the link cannot exceed 2000 characters. If the JWE generated using this method is too long, use method 2 to generate a JWE.
Method 2: Using the server API to generate a pass instance and sending a thin JWE containing only the pass instance ID (serialNumber) to the Huawei server

  1. The Huawei server provides the Wallet Kit API, a RESTful API, for you to create a pass model. For example, you can call the HwLoyaltyInstanceTest.addLoyaltyInstance method to create a loyalty card instance using the API. The methods for creating the instances of other types of passes are similar.
  2. Call the JweTest.generateThinJWEToBindUser() method to send a thin JWE that contains only the pass instance ID (serialNumber). You need to enter the pass instance ID (serialNumber), RSA private key generated in Generating the Public and Private Keys, and link corresponding to the region to which the server belongs.

Well done. You have successfully completed this codelab and learned:

Wallet Kit-related APIs

Demo source code used in this codelab

Code copied