How to use the add Wallet item task for Windows Phone
December 04, 2013
Applies to: Windows Phone 8 only
Use the add Wallet item task to launch the Wallet application and allow the user to add the supplied item to his or her Wallet. If the user completes the task, an event is raised and the event handler receives an TaskResult value indicating whether the item was successfully added to the Wallet. This is the only way for apps to add a PaymentInstrument or a WalletTransactionItem. To add a Deal, use the SaveAsync() method. For more information on creating applications that use Wallet, see Wallet for Windows Phone 8.
By using Choosers, you help provide a consistent user experience throughout the Windows Phone platform. For more information, see Launchers and Choosers for Windows Phone.
To use the add Wallet item task
Add the following statement to your code.
Declare the task object. It must have page scope, so declare it in your page before the constructor.
Add the following code to your page constructor. This code initializes the task object, and identifies the method to run after the user completes the task.
Instantiate one of the supported objects that inherit from WalletItem and set the Item property of the AddWalletItemTask object. Only PaymentInstrument and WalletTransactionItem objects are supported for this chooser. The following properties must be set before calling AddWalletItemTask.Show or an InvalidOperationException will be thrown.
Wallet Item Type
Add the following code to your application wherever you need it, such as in a button click event. To test this procedure, you can put the code in the page constructor. This is the code to launch the task.
PaymentInstrument card = new PaymentInstrument("FabrikamBankCard"); card.DisplayName = "Fabrikam Bank"; card.CustomerName = "Chris Preston"; card.ExpirationDate = new DateTime(2014, 12, 15); card.PaymentInstrumentKinds = PaymentInstrumentKinds.CreditAndDebit; BitmapImage bmp = new BitmapImage(new Uri("/images/BrandImageSmall.png", UriKind.RelativeOrAbsolute)); bmp.CreateOptions = BitmapCreateOptions.None; card.Logo99x99 = bmp; bmp = new BitmapImage(new Uri("/images/BrandImageMedium.png", UriKind.RelativeOrAbsolute)); bmp.CreateOptions = BitmapCreateOptions.None; card.Logo159x159 = bmp; bmp = new BitmapImage(new Uri("/images/BrandImageLarge.png", UriKind.RelativeOrAbsolute)); bmp.CreateOptions = BitmapCreateOptions.None; card.Logo336x336 = bmp; addWalletItemTask.Item = card; addWalletItemTask.Show();
Add the code for the completed event handler to your page. This code runs after the user completes the task. The result is an AddWalletItemResult object that contains the name and address of the contact.