目录

Wallet Kit Manual Conversion Guide

Overview

  1. In HMS, coupons, gift cards, and loyalty cards all correspond to the PassObject object.
  2. PassObject uses the builder mode. All parameters need to be set in the builder. After setting the parameters in the builder, use the build() method to build the PassObject object.
    PassObject loyaltyObject = PassObject.getBuilder().setSerialNumber("12345")
        .addImageList(new ArrayList<>())
         //... Add other settings as required.
        .build();
  3. Most attributes of PassObject use the common APIs AppendField and CommonField. They are set using the addAppendFields() and addCommonFields() methods of PassObject.Builder. The key-value structure (key/label/value) is used, and no independent get/set method is provided. The common attributes of the Key value are defined in the WalletPassConstant class.

addInfoModuleDataLabeValueRow(LabelValueRow row)

The LabelValue information in HMS is merged into textData.

Refer to the following sample code for To HMS API conversion. Convert the LabelValue list in the LabelValueRow object to the AppendField list in HMS, assign the values of the label and value attributes in LabelValue to the label and value attributes in AppendField, and call the addTextList() method of the PassObject object to assign the AppendField object list to the PassObject object.

// The following row1/row2 corresponds to the object in the LabelValueLie table in LabelValueRow.
AppendField row1= AppendField.getBuilder().setKey("uniqueKey1") // The value of Key can be set randomly but must be unique in an object.
    .setLabel("Next Reward") // The value of label corresponds to the label in LabelValue.
    .setValue("2 coffees")   // The value of value corresponds to the value in LabelValue.
    .build();
AppendField row2= AppendField.getBuilder().setKey("uniqueKey2")
    .setLabel("Member Since")
    .setValue("01/15/2013")
    .build();
ArrayList<AppendField> textList = new java.util.ArrayList<>();
textList.add(row1);
textList.add(row2);
PassObject.getBuilder().addTextList(textList);

addInfoModuleDataLabelValueRows(Collection<LabelValueRow> rows)

For details about how to convert this method in the To HMS API scenario, please refer to addInfoModuleDataLabeValueRow(LabelValueRow row).

addImageModuleDataMainImageUri(UriData uriData)

The conversion in the To HMS API scenario is as follows:

addImageModuleDataMainImageUris(Collection<UriData> uris)

For details about how to convert this method in the To HMS API scenario, please refer to addImageModuleDataMainImageUri(UriData uriData).

addLinksModuleDataUri(UriData uriData)

In the Add HMS API and To HMS API scenarios, please refer to the following conversion instructions.

The conversion methods for loyalty cards, gift cards, and coupons are the same. The following uses loyalty cards as an example:

For the following in LoyaltyWalletObject:

public LoyaltyWalletObject.Builder addLinksModuleDataUri(UriData uriData);

Refer to the following instructions:

Currently, the uri value types of the uriData attribute are Nearby stores, Main page, and Hotline. When the AppendField object in HMS is built, the key value constants in HMS are as follows:

WalletPassConstant.PASS_APPEND_FIELD_KEY_NEARBY_LOCATIONS,

WalletPassConstant.PASS_APPEND_FIELD_KEY_MAINPAGE,

WalletPassConstant.PASS_APPEND_FIELD_KEY_HOTLINE.

For the AppendField object in HMS, the value of value can be the value of uri in uriData, and the value of Label can be the value of description in uriData.

Build an object instance hotlineAppendField of the AppendField type, put it into List<AppendField> appendFields, and use the addAppendFields() method of PassObject to assign appendFields to the PassObject object.

Hotline sample code:

PassObject.Builder passBuilder = PassObject.getBuilder();
ArrayList<AppendField> appendFields = new ArrayList<>();
String hotlineLabel = "hotline";
String hotlineValue = "4000";
AppendField hotlineAppendField = AppendField.getBuilder() 
    .setKey(WalletPassConstant.PASS_APPEND_FIELD_KEY_HOTLINE)        
    .setLabel(hotlineLabel)        
    .setValue(hotlineValue)        
    .build();
appendFields.add(hotlineAppendField);
passBuilder.addAppendFields(appendFields);

addLinksModuleDataUris(Collection<UriData> uris)

For details about how to convert this method in the Add HMS API and To HMS API scenarios, please refer to addLinksModuleDataUri(UriData uriData).

addLocation(LatLng latLng)

The conversion in the To HMS API scenario is as follows:

addLocations(Collection<LatLng> locations)

For details about how to convert this method in the To HMS API scenario, please refer to addLocation(LatLng latLng).

addMessage(WalletObjectMessage walletObjectMessage)

The conversion in the To HMS API scenario is as follows:

addMessages(Collection<WalletObjectMessage> messages)

For details about how to convert this method in the To HMS API scenario, please refer to addMessage(WalletObjectMessage walletObjectMessage).

addTextModuleData(TextModuleData textModuleData)

The conversion in the To HMS API scenario is as follows:

addTextModulesData(Collection<TextModuleData> textModulesData)

For details about how to convert this method in the To HMS API scenario, please refer to addTextModuleData(TextModuleData textModuleData).

CreateWalletObjectsRequest.Builder build()

Add HMS API

Before calling build to create a request, perform the following steps:

  1. Send the JSON character string converted from the PassObject object to your server and receive the returned JWE data string.
  2. Replace getJweFromAppServer(passObjectJson) in the sample code with the encrypted JWE data string obtained from the server.
  3. After obtaining the JWE data string, use the setContent() method of CreateWalletPassRequest.Builder to pass the data to the request.
Sample code for loyalty cards, coupons, and gift cards:
if (org.xms.g.utils.GlobalEnvSetting.isHms()) {
    String passObjectJson = ((com.huawei.hms.wallet
.pass
.PassObject) (wob.getHInstance())).toJson();  
    String jweString = getJweFromAppServer(passObjectJson);
    ((com.huawei.hms.wallet.CreateWalletPassRequest.Builder) (build.getHInstance())).setContent(jweString);
}
// wob is the instance of the PassObject object.
// build is the instance of the CreateWalletPassRequest object.

To HMS API

Before calling build to create a request, perform the following steps:

  1. Send the JSON character string converted from the PassObject object to your server and receive the returned JWE data string.
  2. Replace getJweFromAppServer(passObjectJson) in the sample code with the encrypted JWE data string obtained from the server.
  3. After obtaining the JWE data string, use the setContent() method of CreateWalletPassRequest.Builder to pass the data to the request.
Sample code for loyalty cards, coupons, and gift cards:
PassObject passObject = new PassObject();  // Here, new is used only as an example. In actual code, the corresponding PassObject object needs to be obtained.
String passObjectJson = passObject.toJson();  
String jweString = getJweFromAppServer(passObjectJson);  
CreateWalletPassRequest.Builder builder =  CreateWalletPassRequest.getBuilder();
builder.setContent(jweString);

GiftCardWalletObject.Builder build(), LoyaltyWalletObject.Builder build(), and OfferWalletObject.Builder build()

Before creating a GiftCardWalletObject, you need to manually set PassTypeIdentifier. The value of PassTypeIdentifier is the service ID used when a user registers with the Wallet Kit pass service on the AppGallery website. In the sample code, the values of PassTypeIdentifier for GiftCardWalletObject, LoyaltyWalletObject, and OfferWalletObject are hwpass.type.giftcard.hmspublic, hwpass.type.loyalty.hmspublic, and hwpass.type.offer.hmspublic, respectively.

java.lang.String getBarcodeAlternateText()

The conversion in the Add HMS API and To HMS API scenarios is as follows:

PassObject passObject = new PassObject();  // Here, new is used only as an example. In actual code, the corresponding PassObject object needs to be obtained.
BarCode barCode = passObject.getBarCode();
String text = barCode.getText();

java.lang.String getBarcodeType()

The conversion in the Add HMS API and To HMS API scenarios is as follows:

PassObject passObject = new PassObject();  // Here, new is used only as an example. In actual code, the corresponding PassObject object needs to be obtained.
BarCode barCode = passObject.getBarCode();
String text = barCode.getType();

java.lang.String getBarcodeValue()

The conversion in the Add HMS API and To HMS API scenarios is as follows:

PassObject passObject = new PassObject();  // Here, new is used only as an example. In actual code, the corresponding PassObject object needs to be obtained.
BarCode barCode = passObject.getBarCode();
String text = barCode.getValue();

LabelValue

In HMS, the LabelValue object needs to be converted into the AppendField object for use.

The conversion in the Add HMS API and To HMS API scenarios is as follows:

AppendField field = AppendField.getBuilder().setKey("key") // The value of Key can be set randomly but must be unique in the same PassObject.
    .setLabel("LabelValue.getLabel()")
    .setValue("LabelValue.getValue()")
    .build();

For the LabelValueRow class, please refer to this class and addInfoModuleDataLabeValueRow(LabelValueRow row).

LoyaltyPoints

In HMS, the bonus points of a loyalty card can be set only by value and label. The value is of the string type, and the currency type is not distinguished. For details, please refer to setLoyaltyPoints(LoyaltyPoints loyaltyPoints).

setAccountId(String accountId)

The conversion in the To HMS API scenario is as follows:

setAccountName(String accountName)

The conversion in the To HMS API scenario is as follows:

setBalanceMicros(long balanceMicros)

The conversion in the To HMS API scenario is as follows:

setBalanceUpdateTime(long balanceUpdateTime)

The conversion in the To HMS API scenario is as follows:

setBarcodeAlternateText(String barcodeAlternate)

When the HMS Wallet solution is used, all barcode information must be set at a time. The values of Type for BarCode are BarCode.BARCODE_TYPE_QR_CODE (2D barcode) and BarCode.BARCODE_TYPE_CODABAR (1D barcode).

The conversion in the Add HMS API and To HMS API scenarios is as follows:

PassObject.Builder passObject= PassObject.getBuilder();
BarCode barCode = BarCode.getBuilder().setType(BarCode.BARCODE_TYPE_QR_CODE).setText("12345").setValue("28343E3").build();
passObject.setBarCode(barCode);

setBarcodeValue(String barcodeValue)

For details, please refer to setBarcodeAlternateText(String barcodeAlternate).

setBarcodeType(String barcodeType)

For details, please refer to setBarcodeAlternateText(String barcodeAlternate).

setCardNumber(String cardNumber)

Conversion is needed only for gift cards.

The conversion in the To HMS API scenario is as follows:

setEventNumber(String eventNumber)

The conversion in the To HMS API scenario is as follows:

setId(String id)

In HMS, the passId field is added for each pass and is mandatory. The value of passId is the same as that of id and needs to be set during coupon Id setting.

The conversion in the To HMS API scenario is as follows (coupon):

String id = "abc123";// You need to transfer the value of id.
PassObject.getBuilder().setSerialNumber(id).setOrganizationPassId(id);

setIssuerName(String merchantName)

The conversion in the To HMS API scenario is as follows:

setLoyaltyPoints(LoyaltyPoints loyaltyPoints)

The conversion in the To HMS API scenario is as follows:

setPin(String pin)

The conversion in the To HMS API scenario is as follows:

setProgramName(String programName)

The conversion in the To HMS API scenario is as follows:

setState(int state)

In HMS, the card status and validity period constitute the PassStatus object.

The conversion in the Add HMS API and To HMS API scenarios is as follows:

Build a PassObject object and assign a value to its status attribute. The data type of the status attribute of PassObject is PassStatus. The value of the state attribute of PassStatus is set based on actual requirements. The value can be active, completed, expired, or inactive.

Sample code:

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");        
Long startTime = 0L;        
Long endTime = 0L;
PassStatus passStatus = PassStatus.getBuilder()        
    .setState("active")        
    .setEffectTime(format.format(new Date(startTime)))        
    .setExpireTime(format.format(new Date(endTime)))        
    .build();
PassObject.Builder passBuilder = PassObject.getBuilder();
passBuilder.setStatus(passStatus);

Note: The values of startTime and endTime are time in millisecond. Set them based on the actual time of a pass.

setTitle(String title)

The conversion in the To HMS API scenario is as follows:

setValidTimeInterval(TimeInterval timeInterval)

The conversion in the Add HMS API and To HMS API scenarios is as follows:

The startTimestamp and endTimestamp attributes of TimeInterval respectively correspond to the effectTime and expireTime attributes of the PassStatus object of HMS. For building details, please refer to setState(int state).

TextModuleData

In HMS, the TextModuleData object needs to be converted into the AppendField object for use.

The conversion in the Add HMS API and To HMS API scenarios is as follows:

AppendField field = AppendField.getBuilder().setKey("key") // The value of Key can be set randomly but must be unique in the same PassObject.
    .setLabel("TextModuleData.getHeader()")
    .setValue("TextModuleData.getBody()")
    .build();

For details, please refer to addTextModuleData(TextModuleData textModuleData).

TimeInterval

In HMS, the TimeInterval object is no longer supported. The pass validity period can be converted to PassStatus. For details, please refer to setState(int state).

UriData

In HMS, the UriData object needs to be converted into the AppendField object for use.

The conversion in the Add HMS API and To HMS API scenarios is as follows:

AppendField field = AppendField.getBuilder().setKey("key") // The value of Key can be set randomly but must be unique in the same PassObject.
    .setLabel("UriData.getDescription()")
    .setValue("UriData.getUri()")
    .build();

For details, please refer to addImageModuleDataMainImageUri(UriData uriData).

WalletObjectMessage

In HMS, the WalletObjectMessage object needs to be converted into the AppendField object for use.

The conversion in the Add HMS API and To HMS API scenarios is as follows:

AppendField field = AppendField.getBuilder().setKey("key") // The value of Key can be set randomly but must be unique in the same PassObject.
    .setLabel("WalletObjectMessage.getHeader()")
    .setValue("WalletObjectMessage.getBody()")
    .build();

For details, please refer to addMessage(WalletObjectMessage walletObjectMessage).

WalletObjectsClient getWalletObjectsClient(Activity activity, Wallet.WalletOptions options)

Use the following method as a replacement in the To HMS API scenario:

public static WalletPassClient getWalletPassClient(Activity activity);

WalletObjectsConstants

In HMS, the pass status is identified by a string constant, which is defined in the com.huawei.hms.wallet.constant.WalletPassConstant class.

public static final String PASS_STATE_COMPLETED = "completed";
public static final String PASS_STATE_EXPIRED = "expired";
public static final String PASS_STATE_INACTIVE = "inactive";
public static final String PASS_STATE_ACTIVE = "active";

For details, please refer to setState(int state).

getImageModuleDataMainImageUris()

List<com.google.android.gms.wallet.wobs.UriData> getImageModuleDataMainImageUris()

In HMS, no class can completely correspond to UriData. UriData can be replaced by the AppendField class in HMS.

In the To HMS API scenario, the preceding API can be replaced by using the following code:

PassObject passObject = new PassObject(); // Here, new is used only as an example. In actual code, the corresponding PassObject object needs to be obtained.
List<AppendField> imageList = passObject.getImageList();

The return values are different. For details about the mapping between attribute values in AppendField and those in UriData, please refer to addImageModuleDataMainImageUri(UriData uriData).

The following APIs are replaced in a similar way:

getIssuerName()

HMS does not have the corresponding get method. To obtain issuerName, you can modify the code as follows to obtain the attribute value from CommonFIelds of PassObject by using the specified key value.

PassObject passObject = new PassObject(); // Here, new is used only as an example. In actual code, the corresponding PassObject object needs to be obtained.
String issuerName;
List<CommonField> fields = passObject.getCommonField();
for (CommonField field : fields) {
    if (WalletPassConstant.PASS_COMMON_FIELD_KEY_MERCHANT_NAME.equals(field.getKey())) {
        issuerName = field.getValue(); // Obtain the value of issuerName.
        break;
    }
}

The following APIs for obtaining the attribute value can be replaced by using similar code, and only the corresponding key value needs to be used.

In addition, the following two APIs can also use a similar method to obtain the attribute value. The key value is located in AppendField.

PassObject passObject = new PassObject(); // Here, new is used only as an example. In actual code, the corresponding PassObject object needs to be obtained.
String eventNumber;
List<AppendField> fields = passObject.getAppendFields(); // Compared with the preceding example, the getAppendFields() method needs to be called here.
for (AppendField field : fields) {
    if (WalletPassConstant.PASS_APPEND_FIELD_KEY_EVENT_NUMBER.equals(field.getKey())) {
        eventNumber= field.getValue(); // Obtain the value of eventNumber.
        break;
    }
}
  1. The getLoyaltyPoints() method returns the LoyaltyPoints object. However, the LoyaltyPoints object does not have a matching class in HMS, and only the bonus point value is obtained based on the corresponding key value.
  2. For details about how to use the get method, refer to the description about the set method in this document.

getLocations()

List<com.google.android.gms.maps.model.LatLng> getLocations()

In the To HMS API scenario, use the following code to obtain the corresponding information in HMS:

PassObject passObject = new PassObject(); // Here, new is used only as an example. In actual code, the corresponding PassObject object needs to be obtained.
List<Location> locationList = passObject.getLocationList();

The return value is a Location list. Location is an object customized by Wallet Kit. When using this method, you need to adapt the code involving the use of the return value.

getRedemptionCode()

In HMS, no redemption code field is set for the gift card. The value of the redemption code field has been converted into the value of the 1D or 2D barcode. You can obtain the redemption code by referring to java.lang.String getBarcodeType().

getState()

In HMS, the card status and validity period constitute the PassStatus object. Therefore, there is no independent API for obtaining the card status attribute. You can obtain the card status and validity period in the following way:

PassObject passObject = new PassObject(); // Here, new is used only as an example. In actual code, the corresponding PassObject object needs to be obtained.
PassStatus passStatus = passObject.getStatus();
String state = passStatus.getState(); // Card status represented by a character string.
String effectiveTime = passStatus.getEffectTime();  // Pass effective time.
String expireTime = passStatus.getExpireTime();  // Pass expiration time.

For details, please refer to the setState(int state) API description.

getValidTimeInterval()

In HMS, there is no class corresponding to TimeInterval. If you want to obtain the card validity period, please refer to getState().

LoyaltyPointsBalance

No class in HMS corresponds to LoyaltyPointsBalance. In addition, the number of bonus points in HMS is stored as a character string regardless of the data type. Therefore, if you need to use this class in HMS, use the following conversion method.

The conversion in the Add HMS API and To HMS API scenarios is as follows:

Methods for setting bonus points:

public final com.google.android.gms.wallet.wobs.LoyaltyPointsBalance.Builder setInt(int)
public final com.google.android.gms.wallet.wobs.LoyaltyPointsBalance.Builder setDouble(double)
public final com.google.android.gms.wallet.wobs.LoyaltyPointsBalance.Builder setString(java.lang.String)
public final com.google.android.gms.wallet.wobs.LoyaltyPointsBalance.Builder setMoney(java.lang.String,long)

Modify the preceding four methods for setting bonus points as follows:

String label = "Points";
String value = "123";
String currencyCode = "12";// Here, the value is used only as an example. In actual development, the corresponding data is obtained based on the requirements.
PassObject.Builder passBuilder = PassObject.getBuilder();
List<AppendField> fields = new ArrayList<>();
AppendField balance = AppendField.getBuilder()
    .setKey(WalletPassConstant.PASS_APPEND_FIELD_KEY_POINTS)  
    .setValue(value) // value is a character string indicating the number of bonus points.
   .setLabel(label) // label is a character string indicating the label, which is the same as label in LoyaltyPointsBalance.
    .build();
fields.add(balance);
passBuilder.addAppendFields(fields);
// If the number of bonus points is in currency, set the currency code as follows:
passBuilder.setCurrencyCode(currencyCode);

Method for obtaining the number of bonus points:

public final long getCurrencyMicros()
public final double getDouble()
public final int getInt()
public final java.lang.String getString()

Modify the preceding four methods for obtaining the number of bonus points as follows. A character string indicating the number of bonus points is returned.

PassObject passObject = new PassObject(); // Here, new is used only as an example. In actual code, the corresponding PassObject object needs to be obtained.
String loyaltyPoints;
List<AppendField> appendFields = passObject.getAppendFields();
for (AppendField field : appendFields) {
    if (WalletPassConstant.PASS_APPEND_FIELD_KEY_POINTS.equals(field.getKey())) {
       loyaltyPoints = field.getValue(); // Obtain the character string indicating the number of bonus points.
        break;
    }
}

Method for obtaining the currency code:

public final java.lang.String getCurrencyCode()

The getCurrencyCode() method of PassObject can be directly used to obtain the currency code.

PassObject passObject = new PassObject(); // Here, new is used only as an example. In actual code, the corresponding PassObject object needs to be obtained.
String currencyCode = passObject.getCurrencyCode();