private async void donateButton_Click(object sender, RoutedEventArgs e) { PurchaseResults purchaseResults = await CurrentApp.RequestProductPurchaseAsync(ProductKey); switch (purchaseResults.Status) { case ProductPurchaseStatus.Succeeded: int count = UpdateAndGetDonationCount(); await CurrentApp.ReportConsumableFulfillmentAsync(ProductKey, purchaseResults.TransactionId); MessageDialog msgDialog; if (count > 1) { msgDialog = new MessageDialog(string.Format("这已经是您的第{0}次打赏了,真是万分感谢!")); } else { msgDialog = new MessageDialog("感谢您的打赏!您随时可以再次打赏哟!"); } await msgDialog.ShowAsync(); break; case ProductPurchaseStatus.NotFulfilled: await CurrentApp.ReportConsumableFulfillmentAsync(ProductKey, purchaseResults.TransactionId); msgDialog = new MessageDialog ("不好意思,您上次的打赏似乎出了点问题,但现在已经解决了。您现在可以再次打赏了。"); await msgDialog.ShowAsync(); break; } }
private async void FulfillProduct(string productId, Guid transactionId) { try { FulfillmentResult result = await IAPs.ReportConsumableFulfillmentAsync(productId, transactionId); switch (result) { case FulfillmentResult.Succeeded: break; case FulfillmentResult.NothingToFulfill: //rootPage.NotifyUser("There is no purchased product 1 to fulfill.", NotifyType.StatusMessage); break; case FulfillmentResult.PurchasePending: //rootPage.NotifyUser("You bought product 1. The purchase is pending so we cannot fulfill the product.", NotifyType.StatusMessage); break; case FulfillmentResult.PurchaseReverted: //rootPage.NotifyUser("You bought product 1, but your purchase has been reverted.", NotifyType.StatusMessage); // Since the user's purchase was revoked, they got their money back. // You may want to revoke the user's access to the consumable content that was granted. break; case FulfillmentResult.ServerError: //rootPage.NotifyUser("You bought product 1. There was an error when fulfilling.", NotifyType.StatusMessage); break; } } catch (Exception) { //rootPage.NotifyUser("You bought Product 1. There was an error when fulfilling.", NotifyType.ErrorMessage); } ResourceLoader resource = ResourceLoader.GetForCurrentView(); var dlg = DialogHelper.GetSimpleContentDialog( resource.GetString("IAPs/Donation/Thanks/Title"), resource.GetString("IAPs/Donation/Thanks/Content"), resource.GetString("Button/Ok/Content")); await dlg.ShowAsync(); App.ContentDlgOp = null; }