private void DoFulfillment() { if (!appSettings.Contains("isPurchased")) { appSettings.Add("isPurchased", true); } appSettings.Save(); OrganizeLayout(); CurrentApp.ReportProductFulfillment("fmRadioDonation"); if (appSettings.Contains("language")) { var languageKey = appSettings["language"].ToString(); switch (languageKey) { case App.Languages.English: MessageBox.Show("Thank you for your support and donation, it is very much appreciated.", "Thanks", MessageBoxButton.OK); break; case App.Languages.Turkce: MessageBox.Show("Destek ve yardımınız için çok teşekkürler.", "Teşekkürler", MessageBoxButton.OK); break; } } else { MessageBox.Show("Thank you for your support and donation, it is very much appreciated.", "Thanks", MessageBoxButton.OK); } }
async private void btnBuy50Points_Click_1(object sender, RoutedEventArgs e) { //50 Points - Consumable var listing = await CurrentApp.LoadListingInformationAsync(); var fiftypoints = listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == "11111" && p.Value.ProductType == ProductType.Consumable); try { receipt = await CurrentApp.RequestProductPurchaseAsync(fiftypoints.Value.ProductId, true); if (CurrentApp.LicenseInformation.ProductLicenses[fiftypoints.Value.ProductId].IsActive) { // do something CurrentApp.ReportProductFulfillment(fiftypoints.Value.ProductId); m_pointCount += 50; txtBought50Pts.Visibility = System.Windows.Visibility.Visible; txtBought50Pts.Text = "Bought 50 Points " + i++ + " times for a total of " + m_pointCount + "!"; } } catch (Exception ex) { //catch exception } }
public async Task <bool> BuyProduct(string productId) { if (mListingInformation != null) { var product = mListingInformation.ProductListings.FirstOrDefault(p => p.Value.ProductId == productId); // && p.Value.ProductType == ProductType.Consumable); try { string receipt = await CurrentApp.RequestProductPurchaseAsync(product.Value.ProductId, true); if (CurrentApp.LicenseInformation.ProductLicenses[product.Value.ProductId].IsActive) { CurrentApp.ReportProductFulfillment(product.Value.ProductId); // TO DO: // add your code here to increment or unlock your game data return(true); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } } return(false); }
/// <summary> /// Notifies the Windows Store that the application has fulfilled the in-app product. This product cannot be re-purchased /// until the app has confirmed fulfillment using this method. /// </summary> /// <param name="productId">The ID of the product that has been delivered to the user.</param> public static void ReportProductFulfillment(string productId) { if (IsMockEnabled) { // There is no fulfillment method in the simulator that // accepts one parameter. throw new ArgumentException(); } CurrentApp.ReportProductFulfillment(productId); }
public static async void Donate(string productId, bool isConsurable = false) { try { PopupMessage popupMessage = new PopupMessage(); if (NetworkInterface.GetIsNetworkAvailable()) { var listing = await CurrentApp.LoadListingInformationAsync(); var myProduct = listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == productId); if (!CurrentApp.LicenseInformation.ProductLicenses[myProduct.Value.ProductId].IsActive) { await CurrentApp.RequestProductPurchaseAsync(productId, false); var productLicenses = CurrentApp.LicenseInformation.ProductLicenses; ProductLicense tokenLicense = productLicenses[productId]; if (tokenLicense.IsActive) { if (isConsurable)//если продукт расходуемый { CurrentApp.ReportProductFulfillment(productId); } var settings = IsolatedStorageSettings.ApplicationSettings; string product = "product" + productId; if (!settings.Contains(product)) { settings.Add(product, true); settings.Save(); } //popupMessage.Show("Thank you for your purchase!");//en //popupMessage.Show(AppResources.ThankYouForPurchase);//it popupMessage.Show("Thank you for your purchase!"); } } else { //popupMessage.Show("You have already bought this product!");//en //popupMessage.Show(AppResources.ProductExitsts);//it popupMessage.Show("You have already bought this product!"); } } else { //popupMessage.Show("Пожалуйста, проверьте подключение к сети Интернет!");//ru //popupMessage.Show("Please check the connection to the Internet!");//en //popupMessage.Show(AppResources.NoInternet);//it popupMessage.Show("Please check the connection to the Internet!"); } } catch (Exception ex) { } }
private async void OnDonateClick(object sender, EventArgs e) { ErrorReporting.Log("OnDonateCick"); try { await CurrentApp.RequestProductPurchaseAsync("Donate", false); if (CurrentApp.LicenseInformation.ProductLicenses["Donate"].IsActive) { CurrentApp.ReportProductFulfillment("Donate"); } } catch { } }
private async void PurchaseProduct(string productID) { try { await CurrentApp.RequestProductPurchaseAsync(productID, false); CurrentApp.ReportProductFulfillment(productID); MessageBox.Show("Purchase successful, thank you!!!"); } catch (Exception excep) { MessageBox.Show("Purchase failed."); } }
public async void BuyProductByName(Plan plan) { ListingInformation allProducts = await CurrentApp.LoadListingInformationAsync(); ProductListing productListing = null; if (!allProducts.ProductListings.TryGetValue(plan.Name, out productListing)) { _informerManagerLocator.InformerManager.AddMessage("Error", "Can't find this plan in market, sorry for this inconvenience"); PlanPurchased(this, new EventArgs(), null); } else { try { /********************************/ // DON'T DO THIS WITH TRUE APP var licensetest = CurrentApp.LicenseInformation.ProductLicenses[plan.Name]; if (licensetest.IsConsumable && licensetest.IsActive) { CurrentApp.ReportProductFulfillment(licensetest.ProductId); } /*******************************/ string result = await CurrentApp.RequestProductPurchaseAsync(productListing.ProductId, false); var license = CurrentApp.LicenseInformation.ProductLicenses[plan.Name]; if (license.IsConsumable && license.IsActive) { CurrentApp.ReportProductFulfillment(license.ProductId); //Pour envoyer un avis de reception chiffré /*string receiptXml = await CurrentApp.GetProductReceiptAsync(license.ProductId); * await SendReceipt(receiptXml);*/ } PlanPurchased(this, new EventArgs(), plan); } catch (Exception) { if (PlanPurchased != null) { PlanPurchased(this, new EventArgs(), null); } } } }
//</ClaimOfferOnWindows1607AndLater> // This method uses the Windows.ApplicationModel.Store APIs to purchase and claim a targeted offer. // This method can be used on any version of Windows 10. //<ClaimOfferOnAnyVersionWindows10> private async Task ClaimOfferOnAnyVersionWindows10Async( string productId, TargetedOfferData offerData, string msaToken) { if (string.IsNullOrEmpty(productId) || string.IsNullOrEmpty(msaToken)) { System.Diagnostics.Debug.WriteLine("Product ID or Microsoft Account token is null or empty."); return; } // Purchase the add-on for the current user and report it to the Store as fulfilled // if the purchase was successful. Typically, a game or app would first show // a UI that prompts the user to buy the add-on; for simplicity, this example // simply purchases the add-on. var purchaseResult = await CurrentApp.RequestProductPurchaseAsync(productId); if (purchaseResult.Status == ProductPurchaseStatus.Succeeded) { CurrentApp.ReportProductFulfillment(productId); var claim = new TargetedOfferClaim { StoreOffer = offerData, Receipt = purchaseResult.ReceiptXml }; // Submit a request to claim the offer by sending a POST message to the // Store endpoint for targeted offers. using (var httpClientClaimOffer = new HttpClient()) { var uri = new Uri(storeOffersUri, UriKind.Absolute); using (var request = new HttpRequestMessage(HttpMethod.Post, uri)) { request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", msaToken); request.Content = new StringContent( JsonConvert.SerializeObject(claim), Encoding.UTF8, jsonMediaType); using (var response = await httpClientClaimOffer.SendAsync(request)) { response.EnsureSuccessStatusCode(); } } } } }
public async void consumeProduct(string args) { /* * string productId = JsonHelper.Deserialize<string[]>(args)[0]; * Debug.WriteLine("productId: " + productId); * * if (!CurrentApp.LicenseInformation.ProductLicenses[productId].IsActive) * { * try * { * //http://stackoverflow.com/questions/16192783/in-app-purchase-consumable-product-responding-error * CurrentApp.ReportProductFulfillment(productId); * * DispatchCommandResult(new PluginResult(PluginResult.Status.OK, "")); * } * catch * { * DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Unknown Error")); * } * } * else * { * //Already owns the product * } */ string[] productIds = JsonHelper.Deserialize <string[]>(args); try { for (int i = 0; i < productIds.length; i++) { string productId = productIds[i]; if (CurrentApp.LicenseInformation.ProductLicenses[productId].IsActive) { //http://stackoverflow.com/questions/16192783/in-app-purchase-consumable-product-responding-error CurrentApp.ReportProductFulfillment(productId); } } DispatchCommandResult(new PluginResult(PluginResult.Status.OK, "")); } catch { DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Unknown Error")); } }
private async void SupputMe_Click(object sender, RoutedEventArgs e) { try { try { CurrentApp.ReportProductFulfillment("SupportMe"); } catch { } var result = await CurrentApp.RequestProductPurchaseAsync("SupportMe", true); CurrentApp.ReportProductFulfillment("SupportMe"); } catch { } }
/// <summary> /// Reports a consumable as fullfilled. You should call this once you have granted the consumable to the player. /// /// </summary> /// <param name="productId"/><param name="transactionId"/><param name="completionHandler"/> public static void ReportConsumableFulfillment(string productId, Guid transactionId, Action <FulfillmentResult, Exception> onComplete) { Exception exception = null; try { CurrentApp.ReportProductFulfillment(productId); if (onComplete != null) { EtceteraWindows.RunOnUnityThread(() => onComplete(FulfillmentResult.Succeeded, null)); } } catch (Exception ex) { if (onComplete != null) { EtceteraWindows.RunOnUnityThread(() => onComplete(FulfillmentResult.ServerError, ex)); } } }
private async void PurchaseRemoveAdButton_Click(object sender, RoutedEventArgs e) { try { var listing = await CurrentApp.LoadListingInformationAsync(); var iap = listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == "RemoveAd"); var purchaseResult = await CurrentApp.RequestProductPurchaseAsync(iap.Value.ProductId); if (CurrentApp.LicenseInformation.ProductLicenses[iap.Value.ProductId].IsActive) { CurrentApp.ReportProductFulfillment(iap.Value.ProductId); AdWrap.Visibility = Visibility.Collapsed; MainSplitView.Margin = new Thickness(0); } } catch (Exception) { } }
public static void ConsumeProduct(string productId) { Deployment.Current.Dispatcher.BeginInvoke(() => { try { CurrentApp.ReportProductFulfillment(productId); } catch (Exception e) { if (ConsumeFailed != null) { ConsumeFailed(e.Message); } return; } if (ConsumeSucceeded != null) { ConsumeSucceeded(productId); } }); }
private async void Fulfill(string item, string receipt) { var t = CurrentApp.LoadListingInformationAsync(); int v; switch (item) { case IAPs.IAP_AdditionalLogin: products.ItemsSource = null; progressRing.IsActive = true; var prevData = await Storage.LoadAsync <byte[]>(IAPs.IAP_AdditionalLogin); if (prevData == null) { v = 2; } else { var dData = ProtectedData.Unprotect(prevData, null); int value = BitConverter.ToInt32(dData, 0); v = value + 1; } Save(v); using (var c = new HttpClient()) { var result = await c.PostAsync("https://wauth.apphb.com/api/AddPayment", new StringContent(JsonConvert.SerializeObject(new PayingUser { Username = (App.Current as App).currentInfo.Username, Count = v }), Encoding.UTF8, "application/json")); } progressRing.IsActive = false; products.ItemsSource = prods.ProductListings.Values.Select(x => new { x.Name, Status = CurrentApp.LicenseInformation.ProductLicenses[x.ProductId].IsActive ? "Purchased" : x.FormattedPrice, x.ImageUri, x.ProductId, BuyNowButtonVisible = CurrentApp.LicenseInformation.ProductLicenses[x.ProductId].IsActive ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible }); break; case IAPs.IAP_PushNotification: products.ItemsSource = null; progressRing.IsActive = true; var ch = WPUtils.ChannelStartup(); SystemTray.SetProgressIndicator(this, new ProgressIndicator { IsVisible = true, Text = AppResources.PushConnect, IsIndeterminate = true }); var tsk = WPUtils.UploadCurrentData(); while (ch.ConnectionStatus != ChannelConnectionStatus.Connected && ch.ChannelUri == null) { await Task.Delay(1000); } await WPUtils.PushNotificationSetUp(this); SystemTray.SetProgressIndicator(this, null); progressRing.IsActive = false; products.ItemsSource = prods.ProductListings.Values.Select(x => new { x.Name, Status = CurrentApp.LicenseInformation.ProductLicenses[x.ProductId].IsActive ? "Purchased" : x.FormattedPrice, x.ImageUri, x.ProductId, BuyNowButtonVisible = CurrentApp.LicenseInformation.ProductLicenses[x.ProductId].IsActive ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible }); await tsk; break; default: break; } prods = await t; var prod = prods.ProductListings.Single(x => x.Value.ProductId == item); if (prod.Value.ProductType == ProductType.Consumable) { CurrentApp.ReportProductFulfillment(item); } }
private async void buyInAppAsync(string inAppID, InAppPurchaseBuyCallbackMethod purchasedCallback) #endif { #if WINDOWS_PHONE WinRTPlugin.Dispatcher.BeginInvoke(async delegate() #else await WinRTPlugin.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async delegate() #endif { #if WINDOWS_PHONE if ((testing && (!wp8TestLicenseInformation.ProductLicenses[inAppID].IsActive || wp8TestLicenseInformation.ProductLicenses[inAppID].IsConsumable)) || (!testing && (!licenseInformation.ProductLicenses[inAppID].IsActive || licenseInformation.ProductLicenses[inAppID].IsConsumable))) #else if (!licenseInformation.ProductLicenses[inAppID].IsActive || isConsumbable(inAppID)) #endif { try { string receipt = null; #if WINDOWS_PHONE string productID = null; if (testing) { productID = wp8TestListingInformation.ProductListings[inAppID].ProductId; } else { productID = licenseInformation.ProductLicenses[inAppID].ProductId; } #elif UNITY_METRO_8_0 string productID = licenseInformation.ProductLicenses[inAppID].ProductId; #else PurchaseResults results; string productID = licenseInformation.ProductLicenses[inAppID].ProductId; #endif if (testing) { #if WINDOWS_PHONE receipt = await CurrentAppSimulator.RequestProductPurchaseAsync(productID, true); if (wp8TestLicenseInformation.ProductLicenses[inAppID].IsActive) { PlayerPrefsEx.SetIntAsync("ReignIAP_PurchasedAwarded_" + inAppID, 0, true); } #elif UNITY_METRO_8_0 receipt = await CurrentAppSimulator.RequestProductPurchaseAsync(productID, true); #else results = await CurrentAppSimulator.RequestProductPurchaseAsync(productID); receipt = results.ReceiptXml; #endif } else { #if WINDOWS_PHONE receipt = await CurrentApp.RequestProductPurchaseAsync(productID, true); if (licenseInformation.ProductLicenses[inAppID].IsActive) { PlayerPrefsEx.SetIntAsync("ReignIAP_PurchasedAwarded_" + inAppID, 0, true); } #elif UNITY_METRO_8_0 receipt = await CurrentApp.RequestProductPurchaseAsync(productID, true); #else results = await CurrentApp.RequestProductPurchaseAsync(productID); receipt = results.ReceiptXml; #endif } #if UNITY_METRO_8_0 if (!string.IsNullOrEmpty(receipt) || licenseInformation.ProductLicenses[inAppID].IsActive) { PlayerPrefsEx.SetIntAsync("ReignIAP_PurchasedAwarded_" + inAppID, 0, true); } #elif UNITY_METRO if (results.Status == ProductPurchaseStatus.Succeeded || results.Status == ProductPurchaseStatus.AlreadyPurchased || licenseInformation.ProductLicenses[inAppID].IsActive) { PlayerPrefsEx.SetIntAsync("ReignIAP_PurchasedAwarded_" + inAppID, 0, true); } #endif if (purchasedCallback != null) { #if WINDOWS_PHONE if (testing) { purchasedCallback(inAppID, receipt, wp8TestLicenseInformation.ProductLicenses[inAppID].IsActive); if (wp8TestLicenseInformation.ProductLicenses[inAppID].IsConsumable) { CurrentAppSimulator.ReportProductFulfillment(productID); } } else { purchasedCallback(inAppID, receipt, licenseInformation.ProductLicenses[inAppID].IsActive); if (licenseInformation.ProductLicenses[inAppID].IsConsumable) { CurrentApp.ReportProductFulfillment(productID); } } #elif UNITY_METRO_8_0 purchasedCallback(inAppID, receipt, !string.IsNullOrEmpty(receipt) || licenseInformation.ProductLicenses[inAppID].IsActive); if (isConsumbable(inAppID)) { Debug.LogError("NOTE: Consumable IAP not supported in 8.0"); } #else purchasedCallback(inAppID, receipt, results.Status == ProductPurchaseStatus.Succeeded || results.Status == ProductPurchaseStatus.AlreadyPurchased || licenseInformation.ProductLicenses[inAppID].IsActive); if (isConsumbable(inAppID)) { if (testing) { await CurrentAppSimulator.ReportConsumableFulfillmentAsync(productID, results.TransactionId); } else { await CurrentApp.ReportConsumableFulfillmentAsync(productID, results.TransactionId); } } #endif } } catch (Exception e) { Debug.LogError(e.Message); if (purchasedCallback != null) { purchasedCallback(inAppID, null, false); } } } else { if (purchasedCallback != null) { purchasedCallback(inAppID, null, true); } } }); }
public async void inAppPurchase_Purchase(string productID) { try { ListingInformation products = await CurrentApp.LoadListingInformationByProductIdsAsync(new[] { productID }); // get specific in-app product by ID ProductListing productListing = null; if (!products.ProductListings.TryGetValue(productID, out productListing)) { MainPage.m_d3dInterop.csActionResult("CCAppManager::InAppPurchaseSuccessful", "false"); return; } bool isActive = false; ProductLicense pLicense; if (CurrentApp.LicenseInformation.ProductLicenses.TryGetValue(productID, out pLicense)) { isActive = pLicense.IsActive; } if (isActive) { // Auto-consume product if (pLicense.IsConsumable) { CurrentApp.ReportProductFulfillment(productID); } MainPage.m_d3dInterop.csActionResult("CCAppManager::InAppPurchaseSuccessful", "true"); return; } string result = await CurrentApp.RequestProductPurchaseAsync(productID, true); if (CurrentApp.LicenseInformation.ProductLicenses.TryGetValue(productID, out pLicense)) { // Auto-consume product if (pLicense.IsConsumable) { CurrentApp.ReportProductFulfillment(productID); } } if (result.Length > 0) { // Purchased MainPage.m_d3dInterop.csActionResult("CCAppManager::InAppPurchaseSuccessful", "true"); } else { MainPage.m_d3dInterop.csActionResult("CCAppManager::InAppPurchaseSuccessful", "true"); } } catch (Exception e) { #if DEBUGON MainPage.m_d3dInterop.Print("InAppPurchase::Error" + e.ToString()); #endif // The in-app purchase was not completed because the // customer canceled it or an error occurred. MainPage.m_d3dInterop.csActionResult("CCAppManager::InAppPurchaseSuccessful", "false"); } }