private async void loadTestData(InAppPurchaseDesc desc, InAppPurchaseCreatedCallbackMethod createdCallback) { bool pass = true; try { // create xml obj var currentApp = new InAppTestObjects.CurrentApp(); currentApp.ListingInformation.Products = new InAppTestObjects.ListingInformation_Product[desc.WinRT_MicrosoftStore_InAppIDs.Length]; currentApp.LicenseInformation.Products = new InAppTestObjects.LicenseInformation_Product[desc.WinRT_MicrosoftStore_InAppIDs.Length]; for (int i = 0; i != currentApp.ListingInformation.Products.Length; ++i) { var listingProduct = new InAppTestObjects.ListingInformation_Product(); listingProduct.ProductId = desc.WinRT_MicrosoftStore_InAppIDs[i].ID; listingProduct.ProductType = desc.WinRT_MicrosoftStore_InAppIDs[i].Type == InAppPurchaseTypes.NonConsumable ? null : "Consumable"; listingProduct.MarketData.Name = desc.WinRT_MicrosoftStore_InAppIDs[i].ID; listingProduct.MarketData.Description = null; listingProduct.MarketData.Price = desc.WinRT_MicrosoftStore_InAppIDs[i].Price.ToString(); listingProduct.MarketData.CurrencySymbol = desc.WinRT_MicrosoftStore_InAppIDs[i].CurrencySymbol; currentApp.ListingInformation.Products[i] = listingProduct; var licenseProduct = new InAppTestObjects.LicenseInformation_Product(); licenseProduct.ProductId = desc.WinRT_MicrosoftStore_InAppIDs[i].ID; currentApp.LicenseInformation.Products[i] = licenseProduct; } // serialize obj var xml = new XmlSerializer(typeof(InAppTestObjects.CurrentApp)); byte[] data = null; using (var stream = new MemoryStream()) { xml.Serialize(stream, currentApp); stream.Position = 0; data = new byte[stream.Length]; stream.Read(data, 0, data.Length); } // write and read test InApp data StorageFile writeFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("TEST_InAppPurchase.xml", CreationCollisionOption.ReplaceExisting); await FileIO.WriteBytesAsync(writeFile, data); StorageFile readFile = await ApplicationData.Current.LocalFolder.GetFileAsync("TEST_InAppPurchase.xml"); await CurrentAppSimulator.ReloadSimulatorAsync(readFile); licenseInformation = CurrentAppSimulator.LicenseInformation; licenseInformation.LicenseChanged += licenseChanged; } catch (Exception e) { Debug.LogError(e.Message); pass = false; } if (createdCallback != null) { createdCallback(pass); } }
private async void loadTestData(InAppPurchaseDesc desc, InAppPurchaseCreatedCallbackMethod createdCallback) { bool pass = true; try { MockIAPLib.MockIAP.Init(); MockIAPLib.MockIAP.RunInMockMode(true); MockIAPLib.MockIAP.SetListingInformation(1, "en-us", "Some description", "1", "TestApp"); int i = 1; foreach (var inApp in desc.WP8_MicrosoftStore_InAppIDs) { var product = new MockIAPLib.ProductListing { Name = inApp.ID, ImageUri = new Uri("/Res/ReignIcon.png", UriKind.Relative), ProductId = inApp.ID, ProductType = inApp.Type == InAppPurchaseTypes.NonConsumable ? ProductType.Durable : ProductType.Consumable, Keywords = new string[] { "image" }, Description = "Product Desc " + i, FormattedPrice = inApp.CurrencySymbol + inApp.Price, Tag = string.Empty }; MockIAPLib.MockIAP.AddProductListing(inApp.ID, product); ++i; } wp8TestListingInformation = await CurrentAppSimulator.LoadListingInformationAsync(); MockIAPLib.MockIAP.ClearCache(); wp8TestLicenseInformation = CurrentAppSimulator.LicenseInformation; wp8TestLicenseInformation.LicenseChanged += licenseChanged; } catch (Exception e) { Debug.LogError(e.Message); pass = false; } if (createdCallback != null) { createdCallback(pass); } }
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 GetProductInfo(InAppPurchaseGetProductInfoCallbackMethod callback) { if (callback == null) { return; } var infos = new List <InAppPurchaseInfo>(); try { #if WINDOWS_PHONE if (testing) { var listingInfo = wp8TestListingInformation; foreach (var l in listingInfo.ProductListings) { var info = new InAppPurchaseInfo() { ID = l.Value.ProductId, FormattedPrice = l.Value.FormattedPrice }; infos.Add(info); } } else { var listingInfo = await CurrentApp.LoadListingInformationAsync(); foreach (var l in listingInfo.ProductListings) { var info = new InAppPurchaseInfo() { ID = l.Value.ProductId, FormattedPrice = l.Value.FormattedPrice }; infos.Add(info); } } #else ListingInformation listingInfo; if (testing) { listingInfo = await CurrentAppSimulator.LoadListingInformationAsync(); } else { listingInfo = await CurrentApp.LoadListingInformationAsync(); } foreach (var l in listingInfo.ProductListings) { var info = new InAppPurchaseInfo() { ID = l.Value.ProductId, FormattedPrice = l.Value.FormattedPrice }; infos.Add(info); } #endif callback(infos.ToArray(), true); } catch (Exception e) { Debug.LogError(e.Message); callback(null, false); } }
public async void GetProductInfo(InAppPurchaseGetProductInfoCallbackMethod callback) { if (callback == null) { return; } #if WINDOWS_PHONE WinRTPlugin.Dispatcher.BeginInvoke(async delegate() #else await WinRTPlugin.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async delegate() #endif { var infos = new List <InAppPurchaseInfo>(); try { #if WINDOWS_PHONE if (testing) { var listingInfo = wp8TestListingInformation; foreach (var l in listingInfo.ProductListings) { var info = new InAppPurchaseInfo() { ID = l.Value.ProductId, FormattedPrice = l.Value.FormattedPrice }; infos.Add(info); } } else { var listingInfo = await CurrentApp.LoadListingInformationAsync(); foreach (var l in listingInfo.ProductListings) { var info = new InAppPurchaseInfo() { ID = l.Value.ProductId, FormattedPrice = l.Value.FormattedPrice }; infos.Add(info); } } #else ListingInformation listingInfo; if (testing) { listingInfo = await CurrentAppSimulator.LoadListingInformationAsync(); } else { listingInfo = await CurrentApp.LoadListingInformationAsync(); } foreach (var l in listingInfo.ProductListings) { var info = new InAppPurchaseInfo() { ID = l.Value.ProductId, FormattedPrice = l.Value.FormattedPrice }; infos.Add(info); } #endif ReignServices.InvokeOnUnityThread(delegate { callback(infos.ToArray(), true); }); } catch (Exception e) { Debug.LogError(e.Message); ReignServices.InvokeOnUnityThread(delegate { callback(null, false); }); } }); }