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); } } }); }