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.");
}
using Microsoft.Phone.Wallet;
namespace WAgents
{
public class WAgent : WalletAgent
{
private static volatile bool _classInitialized;
public WAgent()
{
if (!_classInitialized)
{
_classInitialized = true;
// Subscribe to the managed exception handler
Deployment.Current.Dispatcher.BeginInvoke(delegate
{
Application.Current.UnhandledException += ScheduledAgent_UnhandledException;
});
}
}
// Code to execute on Unhandled Exceptions
private void ScheduledAgent_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
System.Diagnostics.Debugger.Break();
}
}
protected override async void OnRefreshData(RefreshDataEventArgs args)
{
// Check if the customers birthday etc…
foreach (WalletItem item in args.Items)
{
WalletTransactionItem WTI = item as WalletTransactionItem;
if (WTI != null)
{
if (WTI.Id == "CoffeeContosoMembershipCard")
{
WTI.Message = "Happy birthday, we have a suprise for you. Tap for details.";
WTI.MessageNavigationUri = new Uri("/mainpage.xaml?ParameterName=[ParameterValue] for wallet agent to app communication.", UriKind.Relative);
//WTI.SetUserAttentionRequiredNotification(true);
await WTI.SaveAsync();
}
}
}
//base.OnRefreshData(args);
NotifyComplete();
}
}
}
Deal DI = new Deal("ContosoDeal");
DI.MerchantName = "Contoso Coffee Corp.";
DI.DisplayName = "Contoso Coffee";
DI.Description = "With the above barcode, within the next 15 days, you can get a free coffee from any of our shops.";
DI.CustomerName = "This deal is offered for [Customer Name]";
DI.ExpirationDate = DateTime.Now.AddDays(15);
DI.IssuerName = "Issuer name of this deal is [Issuer Name]";
DI.IssuerWebsite = new Uri("http://www.issuerwebsite.contoso.com");
DI.NavigationUri = new Uri("/mainpage.xaml?ParameterName=[ParameterValue] for wallet to app communication.", UriKind.Relative);
DI.Notes = "Notes for the customer.";
DI.OfferWebsite = new Uri("http://www.offerwebsite.contoso.com");
DI.TermsAndConditions = "Terms and Conditions of the deal goes here.";
DI.Logo99x99 = GetBitmapSource("Assets/wallet_99x99.png");
DI.Logo159x159 = GetBitmapSource("Assets/wallet_159x159.png");
DI.Logo336x336 = GetBitmapSource("Assets/wallet_336x336.png");
DI.BarcodeImage = GetBitmapSource("Assets/wallet_barcode.png");
await DI.SaveAsync();
添加方法如上
好了相信大家看过之后在 windows phone 8 wallet 如何使用电子钱包已经有了一个了解,欢迎大家在这里和我沟通交流或者在新浪微博上 @王博_Nick