歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Windows Phone 8 Wallet 手機錢包 / 電子錢包

Windows Phone 8 Wallet 手機錢包 / 電子錢包

日期:2017/3/1 9:53:51   编辑:Linux編程

手機錢包是windows phone 8中的新特性之一,在這裡先給大家聲明一下 因為有很多合作伙伴對錢包功能有一個“誤解” - 錢包功能不開放 只能做支付其實不然, 目前來說手機錢包主要分為幾個功能點 ,卡片管理 \ 支付功能 \ NFC進場通信通訊交易

其中 NFC 近場通訊交易 - security payment 是依賴於運用商的在這裡不做過多介紹,手機錢包 支付功能 目標國內支持 ailpay (支付寶) 可以進行 應用購買以及應用內支付,這在我們的SDK中都是相應API 這部分內容我會放到 應用內支付(購買)一節中給大家介紹,今天我著重介紹卡片管理功能,卡片管理主要分為 銀行卡(信用卡/儲蓄卡)、會員卡、以及優惠劵的管理下面我會逐一介紹:

windows phone wallet (電子錢包) 可以為你的應用提供一個全新的用戶信息展示平台展示,並且這個平台更加的自然貼近用戶的使用習慣,在細節上討好用戶,在wallet中可以展示帶有圖logo片及連接的卡片項,你可以為這些卡片選擇deep link到應用中 並且可以使用後台的 wallet agent 進行數據同步。

此文是 升級到WP8必需知道的13個特性 系列的一個更新 希望這個系列可以給 Windows Phone 8開發者帶來一些開發上的便利。

升級到WP8必需知道的13個特性 系列文章目錄地址:http://www.linuxidc.com/Linux/2013-08/89003.htm

1. 聲明權限

和其他新特性一樣 wallet 也需要在Manifest中聲明 我這裡是因為後面要進行應用內支付的 code 所以在選擇了 wallet 的基礎上又選擇了 payment in struments

2.銀行卡

銀行卡分為信用卡和借記卡

在創建的時候有以下幾種選擇標記

在對 WalletItem進行操作時候首先是要介紹 AddWalletItemTask 對象,使用他進行卡片的添加操作在Completed 的時候進行判斷操作是否成功。

 // Constructor
        public MainPage()
        {
            InitializeComponent();

            AWIT.Completed += AWIT_Completed;
        }

        static AddWalletItemTask AWIT = new AddWalletItemTask();

        void AWIT_Completed(object sender, AddWalletItemResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                MessageBox.Show(e.Item.DisplayName + " operation successful.");
            }
            else
            {
                MessageBox.Show(e.Item.DisplayName + " Error: " + e.Error.Message);
            }
        }

每一張卡片對應一個 PaymentInstrument 對象其中包含各種信息包括 deeplink 的URL 圖片Logo

                PaymentInstrument PI;
                PI = new PaymentInstrument("Contoso Credit Account");
                PI.PaymentInstrumentKinds = PaymentInstrumentKinds.Credit;
                PI.IssuerName = publisher.Name;
                PI.DisplayName = publisher.Name + " Payment Card";
                PI.IssuerPhone.Business = publisher.TelNo;
                PI.CustomerName = member.Name;
                PI.AccountNumber = member.MembershipNumber;
                PI.BillingPhone = member.TelNo;
                PI.IssuerWebsite = new Uri(publisher.WebSite);
                PI.ExpirationDate = member.ExpirationDate;
                PI.NavigationUri = new Uri("/mainpage.xaml?ParameterName=[ParameterValue] for wallet to app communication.", UriKind.Relative);

                PI.DisplayCreditLimit = member.CreditLimit.ToString();
                PI.DisplayAvailableCredit = member.AvailableLimit.ToString();

                PI.Logo99x99 = GetBitmapSource("Assets/wallet_99x99.png");
                PI.Logo159x159 = GetBitmapSource("Assets/wallet_159x159.png");
                PI.Logo336x336 = GetBitmapSource("Assets/wallet_336x336.png");
                                                
                AWIT.Item = PI;
                AWIT.Show();

上面可以看到設置了三種不同大小的Logo 是因為會在不同的地方使用到 例如當你的卡片pin到主屏的時候

既然是消費類型的卡就有消費記錄的存在 在我們的錢包中自然就有交易記錄

添加一條記錄的方法如下,這裡提一下 wallet 也是獨立應用的 使用Wallet的時候 找卡僅限於當前應用是不允許找其他應用的卡片信息的 原因大家都懂的,當然也可以使用 WalletAgent 進行實時更新。

Random RandomPayment = new Random();

        async private void btnCreatePaymentTrans_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            // Find the payment instrument to use 
            PaymentInstrument PI;

            PI = Wallet.FindItem("Contoso Credit Account") as PaymentInstrument;

            if (PI == null)
            {
                MessageBox.Show("Payment Card [Credit Account] not found on the wallet.");
                return;
            }

            // Create the transaction
            WalletTransaction transaction = new WalletTransaction();

            transaction.DisplayAmount = RandomPayment.Next(50, 500).ToString();

            transaction.Description = "Random online payment";
            transaction.TransactionDate = DateTime.Now;

            // Add the transaction to the wallet
            PI.TransactionHistory.Add("Internet payment " + DateTime.Now, transaction);

            await PI.SaveAsync();

            MessageBox.Show("Succesfully made a random payment. Check your wallet to see the transactions.");
        }
Copyright © Linux教程網 All Rights Reserved