public static void AddProductListing(string key, ProductListing productListing) { CheckIfInitialized(); if (_appListingInformation == null) { throw new Exception("A call to SetListingInformation is required before calling this method"); } if (allProducts == null) { allProducts = new Dictionary <string, ProductListing>(); } allProducts.Add(key, productListing); var store = new MockReceiptStore(); Dictionary <string, string> receipts = store.EnumerateReceipts(); // add a license for this item as well. var license = new ProductLicense { ExpirationDate = DateTimeOffset.Now, IsActive = receipts.ContainsKey(productListing.ProductId), IsConsumable = productListing.ProductType == ProductType.Consumable, ProductId = productListing.ProductId }; _appLicenseInformation.ProductLicenses.Add(productListing.ProductId, license); }
internal static string SimulatePurchase(string ProductId, bool includeReceipt) { ProductListing listing = allProducts.Values.FirstOrDefault(p => p.ProductId.Equals(ProductId, StringComparison.InvariantCultureIgnoreCase)); if (listing == null) { throw new ArgumentException("Specified productId has no ProductListing"); } string receipt = string.Empty; bool OkToPurchase = true; bool?state = StateInformation.GetState(listing.ProductId); if (state != null && state.Value == false) { // This is an unfulfiled item MessageBox.Show("You have already purchased this but not fulfiled it yet"); OkToPurchase = false; } else { var rs = new MockReceiptStore(); if (listing.ProductType == ProductType.Durable && rs.EnumerateReceipts().ContainsKey(listing.ProductId)) { MessageBox.Show("You already purchased this durable"); OkToPurchase = false; } } if (OkToPurchase) { MessageBoxResult result = MessageBox.Show(string.Format("Simulating purchase. Do you want to buy this item ({0})?", listing.Name), "Mock UI", MessageBoxButton.OKCancel); if (result == MessageBoxResult.OK) { var store = new MockReceiptStore(); receipt = store.SaveReceipt(listing, includeReceipt); StateInformation.SetState(listing.ProductId, listing.ProductType == ProductType.Durable); // Set as fulfilled for Durables only _appLicenseInformation.ProductLicenses[listing.ProductId].IsActive = true; } else { throw new Exception("User has clicked on Cancel. In the real API, an exception will be thrown if that happens as well. You must put a try/catch around the RequestProductPurchaseAsync call to handle this."); } } return(receipt); }
public static async Task<string> GetProductReceiptAsync(string selectedProductId) { MockIAP.CheckIfInitialized(); string receipt = null; if (!MockIAP.MockMode) { receipt = await Windows.ApplicationModel.Store.CurrentApp.GetProductReceiptAsync(selectedProductId); } else { var rs = new MockReceiptStore(); Dictionary<string, string> receipts = rs.EnumerateReceipts(); if (receipts.ContainsKey(selectedProductId)) receipt = receipts[selectedProductId]; } return receipt; }
public static async Task <string> GetProductReceiptAsync(string selectedProductId) { MockIAP.CheckIfInitialized(); string receipt = null; if (!MockIAP.MockMode) { receipt = await Windows.ApplicationModel.Store.CurrentApp.GetProductReceiptAsync(selectedProductId); } else { var rs = new MockReceiptStore(); Dictionary <string, string> receipts = rs.EnumerateReceipts(); if (receipts.ContainsKey(selectedProductId)) { receipt = receipts[selectedProductId]; } } return(receipt); }
internal static string SimulatePurchase(string ProductId, bool includeReceipt) { ProductListing listing = allProducts.Values.FirstOrDefault(p => p.ProductId.Equals(ProductId, StringComparison.InvariantCultureIgnoreCase)); if (listing == null) throw new ArgumentException("Specified productId has no ProductListing"); string receipt = string.Empty; bool OkToPurchase = true; bool? state = StateInformation.GetState(listing.ProductId); if (state != null && state.Value == false) { // This is an unfulfiled item MessageBox.Show("You have already purchased this but not fulfiled it yet"); OkToPurchase = false; } else { var rs = new MockReceiptStore(); if (listing.ProductType == ProductType.Durable && rs.EnumerateReceipts().ContainsKey(listing.ProductId)) { MessageBox.Show("You already purchased this durable"); OkToPurchase = false; } } if (OkToPurchase) { MessageBoxResult result = MessageBox.Show(string.Format("Simulating purchase. Do you want to buy this item ({0})?", listing.Name), "Mock UI", MessageBoxButton.OKCancel); if (result == MessageBoxResult.OK) { var store = new MockReceiptStore(); receipt = store.SaveReceipt(listing, includeReceipt); StateInformation.SetState(listing.ProductId, listing.ProductType == ProductType.Durable); // Set as fulfilled for Durables only _appLicenseInformation.ProductLicenses[listing.ProductId].IsActive = true; } else { throw new Exception("User has clicked on Cancel. In the real API, an exception will be thrown if that happens as well. You must put a try/catch around the RequestProductPurchaseAsync call to handle this."); } } return receipt; }
public static void AddProductListing(string key, ProductListing productListing) { CheckIfInitialized(); if (_appListingInformation == null) throw new Exception("A call to SetListingInformation is required before calling this method"); if (allProducts == null) allProducts = new Dictionary<string, ProductListing>(); allProducts.Add(key, productListing); var store = new MockReceiptStore(); Dictionary<string, string> receipts = store.EnumerateReceipts(); // add a license for this item as well. var license = new ProductLicense { ExpirationDate = DateTimeOffset.Now, IsActive = receipts.ContainsKey(productListing.ProductId), IsConsumable = productListing.ProductType == ProductType.Consumable, ProductId = productListing.ProductId }; _appLicenseInformation.ProductLicenses.Add(productListing.ProductId, license); }