Overview
PassObject loyaltyObject = PassObject.getBuilder().setSerialNumber("12345")
.addImageList(new ArrayList<>())
//... Add other settings as required.
.build(); 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); For details about how to convert this method in the To HMS API scenario, please refer to addInfoModuleDataLabeValueRow(LabelValueRow row).
The conversion in the To HMS API scenario is as follows:
The uri and description attributes of the UriData type correspond to the value and label attributes of AppendField in HMS respectively. Convert the uriData parameter into image of the AppendField type. The value of key can be specified but must be unique. Build an ArrayList<AppendField> imageList, put image into imageList, and use the addImageList() method of PassObject to assign imageList to the PassObject object.
UriData uriData = new UriData("www.huaweitest.com", "huawei net");// Here, new is used only as an example. In actual code, the corresponding UriData object needs to be obtained.
PassObject.Builder passBuilder = PassObject.getBuilder();
ArrayList<AppendField> imageList = new ArrayList<>();
AppendField.Builder image = AppendField.getBuilder();
AppendField imageField = image.setKey("image" + image.hashCode())
.setValue(uriData.getUri())
.setLabel(uriData.getDescription())
.build();
imageList.add(imageField);
passBuilder.addImageList(imageList); For details about how to convert this method in the To HMS API scenario, please refer to addImageModuleDataMainImageUri(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); For details about how to convert this method in the Add HMS API and To HMS API scenarios, please refer to addLinksModuleDataUri(UriData uriData).
The conversion in the To HMS API scenario is as follows:
The longitude and latitude attributes of the LatLng type correspond to the longitude and latitude attributes of Location in HMS respectively. Convert the latLng parameter into the location parameter of the Location type. Build an ArrayList<Location> locations, pass location to locations, and use the addLocationList() method of the PassObject object to assign the value of locations to the PassObject object.
LatLng latLng = new LatLng(22.545167,114.056641);// Here, new is used only as an example. In actual code, the corresponding LatLng object needs to be obtained. PassObject.Builder passBuilder = PassObject.getBuilder(); ArrayList<Location> locations = new ArrayList<>(); Location location = new Location(String.valueOf(latLng.getLongitude()), String.valueOf(latLng.getLatitude())); locations.add(location); passBuilder.addLocationList(locations);
For details about how to convert this method in the To HMS API scenario, please refer to addLocation(LatLng latLng).
The conversion in the To HMS API scenario is as follows:
The body and header attributes of the WalletObjectMessage type correspond to the value and label attributes of AppendField in HMS respectively. Convert the walletObjectMessage parameter into field of the AppendField type. The value of key can be specified but must be unique. Build an ArrayList<AppendField> messageList, put field into messageList, and use the addMessageList() method of the PassObject object to assign the value of messageList to the PassObject object.
WalletObjectMessage walletObjectMessage = WalletObjectMessage.newBuilder()
.setHeader("Hi Jane!")
.setBody("Thanks for saving your gift card.")
.build();
PassObject.Builder passBuilder = PassObject.getBuilder();
ArrayList<AppendField> messageList = new java.util.ArrayList<>();
AppendField.Builder message = AppendField.getBuilder();
AppendField field = message.setKey("message" + message.hashCode())
.setValue(walletObjectMessage.getBody())
.setLabel(walletObjectMessage.getHeader())
.build();
messageList.add(field);
passBuilder.addMessageList(messageList); For details about how to convert this method in the To HMS API scenario, please refer to addMessage(WalletObjectMessage walletObjectMessage).
The conversion in the To HMS API scenario is as follows:
The body and header attributes of the TextModuleData type correspond to the value and label attributes of AppendField in HMS respectively. Convert the textModuleData parameter into textData of the AppendField type. The value of key can be specified but must be unique. Build an ArrayList<AppendField> textDataList, put textData into textDataList, and use the addTextList() method of PassObject to assign textDataList to the PassObject object.
TextModuleData textModuleData =new TextModuleData("Header", "Use your gift card when you purchase your next bacon fat latte!");
PassObject.Builder passBuilder = PassObject.getBuilder();
ArrayList<AppendField> textDataList = new java.util.ArrayList<>();
AppendField.Builder textDataBuilder = AppendField.getBuilder();
AppendField textData = textDataBuilder.setKey("text" + textDataBuilder.hashCode())
.setValue(textModuleData.getBody())
.setLabel(textModuleData.getHeader())
.build();
textDataList.add(textData);
passBuilder.addTextList(textDataList); For details about how to convert this method in the To HMS API scenario, please refer to addTextModuleData(TextModuleData textModuleData).
Before calling build to create a request, perform the following steps:
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:
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);
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.
((com.huawei.hms.wallet.pass.PassObject.Builder) wob.getHInstance()).setPassTypeIdentifier("hwpass.type.offer.hmspublic"); Note: wob is an object instance of PassObject.
PassObject.Builder passBuilder = PassObject.getBuilder();
passBuilder.setPassTypeIdentifier("hwpass.type.offer.hmspublic"); 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();
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();
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();
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).
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).
The conversion in the To HMS API scenario is as follows:
Build a CommonField object field. Set the value of key to PASS_COMMON_FIELD_KEY_CARD_NUMBER (value: "cardNumber") and the value of value to the value of accountId. Build an ArrayList<CommonField> idList and add field to idList. Use the addCommonFields() method of the PassObject object to assign the value of idList to the PassObject object and assign the value of accountId to the organizationPassId attribute of the PassObject object.
String accountId = "123";// You need to set accountId.
PassObject.Builder passBuilder = PassObject.getBuilder();
ArrayList<CommonField> idList = new ArrayList<>();
CommonField field = CommonField.getBuilder().setKey(WalletPassConstant.PASS_COMMON_FIELD_KEY_CARD_NUMBER)
.setValue(accountId)
.build();
idList.add(field);
passBuilder.addCommonFields(idList)
.setOrganizationPassId(accountId); // The value of accountId needs to be assigned to passId. The conversion in the To HMS API scenario is as follows:
Build a CommonField object field. Set the value of key to PASS_COMMON_FIELD_KEY_MEMBER_NAME (value: "memberName") and the value of value to the value of accountName. Build an ArrayList<CommonField> accountNameList and add field to accountNameList. Use the addCommonFields() method of the PassObject object to assign the value of accountNameList to the PassObject object.
String accountName = "Jane";// You need to set accountName.
PassObject.Builder passBuilder = PassObject.getBuilder();
ArrayList<CommonField> accountNameList = new ArrayList<>();
CommonField field = CommonField.getBuilder().setKey(WalletPassConstant.PASS_COMMON_FIELD_KEY_MEMBER_NAME)
.setValue(accountName)
.build();
accountNameList.add(field);
passBuilder.addCommonFields(accountNameList); The conversion in the To HMS API scenario is as follows:
Build a CommonField object balance. Set the value of key to PASS_COMMON_FIELD_KEY_BALANCE (value: "balance") and the value of value to the value of balanceMicros. Build an ArrayList<CommonField> balanceMicrosList and add balance to balanceMicrosList. Use the addCommonFields() method of the PassObject object to assign the value of balanceMicrosList to the PassObject object.
long balanceMicros = 1;// You need to set balance.
PassObject.Builder passBuilder = PassObject.getBuilder();
ArrayList<CommonField> balanceMicrosList = new ArrayList<>();
CommonField balance = CommonField.getBuilder()
.setKey(WalletPassConstant.PASS_COMMON_FIELD_KEY_BALANCE)
.setValue(String.valueOf(balanceMicros))
.build();
balanceMicrosList.add(balance);
passBuilder.addCommonFields(balanceMicrosList); The conversion in the To HMS API scenario is as follows:
Build a CommonField object field. Set the value of key to PASS_COMMON_FIELD_KEY_BALANCE_REFRESH_TIME (value: "balanceRefreshTime") and the value of value to the value of balanceUpdateTime. Build an ArrayList<CommonField> balanceUpdateTimeList and add field to balanceUpdateTimeList. Use the addCommonFields() method of the PassObject object to assign the value of balanceUpdateTimeList to the PassObject object.
long balanceUpdateTime = 160509291;// You need to set balanceRefreshTime, for example, 2020-11-11 11:08:35.
PassObject.Builder passBuilder = PassObject.getBuilder();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
String time = format.format(new Date(balanceUpdateTime));
ArrayList<CommonField> balanceUpdateTimeList = new ArrayList<>();
CommonField field = CommonField.getBuilder()
.setKey(WalletPassConstant.PASS_COMMON_FIELD_KEY_BALANCE_REFRESH_TIME)
.setValue(time)
.build();
balanceUpdateTimeList.add(field);
passBuilder.addCommonFields(balanceUpdateTimeList); 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); For details, please refer to setBarcodeAlternateText(String barcodeAlternate).
For details, please refer to setBarcodeAlternateText(String barcodeAlternate).
Conversion is needed only for gift cards.
The conversion in the To HMS API scenario is as follows:
Build a CommonField object field. Set the value of key to PASS_COMMON_FIELD_KEY_CARD_NUMBER (value: "cardNumber") and the value of value to the value of cardNumber. Build an ArrayList<CommonField> cardNumberList and add field to cardNumberList. Use the addCommonFields() method of the PassObject object to assign the value of cardNumberList to the PassObject object, and use the setOrganizationPassId method to assign the value of cardNumber to the PassObject object.
String cardNumber = "abc123";// You need to set cardNumber.
PassObject.Builder passBuilder = PassObject.getBuilder();
ArrayList<CommonField> cardNumberList = new ArrayList<>();
CommonField field = CommonField.getBuilder()
.setKey(WalletPassConstant.PASS_COMMON_FIELD_KEY_CARD_NUMBER)
.setValue(cardNumber)
.build();
cardNumberList.add(field);
passBuilder.addCommonFields(cardNumberList).setOrganizationPassId(cardNumber); // The gift card number is also used as a parameter value assigned to passId. passId must be set in HMS. The conversion in the To HMS API scenario is as follows:
Build an AppendField object field. Set the value of key to PASS_APPEND_FIELD_KEY_EVENT_NUMBER (value: "eventNumber") and the value of value to the value of eventNumber. Build an ArrayList<AppendField> eventNumberList and add field to eventNumberList. Use the addAppendFields() method of the PassObject object to assign the value of eventNumberList to the PassObject object.
String eventNumber = "eventNumber1";// You need to transfer the value of eventNumber.
ArrayList<AppendField> eventNumberList = new ArrayList<>();
AppendField field = AppendField.getBuilder()
.setKey(WalletPassConstant.PASS_APPEND_FIELD_KEY_EVENT_NUMBER)
.setValue(eventNumber)
.build();
eventNumberList.add(field);
PassObject.Builder passBuilder = PassObject.getBuilder();
passBuilder.addAppendFields(eventNumberList); 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);
The conversion in the To HMS API scenario is as follows:
Build a CommonField object field. Set the value of key to PASS_COMMON_FIELD_KEY_MERCHANT_NAME (value: "merchantName") and the value of value to the value of merchantName. Build an ArrayList<CommonField> issuerNameList and add field to issuerNameList. Use the addCommonFields() method of the PassObject object to assign the value of issuerNameList to the PassObject object.
String merchantName = "merchantName";// You need to set merchantName.
PassObject.Builder passBuilder = PassObject.getBuilder();
ArrayList<CommonField> issuerNameList = new ArrayList<>();
CommonField field = CommonField.getBuilder().setKey(WalletPassConstant.PASS_COMMON_FIELD_KEY_MERCHANT_NAME)
.setValue(merchantName)
.build();
issuerNameList.add(field);
passBuilder.addCommonFields(issuerNameList); The conversion in the To HMS API scenario is as follows:
Build an AppendField object balance. Set the value of key to PASS_APPEND_FIELD_KEY_POINTS (value: "points"), and the values of value and label to the values of value and label of the loyaltyPointsBalance attribute in the loyaltyPoints object. Build an ArrayList<AppendField> balanceList and add balance to balanceList. Use the addAppendFields() method of the PassObject object to assign the value of balanceList to the PassObject object. If the bonus point type is currency, you need to use the setCurrencyCode() method of PassObject.Builder to set the currency type.
HMS does not have a class corresponding to LoyaltyPointsBalance. Therefore, you need to assign the values of label and Value in LoyaltyPointsBalance to the PassObject object of the HMS.
LoyaltyPoints loyaltyPoints = LoyaltyPoints.newBuilder().build(); // Here, new is used only as an example. In actual code, the corresponding LoyaltyPoints object needs to be obtained.
PassObject.Builder passBuilder = PassObject.getBuilder();
LoyaltyPointsBalance gBalance = loyaltyPoints.getBalance();
int balanceType = gBalance.getType();
String value = "";
if (balanceType == LoyaltyPointsBalance.Type.getDOUBLE())
{
value = String.valueOf(gBalance.getDouble());
} else if (balanceType == LoyaltyPointsBalance.Type.getINT()) {
value = String.valueOf(gBalance.getInt());
} else if (balanceType == LoyaltyPointsBalance.Type.getSTRING()) {
value = gBalance.getString();
} else if (balanceType == LoyaltyPointsBalance.Type.getMONEY()) {
value = String.valueOf(gBalance.getCurrencyMicros());
passBuilder.setCurrencyCode(gBalance.getCurrencyCode());
}
ArrayList<AppendField> balanceList = new ArrayList<>();
AppendField balance = AppendField.getBuilder().setKey(WalletPassConstant.PASS_APPEND_FIELD_KEY_POINTS)
.setValue(value)
.setLabel(loyaltyPoints.getLabel())
.build();
balanceList.add(balance);
passBuilder.addAppendFields(balanceList); The conversion in the To HMS API scenario is as follows:
Build a CommonField object field. Set the value of key to PASS_COMMON_FIELD_KEY_BLANCE_PIN (value: "pin") and the value of value to the value of pin. Build an ArrayList<CommonField> pinList and add field to pinList. Use the addCommonFields() method of the PassObject object to assign the value of pinList to the PassObject object.
String pin = "pinValue"; // You need to set pin.
ArrayList<CommonField> pinList = new ArrayList<>();
CommonField field = CommonField.getBuilder()
.setKey(WalletPassConstant.PASS_COMMON_FIELD_KEY_BLANCE_PIN)
.setValue(pin)
.build();
pinList.add(field);
PassObject.Builder passBuilder = PassObject.getBuilder();
passBuilder.addCommonFields(pinList); The conversion in the To HMS API scenario is as follows:
Build a CommonField object field. Set the value of key to PASS_COMMON_FIELD_KEY_NAME (value: "name") and the value of value to the value of programName. Build an ArrayList<CommonField> issuerNameList and add field to programNameList. Use the addCommonFields() method of the PassObject object to assign the value of programNameList to the PassObject object.
String programName = "programName"; // You need to set programName.
PassObject.Builder passBuilder = PassObject.getBuilder();
ArrayList<CommonField> programNameList = new ArrayList<>();
CommonField field = CommonField.getBuilder()
.setKey(WalletPassConstant.PASS_COMMON_FIELD_KEY_NAME)
.setValue(programName)
.build();
programNameList.add(field);
passBuilder.addCommonFields(programNameList); 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.
The conversion in the To HMS API scenario is as follows:
Build a CommonField object field. Set the value of key to PASS_COMMON_FIELD_KEY_NAME (value: "name") and the value of value to the value of title. Build an ArrayList<CommonField> titleList and add field to titleList. Use the addCommonFields() method of the PassObject object to assign the value of titleList to the PassObject object.
String title = "title";// You need to set title.
PassObject.Builder passBuilder = PassObject.getBuilder();
ArrayList<CommonField> titleList = new ArrayList<>();
CommonField field = CommonField.getBuilder()
.setKey(WalletPassConstant.PASS_COMMON_FIELD_KEY_NAME)
.setValue(title)
.build();
titleList.add(field);
passBuilder.addCommonFields(titleList); 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).
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).
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).
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).
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).
Use the following method as a replacement in the To HMS API scenario:
public static WalletPassClient getWalletPassClient(Activity activity);
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).
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:
You can use the following code for replacement:
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> messageList = passObject.getMessageList();
The return values are different. For details about the mapping between attribute values in AppendField and those in WalletObjectMessage, please refer to addMessage(WalletObjectMessage walletObjectMessage).
You can use the following code for replacement:
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> messageList = passObject.getTextList();
The return values are different. For details about the mapping between attribute values in AppendField and those in TextModuleData, please refer to addTextModuleData(TextModuleData textModuleData).
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.
API | Key Value |
|---|---|
getAccountId() | |
getAccountName() | |
getBalanceMicros() | |
getBalanceUpdateTime() | WalletPassConstant.PASS_COMMON_FIELD_KEY_BALANCE_REFRESH_TIME |
getCardNumber() | |
getPin() | |
getProgramName() | |
getTitle() |
In addition, the following two APIs can also use a similar method to obtain the attribute value. The key value is located in AppendField.
API | Key Value |
|---|---|
getEventNumber() | |
getLoyaltyPoints() |
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;
}
}
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.
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().
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.
In HMS, there is no class corresponding to TimeInterval. If you want to obtain the card validity period, please refer to getState().
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();