/// <summary> /// Tries to fulfill a Gold IAP with the given amount. /// </summary> /// <param name="productLicense">The store product license.</param> private async Task TryFulfillGold(ProductLicense productLicense) { if (productLicense.IsConsumable && productLicense.IsActive) { var receipt = await CurrentAppProxy.RequestProductPurchaseAsync(productLicense.ProductId); // Fulfill on PhotoSharingApp servers var user = await _photoService.FulfillGold(receipt.ReceiptXml); // If previous step was successful, fulfill in Store await CurrentAppProxy.ReportConsumableFulfillmentAsync(productLicense.ProductId, receipt.TransactionId); // Now update local gold balance AppEnvironment.Instance.CurrentUser.GoldBalance = user.GoldBalance; } }
/// <summary> /// Purchases Gold with the given productId. /// </summary> /// <remarks> /// Please see <see cref="InAppPurchases" /> for available /// IAPs. /// </remarks> /// <param name="productId">The productId to purchase.</param> /// <exception cref="InAppPurchaseException">Thrown when an error occurs during purchase.</exception> /// <returns>The task.</returns> public async Task PurchaseGold(string productId) { await _authEnforcementHandler.CheckUserAuthentication(); // Kick off the purchase var purchaseResults = await CurrentAppProxy.RequestProductPurchaseAsync(productId); if (purchaseResults.Status == ProductPurchaseStatus.Succeeded || purchaseResults.Status == ProductPurchaseStatus.NotFulfilled) { await DoFulfillment(); } else { // ProductPurchaseStatus is either AlreadyPurchased or NotPurchased, // while latter implies either user cancellation or other failures. throw new InAppPurchaseException(); } }
public async Task Should_get_correct_RequestProductPurchaseAsync_EXCEPTION_for_INVALID_InAppPurchase() { //arrange var iapConfigFile = await StorageFile.GetFileFromApplicationUriAsync(TestDataUris.InAppPurchaseLicenseUri); await CurrentAppProxy.ReloadSimulatorSettingsAsync(iapConfigFile); //act try { var iapReceipt = await CurrentAppProxy.RequestProductPurchaseAsync("NonExistantFeature", false); } catch (System.ArgumentException) { Assert.IsTrue(true, "PASS"); return; } //assert Assert.Fail(); }