• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!
  • Fill out your device list and let everyone know which phones you have!    Edit Your Device Inventory

[HMS Core Tips & Tricks] Wallet Kit Integration Procedure and Precautions

Search This thread

John Wo

Official Huawei Rep
Apr 28, 2020
182
22
More information like this, you can visit HUAWEI Developer Forum

In this article, I would like to record the pits for integrating HUAWEI Wallet Kit I stepped on during the integration, so that you can integrate the Wallet Kit more quickly.

Link to the development guide:

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/service-introduction-0000001050042318-V5

Integration Procedure

The Wallet Kit integration process consists of the following five steps:

1. Open the wallet service on the AGC

2. Generating Public and Private Keys

3. Adding a Pass Type on the AGC

4. Running the Demo of the Server

5. Running the Demo of the Client

6. View card adding status

Step 1.2.3 can be performed under the guidance of the development guide.

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/preparations-server-0000001050160377

You are advised to run the demo provided in the development guide in section 4.5 to avoid many detours.

Note that this function is invoked when the demo is invoked. (The demo is normal, but you need to pay attention to some points when using the demo.)

Download the demo from these

Server demo(huawei-wallet-server-windows-jwe-demo.zip):

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Examples-V5/java-sample-code-0000001050157448-V5

Android demo:

https://developer.huawei.com/consumer/en/doc/development/HMSCore-Examples-V5/android-sample-code-0000001050159395-V5

Note: The sequence of steps in section 4.5 cannot be reversed. The reason is described in the following sections.

Precautions

1. Pass structure

A card is made up of two parts.

Merchant information:

This is called model, which contains fixed information about the same type of vouchers, such as the card base, logo, merchant name, and card type.

Special information about a single pass:

This is called instance, such as membership card numbers, membership points, membership levels, and coupon status.

2640852000006560358.20200804011411.06410315272201618503412662191372:50510810025133:2800:2293F42F2FFB4EE81B6C43C5C5BBB13B2ACB929233AE51743B9BB37268290EC3.png

2. Sequence of generating templates and objects

In the Wallet Kit, you need to generate a model and then an instance. Only the server has the interface for generating a model. Therefore, the SDK on the device or an interface on the cloud can be invoked to generate a card instance only after the interface for generating a model is invoked on the server.

This is why the order of steps 4.5 cannot be reversed, as described in the integration steps section.

3. Integration server demo

The following describes the five points of the server:

(1) Dependency for downloading each package in the Maven repository

(2) Modifying the Configuration File in the Demo

(3) Run the demo and move the JSON file to the specified location.

(4) Generate JWE character strings.

(5) Binding pass by URL

(1) Dependency for downloading packages in the Maven repository

After the downloaded server demo is opened in the IDEA, some Maven repositories cannot be downloaded. As a result, some files of the project report errors.

2640852000006560358.20200804011506.24080934609557142793928921318654:50510810025133:2800:A490926D99575A8FE4A534493FA52D89671EBA55AFD7DF63DC59F1887D100355.png

You can wait for the IDEA to download it, or manually download it from the Maven official website: https://mvnrepository.com/

Search for the corresponding groupId on the Maven official website. The search list of each artifactId is displayed. Select the required point to download the version of each artifactId.

2640852000006560358.20200804011822.91573620362703325879890676682739:50510810025133:2800:15D25EB301556C1F3670A7BDE55BEF73AA8544E40BB940A767FCBFC352E6A887.png


2640852000006560358.20200804011855.15474626868521097422273664254645:50510810025133:2800:841292EA161CF5A25BBDB715EAE7AE2475ED51BE17DE1C03350FB464A1A9D127.png


2640852000006560358.20200804011928.12613431308301738681288952095933:50510810025133:2800:02FD60D3CF214B947630BE645B15D86FE2C55AE0807ADC6AEC6CC8C03BC93F24.png

After the download is complete, you can save the downloaded Maven repository to the local Maven repository. To view the local Maven repository, choose File > SettingsBuild, Execution, Deployment > Build Tools > Mavens on the IDEA.

2640852000006560358.20200804012014.76136917739256293217723835239089:50510810025133:2800:F67F188C4D70F21AD66618AECA3843BBE2EBB5985EA1E045FFD9B7893F70E13C.png


2640852000006560358.20200804012102.76222795320493794900655692576355:50510810025133:2800:12B1AC7C6924F12D2AA609D3DBBEB52B82683F48917A48930C1638F3C20EDE8A.png

After the adding is complete, update the Maven repository.

(2) Modify the configuration file in the demo.

After the Maven repository is complete, you can modify the configuration in the demo.

Open the release.config.properties file in the test/resources directory.


2640852000006560358.20200804012232.33598082370749034603320367990334:50510810025133:2800:E28807B0F596059ACF0261789F28EFBC7E1340562BDC2FAF8C0C2A7BA9F97EE5.png

appId and appId.secret are the appId and key of the corresponding app in the AGC. The third URL does not need to be changed. The value of walletServerBaseUrl needs to be changed. Check the region (China, Europe, Asia, Africa, and Russia) to which your developer account belongs. For details about the corresponding URL, see https://developer.huawei.com/consum...-V5/wallet-server-api-2-9-0000001050158382-V5, here, my developer account belongs to Europe. Therefore, change the URL to the URL of Europe. (If you forget the region to which your account belongs, you can try each URL when the demo reports an error.)

2640852000006560358.20200804012340.71947534438615075302011394450554:50510810025133:2800:455440C83FD832FA90A8D2813D030966626A1522AA960A66AD2BE38F5EDE6DFF.png


2640852000006560358.20200804012345.04224807446061027710430063922400:50510810025133:2800:07B3ACBF028DF5B9224F59FFA789E7BCDE02A4B6F500EEB4E97D2A94DAFE4419.png

The screenshot after the modification is as follows:

2640852000006560358.20200804012440.46125687453232471469533084884551:50510810025133:2800:C24731326287D5B5506E0DB1F13748DB5A2DC101F860C3E5804EEC14A152EACF.png

(3) Run the demo and move the JSON file to the specified directory.

After the configuration is complete, copy the hmspass folder in the config directory, build the project, click Build-Build Progect. Then, copy the hmspass folder to the target/classes directory.

2640852000006560358.20200804012537.27510416798804215806301984962065:50510810025133:2800:7FB87FEE139D79F1BFFF2A4E5B4FE73C7B84FE67DC56C3B3954420058CC433BE.png


After that, you can run the demo. When you run the demo, you should mainly run the java files in the Test folder

2640852000006560358.20200804012658.32306106110326578487186858518080:50510810025133:2800:F4307D27FBFF7F19CC430F62DAB260A2FC50CFB3B7BFF652370B36FFD3E3E490.png


Each type of passes corresponds to two Java files. The file whose name ends with ModelTest provides the examples of adding, modifying, and querying pass models. The file whose name ends with InstanceTest provides the examples of adding, modifying, and querying pass instances.

a. Generate a pass model

The following uses the member card (loyalty) as an example.

Open the HwLoyaltyModelTest file and create a model method named createLoyaltyModel().

2640852000006560358.20200804012734.47196229467800282015128776274731:50510810025133:2800:6BB1BD1F659809A184844984D3084712121DCAB9F06532C27EC23A737D9A2A3A.png

The LoyaltyModel.json file is the file to be transferred to Huawei interfaces. Before running the method, you need to modify the file information. You can find the file in the target/classes/hmspass directory.

2640852000006560358.20200804012758.30032173471587615358403900195160:50510810025133:2800:CB5ED71DEF3345F5CC2583F1E95D8708560653BB37DA16AEA40479E95D5004AD.png

Modify the passTypeIdentifier and passStyleIdentifier fields. The passTypeIdentifier field is the service ID defined when we add card types on the AGC. The passStyleIdentifier field is the unique identifier of the model and is used when pass instances are created, field defined by the developer. The screenshot after the modification is as follows:

2640852000006560358.20200804012933.13764991141582672610498155728157:50510810025133:2800:FC66105D902ED0F8EADA9B7329EFA7053F22B9B6ADA925E0EEBAF5C8F7427B76.png

The following figure shows the console after createLoyaltyModel() is executed.

b. Generate a pass instance.

The following uses the member card (loyalty) as an example.

The procedure is similar to that for modifying a model. Open the HwLoyaltyInstanceTest file and view the LoyaltyInstance.json file in createLoyaltyInstance().

2640852000006560358.20200804013017.30271402414898630249170947961966:50510810025133:2800:B1EAB3B9EC6EB4D2D65DF48112D6E529956E32E46AEC6A1EC164BA8C263837D9.png

Change the values of passTypeIdentifier and passStyleIdentifier to the values generated in the previous step. The values of serialNumber and organizationPassId are unique identifiers of cards (in different application scenarios). Ensure that the values of the two fields are unique.

Then we run createLoyaltyInstance() to generate a pass instance.

2640852000006560358.20200804013137.62954820985933677846267604544114:50510810025133:2800:64B18CA4AAC086E154A32A364F443532C114CF6D8A767BEC153A29E121BCE60C.png

(4) Generate a JWE character string

The generateThinJWEToBindUser() and generateJWEToAddPassAndBindUse() methods exist in the InstanceTest file of each pass.

generateThinJWEToBindUser(): Signs and encrypts the generated pass instance and generates a character string. -----The createLoyaltyInstance() method of (3).b does not need to be executed.

generateJWEToAddPassAndBindUse(): Signs and encrypts pass instances that are not generated, and generates corresponding character strings. ------The createLoyaltyInstance() method of (3).b does not need to be executed.

The two methods are similar. The following uses generateThinJWEToBindUser() as an example. The code is as follows:

2640852000006560358.20200804013244.95476364607582617253381435881073:50510810025133:2800:C8B1D278A76C1454EA5D760BB136F32BE5185193C0C6420F00A3A56C7715EF87.png

appId indicates the app ID, and instanceIdListJson indicates the serialNumber set when the pass instance is generated. The code after modification is as follows:

2640852000006560358.20200804013325.90417490346939633100657564266901:50510810025133:2800:F8BAFA0F8AE4AA68657DFF880288F3AD3228684CDA08D2537DAA5BE46B9B96E4.png

Note: The LoyaltyInstance.json file in generateJWEToAddPassAndBindUse() is a pass instance that is not generated (the createLoyaltyInstance() method is not executed).

Then you need to change the value of jweSignPrivateKey to the private key of the public key configured on the AGC card.

2640852000006560358.20200804013400.67835016652734926986691342697076:50510810025133:2800:BC2C77E45C46D1A03BFD5BE6CA2EA038A4ACACECC2075B50959DD76A309C1490.png


2640852000006560358.20200804013516.38274164349197563427829867467175:50510810025133:2800:7A90908DB56C93F2624373AC890C58A4DC973F5C462D40B29FB1896B7F587568.png

The screenshot after the modification is as follows:

2640852000006560358.20200804013704.44721908976347402969843612215915:50510810025133:2800:661BD34334DCA435D003CB21D971FCB64F20A2B29B565C6E5D2E500B9F4C8810.png

The following results are obtained:

2640852000006560358.20200804013727.87216529820112882728690779918338:50510810025133:2800:893B511A51E81F8B2C8A7535B2347C93B70DE596AAF5FDD679EAFBBAB7E364F0.png

A JWE string is generated after the serialNumber of a pass is encrypted and signed. Generally, the JWE string is called a thin JWE.

(5) Bind pass by URL

Huawei provides an interface for binding pass through the URL. The format is https://{walletkit_website_url}/walletkit/consumer/pass/save?jwt={jwt_content}.

{jwt_content} is the URL-encoded JWE String obtained in the previous step. The URL-encoded code is as follows:

URLEncoder.encode(jwtStrInstanceIds, StandardCharsets.UTF_8.toString())

{walletkit_website_url}: URL of the area where the developer is located. The mapping is as follows:

1*WtFOD4v3cniuQ-tRxaEj4A.png

For example, the URL of the thin JWE in Europe is in the following format:

https://walletpass-dre.cloud.huawei.com/walletkit/consumer/pass/save?jwt=YWlKtBZmNGtT.......eTlabW

After you enter the URL in the browser, the Huawei ID login page is displayed. Log in to a Huawei ID that is in the same region as the developer account.

2640852000006560358.20200804013749.40899071712333471106371061444591:50510810025133:2800:CCAF8009F3D446AD2660A9AD8A76B0B441E968CA1A7631F8BFAB65A2DF0348E8.png

After the login is successful, the card binding result is displayed.

2640852000006560358.20200804013849.88078663914996350690216478872879:50510810025133:2800:273022A761C874EB4FCC766579149A955DACE5D09CEE73126B8CCFA6D8A8161E.png


2640852000006560358.20200804013849.57671349699783910632630157797558:50510810025133:2800:CB60ADCA7218B62B479D4F89D8AD73DEB9D7652E6022B9A559FC98C337C6DDE2.png


2640852000006560358.20200804013849.18343646875028270090381095689487:50510810025133:2800:786D99D7E7C058B3B7B47626D68C25B25259987E193D3A0BCFC3A103AD4AF1E9.png

The possible cause of binding fail is that the pass has been bound by another user or the region of the Huawei ID is different from that of the developer account.

4. Integrate the client demo.

(1) Changing the Key

(2) Enter the pass information and add passes.

(3) Confirm and log in with your Huawei ID.

(4) Bind passes

(5) Open your wallet and check your passes.

(1) Changing the Key

After opening the HmsWalletClientDemo project using Android Studio, you need to modify the PRIVATE_KEY_EUROPE_DEBUG file in the Constant.java file in the com.huawei.hms.wallet package.

2640852000006560358.20200804013935.54413408758755888665014165391444:50510810025133:2800:FEEC32DF3FDFC0828A63028855365F94051EDC5921CEF6C813F1DFC5CED5E8A8.png

Change the value of this field to the content in the private.txt file that is generated when the public key and private key are generated in step 1.

2640852000006560358.20200804013955.21175196905344588316012961224317:50510810025133:2800:67EE109B6A7F24C6323E2B0908E7B9A6EAB6D4F6F9CB34E64FCB96A6C2F84135.png

(2) Enter the pass information and add passes.

a. Select European test environment

b. Click ClickSaveLoyaltyCard

2640852000006560358.20200804014030.98222488066191794923269770049928:50510810025133:2800:40DA1CF8A4DBA6D4A69B34A8F8C988FB783497F2C5D0B4D372851CC7372DB3B9.png

For the full content, you can visit HUAWEI Developer Forum