public static RequestProductPurchaseAsync ( [ productId, [ includeReceipt ) : IAsyncOperation |
||
productId | [ | |
includeReceipt | [ | |
return | IAsyncOperation |
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; } }
/// <summary> /// Attempts to execute an in-app purchase of the indicated item. /// </summary> /// <param name="selectedProductListing">The selected product listing.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">selectedProductListing</exception> public async Task <PurchaseResults> PurchaseItem(ProductListing selectedProductListing) { if (selectedProductListing == null) { throw new ArgumentNullException("selectedProductListing"); } try { var result = await CurrentApp.RequestProductPurchaseAsync(selectedProductListing.ProductId); return(result); } catch (System.Runtime.InteropServices.COMException comException) { // Happens with E_FAIL throw new InvalidOperationException("In-app purchase failed with a COM exception.", comException); } catch (ArgumentException argumentException) { // Happens with E_INVALIDARG result throw new InvalidOperationException("In-app purchase failed with an argument exception.", argumentException); } catch (OutOfMemoryException outOfMemoryException) { // Happens with E_OUTOFMEMORY result throw new InvalidOperationException("In-app purchase failed with an out of memory exception.", outOfMemoryException); } }
public async void Donate(string productId) { string title = null; string msg = null; try { PurchaseResults purchaseResults = await IAPs.RequestProductPurchaseAsync(productId); switch (purchaseResults.Status) { case ProductPurchaseStatus.Succeeded: //GrantFeatureLocally(purchaseResults.TransactionId); FulfillProduct(productId, purchaseResults.TransactionId); break; case ProductPurchaseStatus.NotFulfilled: // The purchase failed because we haven't confirmed fulfillment of a previous purchase. // Fulfill it now. //if (!IsLocallyFulfilled(purchaseResults.TransactionId)) //{ // GrantFeatureLocally(purchaseResults.TransactionId); //} FulfillProduct(productId, purchaseResults.TransactionId); break; case ProductPurchaseStatus.NotPurchased: //rootPage.NotifyUser("Product 1 was not purchased.", NotifyType.StatusMessage); title = "IAPs/Purchase/Failed/Title"; msg = "IAPs/Purchase/Failed/Content"; break; } } catch (Exception) { //rootPage.NotifyUser("Unable to buy Product 1.", NotifyType.ErrorMessage); title = "IAPs/Purchase/Failed/Title"; msg = "IAPs/Purchase/Failed/Content"; } if (title != null && msg != null) { ResourceLoader resource = ResourceLoader.GetForCurrentView(); var dlg = DialogHelper.GetSimpleContentDialog( resource.GetString(title), resource.GetString(msg), resource.GetString("Button/Ok/Content")); await dlg.ShowAsync(); App.ContentDlgOp = null; } }