private async Task PurchaseProduct(string productId, ushort featureLevel) { LicenseInformation licenseInformation = IAPs.LicenseInformation; if (!licenseInformation.ProductLicenses[productId].IsActive) { try { await IAPs.RequestProductPurchaseAsync(productId); } catch (Exception ex) { var dlg = new ContentDialog { Content = new TextBlock() { Text = "Error occured : " + ex.Message, TextWrapping = TextWrapping.Wrap }, PrimaryButtonText = ResourceLoader.GetForCurrentView().GetString("Confirm"), }; await dlg.ShowAsync(); } } else { VersionHelper.FeatureLevel |= featureLevel; } }
private async void LoadInAppPurchaseProxyFileAsync() { //StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("data"); //StorageFile proxyFile = await proxyDataFolder.GetFileAsync("in-app-product.xml"); //await IAPs.ReloadSimulatorAsync(proxyFile); licenseChangeHandler = new LicenseChangedEventHandler(InAppPurchaseRefreshScenario); IAPs.LicenseInformation.LicenseChanged += licenseChangeHandler; try { ListingInformation listing = await IAPs.LoadListingInformationAsync(); if (!listing.ProductListings.ContainsKey("CCPLAYER_IAP_REMOVE_ADVERTISING") || !listing.ProductListings.ContainsKey("CCPLAYER_IAP_UNLOCK_FEATURES")) { CmdBar.Visibility = Visibility.Collapsed; return; } ChangeCommandBarState(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); CmdBar.Visibility = Visibility.Collapsed; } finally { if (CmdBar.Visibility == Visibility.Collapsed) { IAPs.LicenseInformation.LicenseChanged -= licenseChangeHandler; Messenger.Default.Send(true, typeof(AdMainPage).FullName); } else { Messenger.Default.Register <bool>(this, typeof(MainPage).FullName, (val) => { if (!VersionHelper.IsFullVersion) { CmdBar.Visibility = !val ? Visibility.Visible : Visibility.Collapsed; } }); } } }
/// <summary> Consumes a MANAGED product. </summary> /// /// <param name="productId"> Identifier for the product. </param> public void Consume(string productId) { SoomlaUtils.LogDebug(TAG, "WStorePlugin consume " + productId); try { if (StoreConfig.STORE_TEST_MODE) { MockCurApp.ReportProductFulfillment(productId); } else { CurApp.ReportProductFulfillment(productId); } } catch (InvalidOperationException e) { SoomlaUtils.LogDebug(TAG, e.Message); } }
private async void DoPurchase(string productId) { try { bool licenceActiv = false; if (StoreConfig.STORE_TEST_MODE) { // Kick off purchase; don't ask for a receipt when it returns await MockCurApp.RequestProductPurchaseAsync(productId, false); licInfosMock = MockCurApp.LicenseInformation; licenceActiv = licInfosMock.ProductLicenses[productId].IsActive; } else { // Kick off purchase; don't ask for a receipt when it returns await CurApp.RequestProductPurchaseAsync(productId, false); licInfos = CurApp.LicenseInformation; licenceActiv = licInfos.ProductLicenses[productId].IsActive; } if (licenceActiv) { OnItemPurchasedCB(productId); } else { SoomlaUtils.LogDebug(TAG, "Purchase cancelled " + productId); OnItemPurchaseCancelCB(productId, false); } } catch (Exception ex) { // When the user does not complete the purchase (e.g. cancels or navigates back from the Purchase Page), an exception with an HRESULT of E_FAIL is expected. SoomlaUtils.LogDebug(TAG, ex.Message); OnItemPurchaseCancelCB(productId, true); } }