public async Task Should_get_price_and_currency_for_in_app_purchases() { //arrange var freeAppConfigFile = await StorageFile.GetFileFromApplicationUriAsync(TestDataUris.InAppPurchaseLicenseUri); await CurrentAppProxy.ReloadSimulatorSettingsAsync(freeAppConfigFile); //act var productListingWithIAPs = await CurrentAppProxy.LoadListingInformationAsync(); //assert Assert.IsNotNull(productListingWithIAPs); Assert.AreEqual(3, productListingWithIAPs.ProductListings.Count); //assert MarkedUpExtraFeature var markedUpExtraFeature = productListingWithIAPs.ProductListings.FirstOrDefault(x => x.Key == "MarkedUpExtraFeature").Value; Assert.IsNotNull(markedUpExtraFeature); Assert.AreEqual("MarkedUpExtraFeature", markedUpExtraFeature.Name); Assert.AreEqual("$1.99", markedUpExtraFeature.FormattedPrice); //assert MarkedUpPremiumFeature var markedUpPremiumFeature = productListingWithIAPs.ProductListings.FirstOrDefault(x => x.Key == "MarkedUpPremiumFeature").Value; Assert.IsNotNull(markedUpPremiumFeature); Assert.AreEqual("MarkedUpPremiumFeature", markedUpPremiumFeature.Name); Assert.AreEqual("$4.99", markedUpPremiumFeature.FormattedPrice); //assert SomeOtherFeature var someOtherFeature = productListingWithIAPs.ProductListings.FirstOrDefault(x => x.Key == "SomeOtherFeature").Value; Assert.IsNotNull(someOtherFeature); Assert.AreEqual("SomeOtherFeature", someOtherFeature.Name); Assert.AreEqual("$14.99", someOtherFeature.FormattedPrice); }
/// <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(); _telemetryClient.TrackEvent(TelemetryEvents.PurchaseGoldInitiated, TelemetryProperties.ProductId, productId); // Kick off the purchase var purchaseResults = await CurrentAppProxy.RequestProductPurchaseAsync(productId); _telemetryClient.TrackEvent(TelemetryEvents.PurchaseGoldPurchaseResultsAvailable, new Dictionary <string, string> { { TelemetryProperties.ProductId, productId }, { TelemetryProperties.PurchaseStatus, purchaseResults.Status.ToString() } }); 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(); } }
/// <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; _telemetryClient.TrackEvent(TelemetryEvents.PurchaseGoldSuccess); } else { _telemetryClient.TrackEvent(TelemetryEvents.PurchaseGoldFail, new Dictionary <string, string> { { TelemetryProperties.ProductId, productLicense.ProductId } }); } }
public async Task Should_get_correct_AppPurchaseAsync_result() { //arrange var premiumAppFile = await StorageFile.GetFileFromApplicationUriAsync(TestDataUris.TrialLicenseFileUri); await CurrentAppProxy.ReloadSimulatorSettingsAsync(premiumAppFile); //act var iapReceipt = await CurrentAppProxy.RequestAppPurchaseAsync(true); //assert Assert.IsNotNull(iapReceipt); }
public async Task Should_get_correct_RequestProductPurchaseAsync_result_for_VALID_InAppPurchase() { //arrange var iapConfigFile = await StorageFile.GetFileFromApplicationUriAsync(TestDataUris.InAppPurchaseLicenseUri); await CurrentAppProxy.ReloadSimulatorSettingsAsync(iapConfigFile); //act var iapReceipt = await CurrentAppProxy.RequestProductPurchaseAsync("MarkedUpExtraFeature", false); //assert Assert.IsNotNull(iapReceipt); }
public async Task Should_get_iap_licenses() { //arrange var iapConfigFile = await StorageFile.GetFileFromApplicationUriAsync(TestDataUris.PurchaseIAPLicenseUri); await CurrentAppProxy.ReloadSimulatorSettingsAsync(iapConfigFile); //act var license = CurrentAppProxy.LicenseInformation; //assert Assert.IsTrue(license.ProductLicenses.ContainsKey("MarkedUpExtraFeature")); Assert.IsTrue(license.ProductLicenses["MarkedUpExtraFeature"].IsActive); Assert.IsFalse(license.ProductLicenses["MarkedUpExtraFeature"].IsConsumable); }
/// <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_app_listing_information_for_free_app() { //arrange var freeAppConfigFile = await StorageFile.GetFileFromApplicationUriAsync(TestDataUris.FreeLicenseUri); await CurrentAppProxy.ReloadSimulatorSettingsAsync(freeAppConfigFile); //act var appStoreListing = await CurrentAppProxy.LoadListingInformationAsync(); //assert Assert.IsNotNull(appStoreListing); Assert.AreEqual("$0.00", appStoreListing.FormattedPrice); #if !WINDOWS_PHONE //Age rating is not supported for Windows Phone 8 Assert.AreEqual(3u, appStoreListing.AgeRating); #endif Assert.AreEqual("Free license", appStoreListing.Name); Assert.AreEqual("Sample app for demonstrating trial license management", appStoreListing.Description); Assert.AreEqual("US", appStoreListing.CurrentMarket); }
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(); }