/// <summary> /// Sets when this item is relevant. /// When an item is considered relevant, it will be promoted to the top spot in the Wallet summary view list /// and a toast notifcation will also be shown in a pop-up on the user's phone. /// </summary> /// <returns>An asynchronous action.</returns> public async Task AddRelevancyAsync() { if (walletItem == null) { rootPage.NotifyUser("Item does not exist. Add item using Scenario2", NotifyType.ErrorMessage); return; } try { // For this example, we will clear all relevancy data from the wallet item // to ensure that adding the item below does not fail because it already exists. walletItem.RelevantLocations.Clear(); // Create a new relevant location object. WalletRelevantLocation location = new WalletRelevantLocation(); location.DisplayMessage = "Welcome to Contoso Coffee on 5th"; // Set the desired location. var position = new Windows.Devices.Geolocation.BasicGeoposition(); position.Latitude = 47.63; position.Longitude = -122.2147; location.Position = position; // Add this location to the RelevantLocations collection on the item. // Note: The key for each entry must be unique in the collection. walletItem.RelevantLocations.Add("5thId", location); // Add a relevant date. walletItem.RelevantDate = DateTime.Now; walletItem.RelevantDateDisplayMessage = "Free coffee day"; // Update the item in Wallet. await wallet.UpdateAsync(walletItem); rootPage.NotifyUser("Relevancy data added. Open Wallet to see this card promoted to the top of the list because it is relevant (relevant date was defined as today).", NotifyType.StatusMessage); } catch (Exception ex) { string errorMessage = String.Format("Could not add relevancy data. {0}", ex.Message); rootPage.NotifyUser(errorMessage, NotifyType.ErrorMessage); } }
pkPassConversionResult parsePkpassType(IReadOnlyList<Windows.Storage.StorageFile> files) { try { WalletItem item = null; CurrentInfo = "Opening pass.json..."; JObject o = getJsonData(files.Where(x => x.Name == "pass.json").First()); //Determine the type of the card and return it. if (o["boardingPass"] != null) { pkPassType = "boardingPass"; item = new WalletItem(WalletItemKind.BoardingPass, o["description"].Value<string>()); } else if (o["coupon"] != null) { pkPassType = "coupon"; item = new WalletItem(WalletItemKind.Deal, o["description"].Value<string>()); } else if (o["eventTicket"] != null) { pkPassType = "eventTicket"; item = new WalletItem(WalletItemKind.Ticket, o["description"].Value<string>()); } else if (o["storeCard"] != null) { pkPassType = "storeCard"; item = new WalletItem(WalletItemKind.MembershipCard, o["description"].Value<string>()); } else if (o["generic"] != null) { pkPassType = "generic"; item = new WalletItem(WalletItemKind.General, o["description"].Value<string>()); } else throw new Exception(); //Get images CurrentInfo = "Fetching images..."; item.Logo99x99 = item.Logo159x159 = item.Logo336x336 = getImageFromName("icon.png", contents); item.HeaderBackgroundImage = getImageFromName("logo.png", contents); item.BodyBackgroundImage = getImageFromName("background.png", contents); CurrentInfo = "Fetching colors..."; item.BodyColor = HelperMethods.getColorFromRGBString(o["backgroundColor"].Value<string>()); item.BodyFontColor = HelperMethods.getColorFromRGBString(o["foregroundColor"].Value<string>()); item.HeaderColor = item.BodyColor; item.HeaderFontColor = HelperMethods.getColorFromRGBString(o["labelColor"].Value<string>()); int i = 0; if (o[pkPassType]["primaryFields"] != null) { foreach (JObject jo in o[pkPassType]["primaryFields"]) { WalletItemCustomProperty prop = new WalletItemCustomProperty(jo["label"].Value<string>(), jo["value"].Value<string>()); if (i == 0) prop.DetailViewPosition = WalletDetailViewPosition.PrimaryField1; else if (i == 1) prop.DetailViewPosition = WalletDetailViewPosition.PrimaryField2; else throw new InvalidDataException(); item.DisplayProperties[jo["key"].Value<string>()] = prop; i++; } } //Secondary fields i = 0; if (o[pkPassType]["secondaryFields"] != null) { foreach (JObject jo in o[pkPassType]["secondaryFields"]) { WalletItemCustomProperty prop = new WalletItemCustomProperty(jo["label"].Value<string>(), jo["value"].Value<string>()); if (i == 0) prop.DetailViewPosition = WalletDetailViewPosition.SecondaryField1; else if (i == 1) prop.DetailViewPosition = WalletDetailViewPosition.SecondaryField2; else if (i == 2) prop.DetailViewPosition = WalletDetailViewPosition.SecondaryField3; else if (i == 3) prop.DetailViewPosition = WalletDetailViewPosition.SecondaryField4; else if (i == 4) prop.DetailViewPosition = WalletDetailViewPosition.SecondaryField5; else throw new InvalidDataException(); item.DisplayProperties[jo["key"].Value<string>()] = prop; i++; } } //Auxiliary fields i = 0; if (o[pkPassType]["auxiliaryFields"] != null) { foreach (JObject jo in o[pkPassType]["auxiliaryFields"]) { WalletItemCustomProperty prop = new WalletItemCustomProperty(jo["label"].Value<string>(), jo["value"].Value<string>()); if (i == 0) prop.DetailViewPosition = WalletDetailViewPosition.FooterField1; else if (i == 1) prop.DetailViewPosition = WalletDetailViewPosition.FooterField2; else if (i == 2) prop.DetailViewPosition = WalletDetailViewPosition.FooterField3; else if (i == 3) prop.DetailViewPosition = WalletDetailViewPosition.FooterField4; else throw new InvalidDataException(); item.DisplayProperties[jo["key"].Value<string>()] = prop; i++; } } //Header fields i = 0; if (o[pkPassType]["headerFields"] != null) { foreach (JObject jo in o[pkPassType]["headerFields"]) { WalletItemCustomProperty prop = new WalletItemCustomProperty(jo["label"].Value<string>(), jo["value"].Value<string>()); if (i == 0) prop.DetailViewPosition = WalletDetailViewPosition.HeaderField1; else if (i == 1) prop.DetailViewPosition = WalletDetailViewPosition.HeaderField2; else throw new InvalidDataException(); item.DisplayProperties[jo["key"].Value<string>()] = prop; i++; } } //Header fields if (o[pkPassType]["backFields"] != null) { foreach (JObject jo in o[pkPassType]["backFields"]) { WalletItemCustomProperty prop = new WalletItemCustomProperty(jo["label"].Value<string>(), jo["value"].Value<string>()); prop.SummaryViewPosition = WalletSummaryViewPosition.Hidden; item.DisplayProperties[jo["key"].Value<string>()] = prop; } } if (o["barcode"] != null) { WalletBarcodeSymbology sym = new WalletBarcodeSymbology(); switch (o["barcode"]["format"].Value<string>()) { case "PKBarcodeFormatQR": sym = WalletBarcodeSymbology.Qr; break; case "PKBarcodeFormatPDF417": sym = WalletBarcodeSymbology.Pdf417; break; case "PKBarcodeFormatAztec": sym = WalletBarcodeSymbology.Aztec; break; default: throw new InvalidDataException(); } item.Barcode = new WalletBarcode(sym, o["barcode"]["message"].Value<string>()); } if (o["locations"] != null) { i = 0; foreach (JObject jo in o["locations"]) { WalletRelevantLocation location = new WalletRelevantLocation(); if (jo["relevantText"] != null) { location.DisplayMessage = jo["relevantText"].Value<string>(); } var position = new Windows.Devices.Geolocation.BasicGeoposition(); position.Latitude = jo["latitude"].Value<double>(); position.Longitude = jo["longitude"].Value<double>(); try { position.Altitude = jo["altitude"].Value<double>(); } catch (Exception) { System.Diagnostics.Debug.WriteLine("An altitude does not exist for location " + location.DisplayMessage); } location.Position = position; //Check one doesn't already exist. if (item.RelevantLocations.Where(x => x.Key == i.ToString()).Count() > 0) i++; else item.RelevantLocations.Add(i.ToString(), location); i++; } } if (o["relevantDate"] != null) { item.RelevantDate = DateTime.Parse(o["relevantDate"].Value<string>()); } if (o["expirationDate"] != null) { item.ExpirationDate = DateTime.Parse(o["expirationDate"].Value<string>()); } string cardId = o["serialNumber"].Value<string>(); pkPassConversionResult result = new pkPassConversionResult(); result.item = item; result.cardId = cardId; return result; } catch (Exception ex) { CurrentInfo = "Exception: " + ex.Message; return null; } }