1 out of 1 rated this helpful - Rate this topic

How to use the add Wallet item task for Windows Phone 8

April 14, 2014

Applies to: Windows Phone 8 and Windows Phone Silverlight 8.1 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 8.

To use the add Wallet item task

  1. Add the following statement to your code.

    
    Imports Microsoft.Phone.Tasks
    
    
    
    
    Imports Microsoft.Phone.Wallet
    Imports System.Windows.Media.Imaging
    
    
    
  2. Declare the task object. It must have page scope, so declare it in your page before the constructor.

    
    Dim addWalletItemTask As AddWalletItemTask = New AddWalletItemTask()
    
    
    
  3. 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.

    
    AddHandler addWalletItemTask.Completed, AddressOf addWalletItemTask_Completed
    
    
    
  4. 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.

    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.

    
    
    
            Dim card As PaymentInstrument = New PaymentInstrument("FabrikamBankCard")
            card.DisplayName = "Fabrikam Bank"
            card.CustomerName = "Chris Preston"
            card.ExpirationDate = New DateTime(2014, 12, 15)
            card.PaymentInstrumentKinds = PaymentInstrumentKinds.CreditAndDebit
    
            Dim bmp As BitmapImage = 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
    
            card.Logo99x99 = New BitmapImage(New Uri("/images/BrandImageSmall.png", UriKind.RelativeOrAbsolute))
            card.Logo159x159 = New BitmapImage(New Uri("/images/BrandImageMedium.png", UriKind.RelativeOrAbsolute))
            card.Logo336x336 = New BitmapImage(New Uri("/images/BrandImageLarge.png", UriKind.RelativeOrAbsolute))
    
            addWalletItemTask.Item = card
    
            addWalletItemTask.Show()
    
    
    
    
  5. 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.

    
    void addWalletItemTask_Completed(object sender, AddWalletItemResult e)
    {
        if (e.TaskResult == TaskResult.OK)
        {
            MessageBox.Show(e.Item.Id + " was added to your Wallet");
        } 
    }
    
    
    

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.