private static void Constantize() { try { var builder = new StringBuilder(); builder.AppendLine("/// <summary>"); builder.AppendLine("/// IAPのProductIDを定数として保持するクラス"); builder.AppendLine("/// </summary>"); builder.AppendLine("public static class IAPProductID {"); var catalog = ProductCatalog.LoadDefaultCatalog(); foreach (var product in catalog.allProducts) { var name = RemoveInvalidChars(product.id.Replace(".", "_")).ToUpper(); builder.Append("\t").AppendFormat(@"public const string {0} = ""{1}"";", name, product.id).AppendLine(); } builder.AppendLine("}"); var directoryName = Path.GetDirectoryName(_path); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } File.WriteAllText(_path, builder.ToString(), Encoding.UTF8); AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive); } catch (Exception e) { Debug.LogException(e); } }
private StoreManager() { catalog = ProductCatalog.LoadDefaultCatalog(); StandardPurchasingModule module = StandardPurchasingModule.Instance(); module.useFakeStoreUIMode = FakeStoreUIMode.StandardUser; ConfigurationBuilder builder = ConfigurationBuilder.Instance(module); foreach (var product in catalog.allProducts) { if (product.allStoreIDs.Count > 0) { var ids = new IDs(); foreach (var storeID in product.allStoreIDs) { ids.Add(storeID.id, storeID.store); } builder.AddProduct(product.id, product.type, ids); } else { builder.AddProduct(product.id, product.type); } } UnityPurchasing.Initialize(this, builder); }
private IAPButtonStoreManager() { catalog = ProductCatalog.LoadDefaultCatalog(); StandardPurchasingModule module = StandardPurchasingModule.Instance(); module.useFakeStoreUIMode = FakeStoreUIMode.StandardUser; ConfigurationBuilder builder = ConfigurationBuilder.Instance(module); //This seems to be outdated/unneeded, the value should be set in unity services //builder.Configure<IGooglePlayConfiguration>().SetPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2O/9/H7jYjOsLFT/uSy3ZEk5KaNg1xx60RN7yWJaoQZ7qMeLy4hsVB3IpgMXgiYFiKELkBaUEkObiPDlCxcHnWVlhnzJBvTfeCPrYNVOOSJFZrXdotp5L0iS2NVHjnllM+HA1M0W2eSNjdYzdLmZl1bxTpXa4th+dVli9lZu7B7C2ly79i/hGTmvaClzPBNyX+Rtj7Bmo336zh2lYbRdpD5glozUq+10u91PMDPH+jqhx10eyZpiapr8dFqXl5diMiobknw9CgcjxqMTVBQHK6hS0qYKPmUDONquJn280fBs1PTeA6NMG03gb9FLESKFclcuEZtvM8ZwMMRxSLA9GwIDAQAB"); foreach (var product in catalog.allProducts) { if (product.allStoreIDs.Count > 0) { var ids = new IDs(); foreach (var storeID in product.allStoreIDs) { ids.Add(storeID.id, storeID.store); } builder.AddProduct(product.id, product.type, ids); } else { builder.AddProduct(product.id, product.type); } } #if RECEIPT_VALIDATION validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.bundleIdentifier); #endif UnityPurchasing.Initialize(this, builder); }
private void InitIAP() { var module = StandardPurchasingModule.Instance(); ConfigurationBuilder builder = ConfigurationBuilder.Instance(module); var catalog = ProductCatalog.LoadDefaultCatalog(); foreach (var product in catalog.allValidProducts) { if (product.allStoreIDs.Count > 0) { var ids = new IDs(); foreach (var storeID in product.allStoreIDs) { ids.Add(storeID.id, storeID.store); } builder.AddProduct(product.id, product.type, ids); } else { builder.AddProduct(product.id, product.type); } } UnityPurchasing.Initialize(this, builder); }
public void InitializePurchasing() { // If we have already connected to Purchasing ... if (IsInitialized()) { // ... we are done here. return; } // Create a builder, first passing in a suite of Unity provided stores. var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance()); var catalog = ProductCatalog.LoadDefaultCatalog(); builder = AddProducts(builder, catalog); // Add a product to sell / restore by way of its identifier, associating the general identifier // with its store-specific identifiers. //builder.AddProduct(kProductIDConsumable, ProductType.Consumable); // Continue adding the non-consumable product. //builder.AddProduct(kProductIDNonConsumable, ProductType.NonConsumable); // And finish adding the subscription product. Notice this uses store-specific IDs, illustrating // if the Product ID was configured differently between Apple and Google stores. Also note that // one uses the general kProductIDSubscription handle inside the game - the store-specific IDs // must only be referenced here. //builder.AddProduct(kProductIDSubscription, ProductType.Subscription, new IDs(){ // { kProductNameAppleSubscription, AppleAppStore.Name }, // { kProductNameGooglePlaySubscription, GooglePlay.Name }, //}); // Kick off the remainder of the set-up with an asynchrounous call, passing the configuration // and this class' instance. Expect a response either in OnInitialized or OnInitializeFailed. UnityPurchasing.Initialize(this, builder); }
public IAPManager() { ConfigurationBuilder builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance()); ProductCatalog catalog = ProductCatalog.LoadDefaultCatalog(); foreach (ProductCatalogItem item in catalog.allProducts) { if (item.allStoreIDs.Count > 0) { IDs ids = new IDs(); foreach (StoreID storeID in item.allStoreIDs) { ids.Add(storeID.id, storeID.store); } builder.AddProduct(item.id, item.type, ids); } else { builder.AddProduct(item.id, item.type); } } if (builder.Configure <IAppleConfiguration> ().canMakePayments) { UnityPurchasing.Initialize(this, builder); } else { Alert.Show("当前设备不允许支付,请启用内购功能"); Debug.Log("当前设备不允许支付"); } }
//初始化内购项目,主要是从catalog中获取商品信息,设置给 UnityPurchasing void InitializePurchasing() { if (IsInitialized()) { Debug.Log("初始化失败"); return; } StandardPurchasingModule module = StandardPurchasingModule.Instance(); module.useFakeStoreUIMode = FakeStoreUIMode.StandardUser; ConfigurationBuilder builder = ConfigurationBuilder.Instance(module); //通过编辑器中的Catalog添加,方便操作 ProductCatalog catalog = ProductCatalog.LoadDefaultCatalog(); // Debug.Log(catalog.allProducts.Count); foreach (var product in catalog.allProducts) { if (product.allStoreIDs.Count > 0) { // Debug.Log("product:" + product.id); var ids = new IDs(); foreach (var storeID in product.allStoreIDs) { ids.Add(storeID.id, storeID.store); // Debug.Log("stordId:" + storeID.id + ", " + storeID.store); } builder.AddProduct(product.id, product.type, ids); } else { builder.AddProduct(product.id, product.type); } } UnityPurchasing.Initialize(this, builder); }
private void Start() { var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance()); IAPConfigurationHelper.PopulateConfigurationBuilder(ref builder, ProductCatalog.LoadDefaultCatalog()); _productId = "disable_ads"; builder.AddProduct(_productId, ProductType.NonConsumable); UnityPurchasing.Initialize(this, builder); }
public void BuyCoins(Product bought) { foreach (ProductCatalogItem def in ProductCatalog.LoadDefaultCatalog().allProducts) { if (def.id == bought.definition.id && def.Payouts.Count > 0 && def.Payouts[0].subtype == "Silver") { PlayerBoxController.currentPlayer.silverCoins += (int)def.Payouts[0].quantity; return; } } }
public void Initialize() { Manager <IAPManager> .instance = this; RestoringPurchases = true; PurchasingInitialized = false; PurchasingInitializationFailed = false; RetryPurchasingInitialization = false; StandardPurchasingModule first = StandardPurchasingModule.Instance(); ProductCatalog catalog = ProductCatalog.LoadDefaultCatalog(); ConfigurationBuilder builder = ConfigurationBuilder.Instance(first); // IAPConfigurationHelper.PopulateConfigurationBuilder(ref builder, catalog); UnityPurchasing.Initialize(this, builder); }
public override void OnInspectorGUI() { IapProductData productData = (IapProductData)target; serializedObject.Update(); EditorGUILayout.LabelField(new GUIContent("Product ID:", "Select a product from the IAP catalog")); #if UNITY_PURCHASING var catalog = ProductCatalog.LoadDefaultCatalog(); m_ValidIDs.Clear(); m_ValidIDs.Add(kNoProduct); foreach (var product in catalog.allProducts) { m_ValidIDs.Add(product.id); } int currentIndex = string.IsNullOrEmpty(productData.productId) ? 0 : m_ValidIDs.IndexOf(productData.productId); int newIndex = EditorGUILayout.Popup(currentIndex, m_ValidIDs.ToArray()); if (newIndex > 0 && newIndex < m_ValidIDs.Count) { m_ProductIDProperty.stringValue = m_ValidIDs[newIndex]; } else { m_ProductIDProperty.stringValue = string.Empty; } if (GUILayout.Button("IAP Catalog...")) { ProductCatalogEditor.ShowWindow(); } #else m_ProductIDProperty.stringValue = string.Empty; var defaultColor = GUI.color; GUI.color = Color.red; GUILayout.Label("You must install Unity Purchasing"); GUI.color = defaultColor; #endif DrawPropertiesExcluding(serializedObject, new string[] { "m_Script" }); serializedObject.ApplyModifiedProperties(); }
public SSIAPModule() { Debug.Log("Log - SSIAPModule"); var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance()); var catalog = ProductCatalog.LoadDefaultCatalog(); foreach (var product in catalog.allProducts) { Debug.Log("Log - product - " + product.id); // Debug.Log("add product : " + product.id); builder.AddProduct(product.id, product.type, new IDs { { product.id, AppleAppStore.Name }, { product.id, GooglePlay.Name }, { product.id, AmazonApps.Name }, }); } UnityPurchasing.Initialize(this, builder); }
public void BuyInappProduct(string productID) { Debug.Log("1"); var catalog = ProductCatalog.LoadDefaultCatalog(); Debug.Log("2"); var p = storeController.products.WithID(productID); Debug.Log("3"); if (p == null || !p.availableToPurchase) { Debug.Log(productID + " isn't available product"); return; } storeController.InitiatePurchase(productID); }
public void Init() { this.mHandler.onInitSuccess += this.OnInitSuccess; this.mHandler.onInitFailed += this.OnInitFailed; this.mHandler.onProcessPurchase += this.OnProcessPurchase; this.mHandler.onPurchaseFailed += this.OnPurchaseFailed; var catalog = ProductCatalog.LoadDefaultCatalog(); StandardPurchasingModule module = StandardPurchasingModule.Instance(); module.useFakeStoreUIMode = FakeStoreUIMode.StandardUser; ConfigurationBuilder builder = ConfigurationBuilder.Instance(module); IAPHelper.PopulateConfigurationBuilder(ref builder, catalog); UnityPurchasing.Initialize(this.mHandler, builder); }
public void getInAppPackButtons(string response) { var sdkInfo = JsonUtility.FromJson <YGame.SDKInfo>(response); // sdkInfo is C# object created from api json response var productCatalog = ProductCatalog.LoadDefaultCatalog(); // Load default catalog from default catalog file for (int i = 0; i < sdkInfo.inAppConf.Count; i++) { inAppPacks.Add(Instantiate(inAppPackPrefab)); // Save important info such as payment_id, etc. in InAppPacks for later API call usages var currentButton = ((GameObject)inAppPacks[i]); currentButton.GetComponent <InAppPackInfo>().paymentId = sdkInfo.inAppConf[i].paymentId; currentButton.transform.SetParent(inAppPackGrid.transform, false); currentButton.GetComponent <IAPButton>().onPurchaseComplete.AddListener(callGoogleInAppAPI); currentButton.GetComponent <IAPButton>().productId = sdkInfo.inAppConf[i].paymentId; // Get in app pack button textures dynamically from response icon urls StartCoroutine(getButtonTexture(sdkInfo.inAppConf[i].icon, i)); productCatalog.Add(new ProductCatalogItem { id = sdkInfo.inAppConf[i].paymentId, type = ProductType.Consumable }); } // Overwrite exisiting default catalog file if (File.Exists("Assets/Resources/IAPProductCatalog.json")) { File.WriteAllText("Assets/Resources/IAPProductCatalog.json", ProductCatalog.Serialize(productCatalog)); } else { Debug.LogError("IAPProductCatalog.json does not exists!"); } for (int i = 0; i < inAppPacks.Count; i++) { ((GameObject)inAppPacks[i]).SetActive(true); } }
public override void OnInspectorGUI() { IAPButton button = (IAPButton)target; serializedObject.Update(); if (button.buttonType == IAPButton.ButtonType.Purchase) { EditorGUILayout.LabelField(new GUIContent("Product ID:", "Select a product from the IAP catalog")); var catalog = ProductCatalog.LoadDefaultCatalog(); m_ValidIDs.Clear(); m_ValidIDs.Add(kNoProduct); foreach (var product in catalog.allProducts) { m_ValidIDs.Add(product.id); } int currentIndex = string.IsNullOrEmpty(button.productId) ? 0 : m_ValidIDs.IndexOf(button.productId); int newIndex = EditorGUILayout.Popup(currentIndex, m_ValidIDs.ToArray()); if (newIndex > 0 && newIndex < m_ValidIDs.Count) { m_ProductIDProperty.stringValue = m_ValidIDs[newIndex]; } else { m_ProductIDProperty.stringValue = string.Empty; } if (GUILayout.Button("IAP Catalog...")) { ProductCatalogEditor.ShowWindow(); } } DrawPropertiesExcluding(serializedObject, button.buttonType == IAPButton.ButtonType.Restore ? restoreButtonExcludedFields : excludedFields); serializedObject.ApplyModifiedProperties(); }
private void init() { StandardPurchasingModule first = StandardPurchasingModule.Instance(); first.useFakeStoreUIMode = FakeStoreUIMode.StandardUser; ConfigurationBuilder builder = ConfigurationBuilder.Instance(first, Array.Empty <IPurchasingModule>()); builder.useCatalogProvider = true; builder.Configure <IMoolahConfiguration>().appKey = "ea6cb49d4d909aa31691e0472c6044f4"; builder.Configure <IMoolahConfiguration>().hashKey = "cc"; builder.Configure <IUnityChannelConfiguration>().fetchReceiptPayloadOnPurchase = false; ProductCatalog catalog = ProductCatalog.LoadDefaultCatalog(); int key = 0; foreach (ProductCatalogItem item in catalog.allValidProducts) { if (item.allStoreIDs.Count > 0) { IDs storeIDs = new IDs(); foreach (StoreID eid in item.allStoreIDs) { string[] stores = new string[] { eid.store }; storeIDs.Add(eid.id, stores); } this.mProductList.Add(key, item.id); key++; builder.AddProduct(item.id, item.type, storeIDs); } else { this.mProductList.Add(key, item.id); key++; builder.AddProduct(item.id, item.type); } } builder.Configure <IMoolahConfiguration>().SetMode(CloudMoolahMode.AlwaysSucceed); this.validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.identifier); UnityPurchasing.Initialize(this, builder); }
private void Start() { StandardPurchasingModule module = StandardPurchasingModule.Instance(); ProductCatalog catalog = ProductCatalog.LoadDefaultCatalog(); ConfigurationBuilder builder = ConfigurationBuilder.Instance(module); IAPConfigurationHelper.PopulateConfigurationBuilder(ref builder, catalog); UnityPurchasing.Initialize(this, builder); string gameId = null; if (Application.platform == RuntimePlatform.IPhonePlayer) { gameId = this.iosGameId; } else if (Application.platform == RuntimePlatform.Android) { gameId = this.androidGameId; } if (!Advertisement.isSupported || Advertisement.isInitialized) { return; } if (this.useStagingUrls) { Debug.Log("Using staging URLs:\n" + "\tConfig URL: " + this.configUrl + "\n" + "\tServer URL: " + this.serverUrl); MetaData metaDataObj = new MetaData("test"); metaDataObj.Set("configUrl", this.configUrl); metaDataObj.Set("serverUrl", this.serverUrl); Advertisement.SetMetaData(metaDataObj); } Debug.Log("Advertisement initializing with: gameId=" + gameId + ", testMode=" + testMode); Advertisement.Initialize(gameId, this.testMode); }
public void Awake() { var module = StandardPurchasingModule.Instance(); // The FakeStore supports: no-ui (always succeeding), basic ui (purchase pass/fail), and // developer ui (initialization, purchase, failure code setting). These correspond to // the FakeStoreUIMode Enum values passed into StandardPurchasingModule.useFakeStoreUIMode. module.useFakeStoreUIMode = FakeStoreUIMode.StandardUser; var builder = ConfigurationBuilder.Instance(module); // This enables the Microsoft IAP simulator for local testing. // You would remove this before building your release package. builder.Configure <IMicrosoftConfiguration>().useMockBillingSystem = true; m_IsGooglePlayStoreSelected = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.GooglePlay; // CloudMoolah Configuration setings // All games must set the configuration. the configuration need to apply on the CloudMoolah Portal. // CloudMoolah APP Key builder.Configure <IMoolahConfiguration>().appKey = "d93f4564c41d463ed3d3cd207594ee1b"; // CloudMoolah Hash Key builder.Configure <IMoolahConfiguration>().hashKey = "cc"; // This enables the CloudMoolah test mode for local testing. // You would remove this, or set to CloudMoolahMode.Production, before building your release package. builder.Configure <IMoolahConfiguration>().SetMode(CloudMoolahMode.AlwaysSucceed); // This records whether we are using Cloud Moolah IAP. // Cloud Moolah requires logging in to access your Digital Wallet, so: // A) IAPDemo (this) displays the Cloud Moolah GUI button for Cloud Moolah m_IsCloudMoolahStoreSelected = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.CloudMoolah; // UnityChannel, provides access to Xiaomi MiPay. // Products are required to be set in the IAP Catalog window. The file "MiProductCatalog.prop" // is required to be generated into the project's // Assets/Plugins/Android/assets folder, based off the contents of the // IAP Catalog window, for MiPay. m_IsUnityChannelSelected = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.XiaomiMiPay; // UnityChannel supports receipt validation through a backend fetch. builder.Configure <IUnityChannelConfiguration>().fetchReceiptPayloadOnPurchase = m_FetchReceiptPayloadOnPurchase; // Define our products. // Either use the Unity IAP Catalog, or manually use the ConfigurationBuilder.AddProduct API. // Use IDs from both the Unity IAP Catalog and hardcoded IDs via the ConfigurationBuilder.AddProduct API. // Use the products defined in the IAP Catalog GUI. // E.g. Menu: "Window" > "Unity IAP" > "IAP Catalog", then add products, then click "App Store Export". var catalog = ProductCatalog.LoadDefaultCatalog(); foreach (var product in catalog.allProducts) { if (product.allStoreIDs.Count > 0) { var ids = new IDs(); foreach (var storeID in product.allStoreIDs) { ids.Add(storeID.id, storeID.store); } builder.AddProduct(product.id, product.type, ids); } else { builder.AddProduct(product.id, product.type); } } // In this case our products have the same identifier across all the App stores, // except on the Mac App store where product IDs cannot be reused across both Mac and // iOS stores. // So on the Mac App store our products have different identifiers, // and we tell Unity IAP this by using the IDs class. builder.AddProduct("100.gold.coins", ProductType.Consumable, new IDs { { "100.gold.coins.mac", MacAppStore.Name }, { "000000596586", TizenStore.Name }, { "com.ff", MoolahAppStore.Name }, } #if USE_PAYOUTS , new PayoutDefinition(PayoutType.Currency, "gold", 100) #endif //USE_PAYOUTS ); builder.AddProduct("500.gold.coins", ProductType.Consumable, new IDs { { "500.gold.coins.mac", MacAppStore.Name }, { "000000596581", TizenStore.Name }, { "com.ee", MoolahAppStore.Name }, } #if USE_PAYOUTS , new PayoutDefinition(PayoutType.Currency, "gold", 500) #endif //USE_PAYOUTS ); builder.AddProduct("sword", ProductType.NonConsumable, new IDs { { "sword.mac", MacAppStore.Name }, { "000000596583", TizenStore.Name }, } #if USE_PAYOUTS , new List <PayoutDefinition> { new PayoutDefinition(PayoutType.Item, "", 1, "item_id:76543"), new PayoutDefinition(PayoutType.Currency, "gold", 50) } #endif //USE_PAYOUTS ); builder.AddProduct("subscription", ProductType.Subscription, new IDs { { "subscription.mac", MacAppStore.Name } }); // Write Amazon's JSON description of our products to storage when using Amazon's local sandbox. // This should be removed from a production build. builder.Configure <IAmazonConfiguration>().WriteSandboxJSON(builder.products); // This enables simulated purchase success for Samsung IAP. // You would remove this, or set to SamsungAppsMode.Production, before building your release package. builder.Configure <ISamsungAppsConfiguration>().SetMode(SamsungAppsMode.AlwaysSucceed); // This records whether we are using Samsung IAP. Currently ISamsungAppsExtensions.RestoreTransactions // displays a blocking Android Activity, so: // A) Unity IAP does not automatically restore purchases on Samsung Galaxy Apps // B) IAPDemo (this) displays the "Restore" GUI button for Samsung Galaxy Apps m_IsSamsungAppsStoreSelected = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.SamsungApps; // This selects the GroupId that was created in the Tizen Store for this set of products // An empty or non-matching GroupId here will result in no products available for purchase builder.Configure <ITizenStoreConfiguration>().SetGroupId("100000085616"); #if RECEIPT_VALIDATION string appIdentifier; #if UNITY_5_6_OR_NEWER appIdentifier = Application.identifier; #else appIdentifier = Application.bundleIdentifier; #endif validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), UnityChannelTangle.Data(), appIdentifier); #endif Action initializeUnityIap = () => { // Now we're ready to initialize Unity IAP. UnityPurchasing.Initialize(this, builder); }; bool needExternalLogin = m_IsUnityChannelSelected; if (!needExternalLogin) { initializeUnityIap(); } else { // Call UnityChannel initialize and (later) login asynchronously // UnityChannel configuration settings. Required for Xiaomi MiPay. // Collect this app configuration from the Unity Developer website at // [2017-04-17 PENDING - Contact support representative] // https://developer.cloud.unity3d.com/ providing your Xiaomi MiPay App // ID, App Key, and App Secret. This permits Unity to proxy from the // user's device into the MiPay system. // IMPORTANT PRE-BUILD STEP: For mandatory Chinese Government app auditing // and for MiPay testing, enable debug mode (test mode) // using the `AppInfo.debug = true;` when initializing Unity Channel. AppInfo unityChannelAppInfo = new AppInfo(); unityChannelAppInfo.appId = "abc123appId"; unityChannelAppInfo.appKey = "efg456appKey"; unityChannelAppInfo.clientId = "hij789clientId"; unityChannelAppInfo.clientKey = "klm012clientKey"; unityChannelAppInfo.debug = false; // Shared handler for Unity Channel initialization, here, and login, later unityChannelLoginHandler = new UnityChannelLoginHandler(); unityChannelLoginHandler.initializeFailedAction = (string message) => { Debug.LogError("Failed to initialize and login to UnityChannel: " + message); }; unityChannelLoginHandler.initializeSucceededAction = () => { initializeUnityIap(); }; StoreService.Initialize(unityChannelAppInfo, unityChannelLoginHandler); } }
/// <summary> /// Awake is called when the script instance is being loaded. /// </summary> public void Awake() { var module = StandardPurchasingModule.Instance(); // The FakeStore supports: no-ui (always succeeding), basic ui (purchase pass/fail), and // developer ui (initialization, purchase, failure code setting). These correspond to // the FakeStoreUIMode Enum values passed into StandardPurchasingModule.useFakeStoreUIMode. module.useFakeStoreUIMode = FakeStoreUIMode.StandardUser; var builder = ConfigurationBuilder.Instance(module); // Set this to true to enable the Microsoft IAP simulator for local testing. builder.Configure <IMicrosoftConfiguration>().useMockBillingSystem = false; m_IsGooglePlayStoreSelected = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.GooglePlay; // Define our products. // Either use the Unity IAP Catalog, or manually use the ConfigurationBuilder.AddProduct API. // Use IDs from both the Unity IAP Catalog and hardcoded IDs via the ConfigurationBuilder.AddProduct API. // Use the products defined in the IAP Catalog GUI. // E.g. Menu: "Window" > "Unity IAP" > "IAP Catalog", then add products, then click "App Store Export". var catalog = ProductCatalog.LoadDefaultCatalog(); foreach (var product in catalog.allValidProducts) { if (product.allStoreIDs.Count > 0) { var ids = new IDs(); foreach (var storeID in product.allStoreIDs) { ids.Add(storeID.id, storeID.store); } builder.AddProduct(product.id, product.type, ids); } else { builder.AddProduct(product.id, product.type); } } // In this case our products have the same identifier across all the App stores, // except on the Mac App store where product IDs cannot be reused across both Mac and // iOS stores. // So on the Mac App store our products have different identifiers, // and we tell Unity IAP this by using the IDs class. builder.AddProduct("100.gold.coins", ProductType.Consumable, new IDs { { "com.unity3d.unityiap.unityiapdemo.100goldcoins.7", MacAppStore.Name }, { "100.gold.coins", AmazonApps.Name }, { "100.gold.coins", AppleAppStore.Name } } #if USE_PAYOUTS , new List <PayoutDefinition> { new PayoutDefinition(PayoutType.Item, "", 1, "item_id:76543"), new PayoutDefinition(PayoutType.Currency, "gold", 50) } #endif //USE_PAYOUTS ); builder.AddProduct("500.gold.coins", ProductType.Consumable, new IDs { { "com.unity3d.unityiap.unityiapdemo.500goldcoins.7", MacAppStore.Name }, { "500.gold.coins", AmazonApps.Name }, } #if USE_PAYOUTS , new PayoutDefinition(PayoutType.Currency, "gold", 500) #endif //USE_PAYOUTS ); builder.AddProduct("300.gold.coins", ProductType.Consumable, new IDs { } #if USE_PAYOUTS , new List <PayoutDefinition> { new PayoutDefinition(PayoutType.Item, "", 1, "item_id:76543"), new PayoutDefinition(PayoutType.Currency, "gold", 50) } #endif //USE_PAYOUTS ); builder.AddProduct("sub1", ProductType.Subscription, new IDs { }); builder.AddProduct("sub2", ProductType.Subscription, new IDs { }); // Write Amazon's JSON description of our products to storage when using Amazon's local sandbox. // This should be removed from a production build. //builder.Configure<IAmazonConfiguration>().WriteSandboxJSON(builder.products); #if INTERCEPT_PROMOTIONAL_PURCHASES // On iOS and tvOS we can intercept promotional purchases that come directly from the App Store. // On other platforms this will have no effect; OnPromotionalPurchase will never be called. builder.Configure <IAppleConfiguration>().SetApplePromotionalPurchaseInterceptorCallback(OnPromotionalPurchase); Debug.Log("Setting Apple promotional purchase interceptor callback"); #endif #if RECEIPT_VALIDATION string appIdentifier; #if UNITY_5_6_OR_NEWER appIdentifier = Application.identifier; #else appIdentifier = Application.bundleIdentifier; #endif try { validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), appIdentifier); } catch (NotImplementedException exception) { Debug.Log("Cross Platform Validator Not Implemented: " + exception); } #endif // Now we're ready to initialize Unity IAP. UnityPurchasing.Initialize(this, builder); }
public void Awake() { var module = StandardPurchasingModule.Instance(); // The FakeStore supports: no-ui (always succeeding), basic ui (purchase pass/fail), and // developer ui (initialization, purchase, failure code setting). These correspond to // the FakeStoreUIMode Enum values passed into StandardPurchasingModule.useFakeStoreUIMode. module.useFakeStoreUIMode = FakeStoreUIMode.StandardUser; var builder = ConfigurationBuilder.Instance(module); // Set this to true to enable the Microsoft IAP simulator for local testing. builder.Configure <IMicrosoftConfiguration>().useMockBillingSystem = false; m_IsGooglePlayStoreSelected = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.GooglePlay; builder.Configure <IGooglePlayConfiguration>().SetPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoijNfTc9kS+M6R12DNc32dG7Mrg/czFABHPgYg8IQ8xebBoQMRXGEbmm4CHoNxCSJk+Fcs05wTogSsGbN0uemOmJUwCYowLQxzIeOBqH4aB2kDqMSDqKJnK08wDUFtDIrIBsczFincIW4i0E4JqtrGPksqn/tG5SvKvheG4x8yUcLWbd/MC885cZY1lMoRsaakVf/EoMfqtOccH+1x2dFVh0Q/NTAkgExILsN4KXHTpM2mHLKr6Dv3NK9ueYsLvf39kL9CwLZFFyD3413cyqtR4ZdfHL0BHw+9rSr0uysMtU3SGfqBHgyjMVNFL0eL6txWgVDhL3MaAXokIm0CePiwIDAQAB"); #if AGGRESSIVE_INTERRUPT_RECOVERY_GOOGLEPLAY // For GooglePlay, if we have access to a backend server to deduplicate purchases, query purchase history // when attempting to recover from a network-interruption encountered during purchasing. Strongly recommend // deduplicating transactions across app reinstallations because this relies upon the on-device, deletable // TransactionLog database. builder.Configure <IGooglePlayConfiguration>().aggressivelyRecoverLostPurchases = true; #endif // Define our products. // Either use the Unity IAP Catalog, or manually use the ConfigurationBuilder.AddProduct API. // Use IDs from both the Unity IAP Catalog and hardcoded IDs via the ConfigurationBuilder.AddProduct API. // Use the products defined in the IAP Catalog GUI. // E.g. Menu: "Window" > "Unity IAP" > "IAP Catalog", then add products, then click "App Store Export". var catalog = ProductCatalog.LoadDefaultCatalog(); foreach (var product in catalog.allValidProducts) { if (product.allStoreIDs.Count > 0) { var ids = new IDs(); foreach (var storeID in product.allStoreIDs) { ids.Add(storeID.id, storeID.store); } builder.AddProduct(product.id, product.type, ids); } else { builder.AddProduct(product.id, product.type); } } // In this case our products have the same identifier across all the App stores, // except on the Mac App store where product IDs cannot be reused across both Mac and // iOS stores. // So on the Mac App store our products have different identifiers, // and we tell Unity IAP this by using the IDs class. // builder.AddProduct("100.gold.coins", ProductType.Consumable, new IDs // { // {"com.unity3d.unityiap.unityiapdemo.100goldcoins.7", MacAppStore.Name}, // {"100.gold.coins", AmazonApps.Name}, // {"100.gold.coins", AppleAppStore.Name} // } // #if USE_PAYOUTS // , new List<PayoutDefinition> { // new PayoutDefinition(PayoutType.Item, "", 1, "item_id:76543"), // new PayoutDefinition(PayoutType.Currency, "gold", 50) // } // #endif //USE_PAYOUTS // ); // // builder.AddProduct("500.gold.coins", ProductType.Consumable, new IDs // { // {"com.unity3d.unityiap.unityiapdemo.500goldcoins.7", MacAppStore.Name}, // {"500.gold.coins", AmazonApps.Name}, // } // #if USE_PAYOUTS // , new PayoutDefinition(PayoutType.Currency, "gold", 500) // #endif //USE_PAYOUTS // ); // // builder.AddProduct("300.gold.coins", ProductType.Consumable, new IDs // { // } // #if USE_PAYOUTS // , new List<PayoutDefinition> { // new PayoutDefinition(PayoutType.Item, "", 1, "item_id:76543"), // new PayoutDefinition(PayoutType.Currency, "gold", 50) // } // #endif //USE_PAYOUTS // ); builder.AddProduct("sub1week", ProductType.Subscription, new IDs { }); builder.AddProduct("sub1month", ProductType.Subscription, new IDs { }); // Write Amazon's JSON description of our products to storage when using Amazon's local sandbox. // This should be removed from a production build. //builder.Configure<IAmazonConfiguration>().WriteSandboxJSON(builder.products); // This enables simulated purchase success for Samsung IAP. // You would remove this, or set to SamsungAppsMode.Production, before building your release package. builder.Configure <ISamsungAppsConfiguration>().SetMode(SamsungAppsMode.AlwaysSucceed); // This records whether we are using Samsung IAP. Currently ISamsungAppsExtensions.RestoreTransactions // displays a blocking Android Activity, so: // A) Unity IAP does not automatically restore purchases on Samsung Galaxy Apps // B) IAPDemo (this) displays the "Restore" GUI button for Samsung Galaxy Apps m_IsSamsungAppsStoreSelected = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.SamsungApps; #if INTERCEPT_PROMOTIONAL_PURCHASES // On iOS and tvOS we can intercept promotional purchases that come directly from the App Store. // On other platforms this will have no effect; OnPromotionalPurchase will never be called. builder.Configure <IAppleConfiguration>().SetApplePromotionalPurchaseInterceptorCallback(OnPromotionalPurchase); Debug.Log("Setting Apple promotional purchase interceptor callback"); #endif #if RECEIPT_VALIDATION string appIdentifier; #if UNITY_5_6_OR_NEWER appIdentifier = Application.identifier; #else appIdentifier = Application.bundleIdentifier; #endif validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), appIdentifier); #endif // Now we're ready to initialize Unity IAP. UnityPurchasing.Initialize(this, builder); }
public InApp(TranslationLocale locale) { _locale = (UnityEngine.Purchasing.TranslationLocale)(int) locale; // ключи для PlayerPrefs var temp = new Product(string.Empty); string _baseKey = nameof(InApp); _keyForCheckSave = _baseKey + "IsSave"; _keyForTitle = _baseKey + nameof(temp.Title); _keyForDescription = _baseKey + nameof(temp.Description); _keyForPrice = _baseKey + nameof(temp.Price); _keyForCheckIsBy = _baseKey + nameof(temp.IsBuy); bool isAndroid = false; #if UNITY_EDITOR isAndroid = (EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS) == false; #elif UNITY_IPHONE isAndroid = false; #elif UNITY_ANDROID isAndroid = true; #else isAndroid = true; #endif // подтягиваем ценники для appstore для iphone Dictionary <int, decimal> appStorePriceTiers = null; if (isAndroid == false) { appStorePriceTiers = new AppStoreListTiersCreator().GetValues(); } // находим и сетим иконки для продуктов Dictionary <string, Sprite> productIcons = null; ProductIcons productIconsContainer = Resources.Load <ProductIcons>(ProductIcons.RESOURCES_PATH); if (productIconsContainer != null) { productIcons = productIconsContainer.GetProductIconsList(); } else { Debug.LogError($"Не найден файл по пути {ProductIcons.RESOURCES_PATH} !"); } string decimalFormatingStyle = STRING_MODIFICATOR_FOR_PRICE; string paymentCurrency = "RUB"; // заполняем продукты из сохраненных данных - по умолчанию или из PlayerPrefs var defaultCatalog = ProductCatalog.LoadDefaultCatalog(); foreach (var defaultProduct in defaultCatalog.allValidProducts) { var product = new Product(defaultProduct.id); bool productIsSave = PlayerPrefs.GetString(_keyForCheckSave + product.Id, false.ToString()) == true.ToString(); if (productIsSave) { //формируем продукт из PlayerPrefs product.title = PlayerPrefs.GetString(_keyForTitle + product.Id, string.Empty); product.description = PlayerPrefs.GetString(_keyForDescription + product.Id, string.Empty); product.price = PlayerPrefs.GetString(_keyForPrice + product.Id, string.Empty); product.isBuy = PlayerPrefs.GetString(_keyForCheckIsBy + defaultProduct.id, false.ToString()) == true.ToString(); if (new List <string>() { product.title, product.description, product.price, product.isBuy.ToString() } .Exists(parameters => string.IsNullOrEmpty(parameters)) == true) { Debug.LogError($"Один из параметров продукта {product.Id} не был корректно сохранен!"); } } else { //формируем продукт ProductCatalog (дефолтные значения) var translation = defaultProduct.GetDescription(_locale); if (translation == null) { translation = defaultProduct.defaultDescription; } product.title = translation.Title; product.description = translation.Description; string price = string.Empty; if (isAndroid) { price = defaultProduct.googlePrice.value.ToString(decimalFormatingStyle); } else { int tier = defaultProduct.applePriceTier; if (appStorePriceTiers.ContainsKey(tier)) { price = appStorePriceTiers[tier].ToString(decimalFormatingStyle); } else { Debug.LogError($"Ошибка при поиске ценника для Appstore по словарю appStorePriceTiers " + $"для продукта {product.Id}: В словаре нет такого ключа."); price = "9.99"; } } product.price = $"{price} {paymentCurrency}"; product.isBuy = false; //сохраняем продукт в PlayerPrefs'ы SaveProductToPlayerPrefs(product); } product.productType = defaultProduct.type; product.MarketIds = new IDs(); defaultProduct.allStoreIDs.ToList().ForEach(marketId => product.MarketIds.Add(marketId.id, marketId.store)); // сетим иконку if (productIcons != null) { if (productIcons.ContainsKey(product.Id)) { Sprite icon = productIcons[product.Id]; if (icon != null) { product.icon = icon; } else { Debug.LogError($"В словаре {productIcons} по ключу {product.Id} отсутствует значение"); } } else { Debug.LogError($"В словаре {productIcons} нет такого ключа, как {product.Id}"); } } _products.Add(product); } }
public void Awake() { var module = StandardPurchasingModule.Instance(); // The FakeStore supports: no-ui (always succeeding), basic ui (purchase pass/fail), and // developer ui (initialization, purchase, failure code setting). These correspond to // the FakeStoreUIMode Enum values passed into StandardPurchasingModule.useFakeStoreUIMode. module.useFakeStoreUIMode = FakeStoreUIMode.StandardUser; var builder = ConfigurationBuilder.Instance(module); // Set this to true to enable the Microsoft IAP simulator for local testing. builder.Configure <IMicrosoftConfiguration>().useMockBillingSystem = false; m_IsGooglePlayStoreSelected = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.GooglePlay; // CloudMoolah Configuration setings // All games must set the configuration. the configuration need to apply on the CloudMoolah Portal. // CloudMoolah APP Key builder.Configure <IMoolahConfiguration>().appKey = "d93f4564c41d463ed3d3cd207594ee1b"; // CloudMoolah Hash Key builder.Configure <IMoolahConfiguration>().hashKey = "cc"; // This enables the CloudMoolah test mode for local testing. // You would remove this, or set to CloudMoolahMode.Production, before building your release package. builder.Configure <IMoolahConfiguration>().SetMode(CloudMoolahMode.AlwaysSucceed); // This records whether we are using Cloud Moolah IAP. // Cloud Moolah requires logging in to access your Digital Wallet, so: // A) IAPDemo (this) displays the Cloud Moolah GUI button for Cloud Moolah m_IsCloudMoolahStoreSelected = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.CloudMoolah; // Define our products. // Either use the Unity IAP Catalog, or manually use the ConfigurationBuilder.AddProduct API. // Use IDs from both the Unity IAP Catalog and hardcoded IDs via the ConfigurationBuilder.AddProduct API. // Use the products defined in the IAP Catalog GUI. // E.g. Menu: "Window" > "Unity IAP" > "IAP Catalog", then add products, then click "App Store Export". var catalog = ProductCatalog.LoadDefaultCatalog(); foreach (var product in catalog.allValidProducts) { if (product.allStoreIDs.Count > 0) { var ids = new IDs(); foreach (var storeID in product.allStoreIDs) { ids.Add(storeID.id, storeID.store); } builder.AddProduct(product.id, product.type, ids); } else { builder.AddProduct(product.id, product.type); } } // In this case our products have the same identifier across all the App stores, // except on the Mac App store where product IDs cannot be reused across both Mac and // iOS stores. // So on the Mac App store our products have different identifiers, // and we tell Unity IAP this by using the IDs class. builder.AddProduct("100.gold.coins", ProductType.Consumable, new IDs { { "com.unity3d.unityiap.unityiapdemo.100goldcoins.7", MacAppStore.Name }, { "000000596586", TizenStore.Name }, { "com.ff", MoolahAppStore.Name }, { "100.gold.coins", AmazonApps.Name }, { "100.gold.coins", AppleAppStore.Name } } #if USE_PAYOUTS , new List <PayoutDefinition> { new PayoutDefinition(PayoutType.Item, "", 1, "item_id:76543"), new PayoutDefinition(PayoutType.Currency, "gold", 50) } #endif //USE_PAYOUTS ); builder.AddProduct("500.gold.coins", ProductType.Consumable, new IDs { { "com.unity3d.unityiap.unityiapdemo.500goldcoins.7", MacAppStore.Name }, { "000000596581", TizenStore.Name }, { "com.ee", MoolahAppStore.Name }, { "500.gold.coins", AmazonApps.Name }, } #if USE_PAYOUTS , new PayoutDefinition(PayoutType.Currency, "gold", 500) #endif //USE_PAYOUTS ); builder.AddProduct("300.gold.coins", ProductType.Consumable, new IDs { } #if USE_PAYOUTS , new List <PayoutDefinition> { new PayoutDefinition(PayoutType.Item, "", 1, "item_id:76543"), new PayoutDefinition(PayoutType.Currency, "gold", 50) } #endif //USE_PAYOUTS ); builder.AddProduct("sub1", ProductType.Subscription, new IDs { }); builder.AddProduct("sub2", ProductType.Subscription, new IDs { }); // Write Amazon's JSON description of our products to storage when using Amazon's local sandbox. // This should be removed from a production build. //builder.Configure<IAmazonConfiguration>().WriteSandboxJSON(builder.products); // This enables simulated purchase success for Samsung IAP. // You would remove this, or set to SamsungAppsMode.Production, before building your release package. builder.Configure <ISamsungAppsConfiguration>().SetMode(SamsungAppsMode.AlwaysSucceed); // This records whether we are using Samsung IAP. Currently ISamsungAppsExtensions.RestoreTransactions // displays a blocking Android Activity, so: // A) Unity IAP does not automatically restore purchases on Samsung Galaxy Apps // B) IAPDemo (this) displays the "Restore" GUI button for Samsung Galaxy Apps m_IsSamsungAppsStoreSelected = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.SamsungApps; // This selects the GroupId that was created in the Tizen Store for this set of products // An empty or non-matching GroupId here will result in no products available for purchase builder.Configure <ITizenStoreConfiguration>().SetGroupId("100000085616"); #if INTERCEPT_PROMOTIONAL_PURCHASES // On iOS and tvOS we can intercept promotional purchases that come directly from the App Store. // On other platforms this will have no effect; OnPromotionalPurchase will never be called. builder.Configure <IAppleConfiguration>().SetApplePromotionalPurchaseInterceptorCallback(OnPromotionalPurchase); Debug.Log("Setting Apple promotional purchase interceptor callback"); #endif #if RECEIPT_VALIDATION string appIdentifier; #if UNITY_5_6_OR_NEWER appIdentifier = Application.identifier; #else appIdentifier = Application.bundleIdentifier; #endif validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), appIdentifier); #endif // Now we're ready to initialize Unity IAP. UnityPurchasing.Initialize(this, builder); }
public void ExportCatalog() { var allItems = gameInstance.GetAllItems(); var catalogItems = new Dictionary <string, CatalogItem>(); if (allItems != null) { foreach (var item in allItems) { if (item == null) { continue; } var virtualCurrencyPrices = new Dictionary <string, int>(); if (!string.IsNullOrEmpty(item.price.id)) { virtualCurrencyPrices[item.price.id] = item.price.amount; } if (item.prices != null) { foreach (var price in item.prices) { if (price == null) { continue; } if (!string.IsNullOrEmpty(price.id)) { virtualCurrencyPrices[price.id] = price.amount; } } } catalogItems[item.GetId()] = new CatalogItem() { ItemId = item.GetId(), CatalogVersion = exportingCatalogVersion, DisplayName = item.GetTitle(), Description = item.GetDescription(), VirtualCurrencyPrices = virtualCurrencyPrices, CustomData = JsonMapper.ToJson(new ItemCustomData() { PricesOption = (byte)InGameProductData.PricesOption.Alternative, CanBuyOnlyOnce = item.canBuyOnlyOnce, }), Consumable = new CatalogConsumable(), Bundle = new CatalogBundle(), }; } } var packageCatalogDict = new Dictionary <string, InGamePackageData>(); if (packages != null) { foreach (var bundle in packages) { if (bundle == null) { continue; } var virtualCurrencyPrices = new Dictionary <string, int>(); if (!string.IsNullOrEmpty(bundle.price.id)) { virtualCurrencyPrices[bundle.price.id] = bundle.price.amount; } if (bundle.prices != null) { foreach (var price in bundle.prices) { if (price == null) { continue; } if (!string.IsNullOrEmpty(price.id)) { virtualCurrencyPrices[price.id] = price.amount; } } } var itemIds = new List <string>(); if (bundle.items != null) { foreach (var item in bundle.items) { if (item == null) { continue; } itemIds.Add(item.GetId()); } } var rewardCurrencies = new Dictionary <string, int>(); if (bundle.currencies != null) { foreach (var currency in bundle.currencies) { if (currency == null) { continue; } rewardCurrencies[currency.id] = currency.amount; } } catalogItems[bundle.GetId()] = new CatalogItem() { ItemId = bundle.GetId(), CatalogVersion = exportingCatalogVersion, DisplayName = bundle.GetTitle(), Description = bundle.GetDescription(), VirtualCurrencyPrices = virtualCurrencyPrices, CustomData = JsonMapper.ToJson(new ItemCustomData() { PricesOption = (byte)InGameProductData.PricesOption.Alternative, CanBuyOnlyOnce = bundle.canBuyOnlyOnce, }), Consumable = new CatalogConsumable(), Bundle = new CatalogBundle() { BundledItems = itemIds, BundledVirtualCurrencies = rewardCurrencies, } }; } } #if !NO_IAP && UNITY_PURCHASING var iapCatalog = ProductCatalog.LoadDefaultCatalog(); var iapCatalogDict = new Dictionary <string, ProductCatalogItem>(); if (iapCatalog.allProducts != null) { foreach (var product in iapCatalog.allProducts) { if (product == null) { continue; } iapCatalogDict[product.id] = product; } } var allBundles = monetizationManager.products; if (allBundles != null) { ProductCatalogItem tempIAPItem; foreach (var bundle in allBundles) { if (bundle == null) { continue; } var virtualCurrencyPrices = new Dictionary <string, int>(); virtualCurrencyPrices.Add("RM", 0); // TODO: SET USD PRICE var itemIds = new List <string>(); if (bundle.items != null) { foreach (var item in bundle.items) { if (item == null) { continue; } itemIds.Add(item.GetId()); } } var rewardCurrencies = new Dictionary <string, int>(); if (bundle.currencies != null) { foreach (var currency in bundle.currencies) { if (currency == null) { continue; } rewardCurrencies[currency.id] = currency.amount; } } if (iapCatalogDict.TryGetValue(bundle.GetId(), out tempIAPItem)) { // Google play if (!string.IsNullOrEmpty(tempIAPItem.GetStoreID(GooglePlay.Name))) { catalogItems[tempIAPItem.GetStoreID(GooglePlay.Name)] = new CatalogItem() { ItemId = tempIAPItem.GetStoreID(GooglePlay.Name), CatalogVersion = exportingCatalogVersion, DisplayName = bundle.GetTitle(), Description = bundle.GetDescription(), VirtualCurrencyPrices = virtualCurrencyPrices, Consumable = new CatalogConsumable() { UsagePeriod = 3, }, Bundle = new CatalogBundle() { BundledItems = itemIds, BundledVirtualCurrencies = rewardCurrencies, } }; } else { Debug.LogWarning("[PlayfabMonetizationExporter] IAP items's GooglePlay store ID override does not set."); } // Apple appstore if (!string.IsNullOrEmpty(tempIAPItem.GetStoreID(AppleAppStore.Name))) { catalogItems[tempIAPItem.GetStoreID(AppleAppStore.Name)] = new CatalogItem() { ItemId = tempIAPItem.GetStoreID(AppleAppStore.Name), CatalogVersion = exportingCatalogVersion, DisplayName = bundle.GetTitle(), Description = bundle.GetDescription(), VirtualCurrencyPrices = virtualCurrencyPrices, Consumable = new CatalogConsumable() { UsagePeriod = 3, }, Bundle = new CatalogBundle() { BundledItems = itemIds, BundledVirtualCurrencies = rewardCurrencies, } }; } else { Debug.LogWarning("[PlayfabMonetizationExporter] IAP items's AppleAppStore store ID override does not set."); } } } } #endif var dropTables = new List <DropTableItem>(); var catalog = new PlayfabCatalog() { CatalogVersion = exportingCatalogVersion, Catalog = new List <CatalogItem>(catalogItems.Values), DropTables = dropTables, }; var json = JsonMapper.ToJson(catalog); var path = EditorUtility.SaveFilePanel("Export Catalog", Application.dataPath, "CATALOG", "json"); if (path.Length > 0) { File.WriteAllText(path, json); } }
public void Awake() { StandardPurchasingModule module = StandardPurchasingModule.Instance(); // The FakeStore supports: no-ui (always succeeding), basic ui (purchase pass/fail), and // developer ui (initialization, purchase, failure code setting). These correspond to // the FakeStoreUIMode Enum values passed into StandardPurchasingModule.useFakeStoreUIMode. module.useFakeStoreUIMode = FakeStoreUIMode.StandardUser; ConfigurationBuilder builder = ConfigurationBuilder.Instance(module); // Set this to true to enable the Microsoft IAP simulator for local testing. builder.Configure <IMicrosoftConfiguration>().useMockBillingSystem = false; m_IsGooglePlayStoreSelected = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.GooglePlay; #if AGGRESSIVE_INTERRUPT_RECOVERY_GOOGLEPLAY // For GooglePlay, if we have access to a backend server to deduplicate purchases, query purchase history // when attempting to recover from a network-interruption encountered during purchasing. Strongly recommend // deduplicating transactions across app reinstallations because this relies upon the on-device, deletable // TransactionLog database. builder.Configure <IGooglePlayConfiguration>().aggressivelyRecoverLostPurchases = true; // Use purchaseToken instead of orderId for all transactions to avoid non-unique transactionIDs for a // single purchase; two ProcessPurchase calls for one purchase, differing only by which field of the receipt // is used for the Product.transactionID. Automatically true if aggressivelyRecoverLostPurchases is enabled // and this API is not called at all. builder.Configure <IGooglePlayConfiguration>().UsePurchaseTokenForTransactionId(true); #endif // Define our products. // Either use the Unity IAP Catalog, or manually use the ConfigurationBuilder.AddProduct API. // Use IDs from both the Unity IAP Catalog and hardcoded IDs via the ConfigurationBuilder.AddProduct API. // Use the products defined in the IAP Catalog GUI. // E.g. Menu: "Window" > "Unity IAP" > "IAP Catalog", then add products, then click "App Store Export". ProductCatalog catalog = ProductCatalog.LoadDefaultCatalog(); foreach (ProductCatalogItem product in catalog.allValidProducts) { if (product.allStoreIDs.Count > 0) { IDs ids = new IDs(); foreach (StoreID storeID in product.allStoreIDs) { ids.Add(storeID.id, storeID.store); } builder.AddProduct(product.id, product.type, ids); } else { builder.AddProduct(product.id, product.type); } } // In this case our products have the same identifier across all the App stores, // except on the Mac App store where product IDs cannot be reused across both Mac and // iOS stores. // So on the Mac App store our products have different identifiers, // and we tell Unity IAP this by using the IDs class. builder.AddProduct("100.gold.coins", ProductType.Consumable, new IDs { { "com.unity3d.unityiap.unityiapdemo.100goldcoins.7", MacAppStore.Name }, { "100.gold.coins", AmazonApps.Name }, { "100.gold.coins", AppleAppStore.Name } } #if USE_PAYOUTS , new List <PayoutDefinition> { new PayoutDefinition(PayoutType.Item, "", 1, "item_id:76543"), new PayoutDefinition(PayoutType.Currency, "gold", 50) } #endif //USE_PAYOUTS ); builder.AddProduct("500.gold.coins", ProductType.Consumable, new IDs { { "com.unity3d.unityiap.unityiapdemo.500goldcoins.7", MacAppStore.Name }, { "500.gold.coins", AmazonApps.Name }, } #if USE_PAYOUTS , new PayoutDefinition(PayoutType.Currency, "gold", 500) #endif //USE_PAYOUTS ); builder.AddProduct("300.gold.coins", ProductType.Consumable, new IDs() #if USE_PAYOUTS , new List <PayoutDefinition> { new PayoutDefinition(PayoutType.Item, "", 1, "item_id:76543"), new PayoutDefinition(PayoutType.Currency, "gold", 50) } #endif //USE_PAYOUTS ); builder.AddProduct("sub1", ProductType.Subscription, new IDs()); builder.AddProduct("sub2", ProductType.Subscription, new IDs()); // Write Amazon's JSON description of our products to storage when using Amazon's local sandbox. // This should be removed from a production build. //builder.Configure<IAmazonConfiguration>().WriteSandboxJSON(builder.products); // This enables simulated purchase success for Samsung IAP. // You would remove this, or set to SamsungAppsMode.Production, before building your release package. builder.Configure <ISamsungAppsConfiguration>().SetMode(SamsungAppsMode.AlwaysSucceed); // This records whether we are using Samsung IAP. Currently ISamsungAppsExtensions.RestoreTransactions // displays a blocking Android Activity, so: // A) Unity IAP does not automatically restore purchases on Samsung Galaxy Apps // B) IAPDemo (this) displays the "Restore" GUI button for Samsung Galaxy Apps m_IsSamsungAppsStoreSelected = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.SamsungApps; #if INTERCEPT_PROMOTIONAL_PURCHASES // On iOS and tvOS we can intercept promotional purchases that come directly from the App Store. // On other platforms this will have no effect; OnPromotionalPurchase will never be called. builder.Configure <IAppleConfiguration>().SetApplePromotionalPurchaseInterceptorCallback(OnPromotionalPurchase); Debug.Log("Setting Apple promotional purchase interceptor callback"); #endif #if RECEIPT_VALIDATION string appIdentifier; #if UNITY_5_6_OR_NEWER appIdentifier = Application.identifier; #else appIdentifier = Application.bundleIdentifier; #endif validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), appIdentifier); #endif // Now we're ready to initialize Unity IAP. UnityPurchasing.Initialize(this, builder); }
public void Awake() { var module = StandardPurchasingModule.Instance(); // The FakeStore supports: no-ui (always succeeding), basic ui (purchase pass/fail), and // developer ui (initialization, purchase, failure code setting). These correspond to // the FakeStoreUIMode Enum values passed into StandardPurchasingModule.useFakeStoreUIMode. //FakeStore支持:无ui(总是成功)、基本ui(购买/失败),以及 //开发人员ui(初始化、购买、失败代码设置)。这些对应于 //传递给StandardPurchasingModule.useFakeStoreUIMode FakeStoreUIMode枚举值。 //module.useFakeStoreUIMode = FakeStoreUIMode.StandardUser; var builder = ConfigurationBuilder.Instance(module); // This enables the Microsoft IAP simulator for local testing. // You would remove this before building your release package. //这使Microsoft IAP模拟器能够进行本地测试。 //您将在构建您的发布包之前删除它。 builder.Configure <IMicrosoftConfiguration>().useMockBillingSystem = true; //m_IsGooglePlayStoreSelected = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.GooglePlay; // CloudMoolah Configuration setings // All games must set the configuration. the configuration need to apply on the CloudMoolah Portal. // CloudMoolah APP Key //CloudMoolah配置设置 //所有的游戏都必须设定配置。配置需要在CloudMoolah门户上应用。 ////CloudMoolah应用的key //builder.Configure<IMoolahConfiguration>().appKey = "d93f4564c41d463ed3d3cd207594ee1b"; //// CloudMoolah Hash Key //builder.Configure<IMoolahConfiguration>().hashKey = "cc"; // This enables the CloudMoolah test mode for local testing. // You would remove this, or set to CloudMoolahMode.Production, before building your release package. //这使得CloudMoolah测试模式能够进行本地测试。 ////您可以删除这个,或者设置为CloudMoolahMode。在构建您的发布包之前,生产。 //builder.Configure<IMoolahConfiguration>().SetMode(CloudMoolahMode.AlwaysSucceed); // This records whether we are using Cloud Moolah IAP. // Cloud Moolah requires logging in to access your Digital Wallet, so: // A) IAPDemo (this) displays the Cloud Moolah GUI button for Cloud Moolah //这记录了我们是否使用了Cloud Moolah IAP。 //云Moolah需要登录才能进入你的数字钱包,所以: ////A)IAPDemo(这)显示云Moolah GUI按钮 //m_IsCloudMoolahStoreSelected = // Application.platform == RuntimePlatform.Android && module.appStore == AppStore.CloudMoolah; // UnityChannel, provides access to Xiaomi MiPay. // Products are required to be set in the IAP Catalog window. The file "MiProductCatalog.prop" // is required to be generated into the project's // Assets/Plugins/Android/assets folder, based off the contents of the // IAP Catalog window, for MiPay. //UnityChannel,提供对小米MiPay的访问。 //产品需要在IAP目录窗口中设置。文件“MiProductCatalog.prop” //需要被生成到项目中 //资产 / 插件 / Android / 文件夹,基础的内容 //IAP目录窗口,为MiPay。 m_IsUnityChannelSelected = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.XiaomiMiPay; // UnityChannel supports receipt validation through a backend fetch. //UnityChannel通过后台取回支持接收验证。 builder.Configure <IUnityChannelConfiguration>().fetchReceiptPayloadOnPurchase = m_FetchReceiptPayloadOnPurchase; // Define our products. // Either use the Unity IAP Catalog, or manually use the ConfigurationBuilder.AddProduct API. // Use IDs from both the Unity IAP Catalog and hardcoded IDs via the ConfigurationBuilder.AddProduct API. // Use the products defined in the IAP Catalog GUI. // E.g. Menu: "Window" > "Unity IAP" > "IAP Catalog", then add products, then click "App Store Export". // 定义我们的产品。 //使用统一的IAP目录,或者手动使用配置构建器。AddProduct API。 //通过配置构建器从Unity IAP目录和硬编码的IDs中使用id。AddProduct API。 //使用在IAP目录GUI中定义的产品。 //例如菜单:“窗口”“统一IAP目录”,然后添加产品,然后点击“App Store导出”。 var catalog = ProductCatalog.LoadDefaultCatalog(); foreach (var product in catalog.allProducts) { if (product.allStoreIDs.Count > 0) { var ids = new IDs(); foreach (var storeID in product.allStoreIDs) { ids.Add(storeID.id, storeID.store); } builder.AddProduct(product.id, product.type, ids); } else { builder.AddProduct(product.id, product.type); } } // In this case our products have the same identifier across all the App stores, // except on the Mac App store where product IDs cannot be reused across both Mac and // iOS stores. // So on the Mac App store our products have different identifiers, // and we tell Unity IAP this by using the IDs class. //在这种情况下,我们的产品在所有应用商店中都有相同的标识符, //除了Mac App store,产品id不能在Mac和Mac上重复使用 //iOS商店。在Mac App store中,我们的产品有不同的标识符, //我们通过使用IDs类来告诉Unity IAP。 builder.AddProduct("100.gold.coins", ProductType.Consumable, new IDs { { "100.gold.coins.mac", MacAppStore.Name }, { "000000596586", TizenStore.Name }, { "com.ff", MoolahAppStore.Name }, } #if USE_PAYOUTS , new PayoutDefinition(PayoutType.Currency, "gold", 100) #endif //USE_PAYOUTS ); builder.AddProduct("500.gold.coins", ProductType.Consumable, new IDs { { "500.gold.coins.mac", MacAppStore.Name }, { "000000596581", TizenStore.Name }, { "com.ee", MoolahAppStore.Name }, } #if USE_PAYOUTS , new PayoutDefinition(PayoutType.Currency, "gold", 500) #endif //USE_PAYOUTS ); builder.AddProduct("sword", ProductType.NonConsumable, new IDs { { "sword.mac", MacAppStore.Name }, { "000000596583", TizenStore.Name }, } #if USE_PAYOUTS , new List <PayoutDefinition> { new PayoutDefinition(PayoutType.Item, "", 1, "item_id:76543"), new PayoutDefinition(PayoutType.Currency, "gold", 50) } #endif //USE_PAYOUTS ); builder.AddProduct("subscription", ProductType.Subscription, new IDs { { "subscription.mac", MacAppStore.Name } }); // Write Amazon's JSON description of our products to storage when using Amazon's local sandbox. // This should be removed from a production build. //在使用亚马逊的本地沙盒时,将亚马逊的JSON描述写入到存储中。 //这应该从生产构建中删除。 //builder.Configure<IAmazonConfiguration>().WriteSandboxJSON(builder.products); // This enables simulated purchase success for Samsung IAP. // You would remove this, or set to SamsungAppsMode.Production, before building your release package. //这为三星IAP提供了模拟的购买成功。 //你可以把它移开,或者把它调到三星。在构建您的发布包之前,生产。 // builder.Configure<ISamsungAppsConfiguration>().SetMode(SamsungAppsMode.AlwaysSucceed); // This records whether we are using Samsung IAP. Currently ISamsungAppsExtensions.RestoreTransactions // displays a blocking Android Activity, so: // A) Unity IAP does not automatically restore purchases on Samsung Galaxy Apps // B) IAPDemo (this) displays the "Restore" GUI button for Samsung Galaxy Apps //这记录了我们是否在使用三星IAP。目前ISamsungAppsExtensions.RestoreTransactions //显示一个阻塞的Android活动,所以: //A)统一IAP不会自动恢复三星Galaxy应用程序的购买 //B)IAPDemo(这)显示了三星Galaxy应用的“恢复”GUI按钮 //m_IsSamsungAppsStoreSelected = // Application.platform == RuntimePlatform.Android && module.appStore == AppStore.SamsungApps; // This selects the GroupId that was created in the Tizen Store for this set of products // An empty or non-matching GroupId here will result in no products available for purchase //它选择了在Tizen商店中为这组产品创建的GroupId //一个空的或非匹配的GroupId将导致没有可供购买的产品 //builder.Configure<ITizenStoreConfiguration>().SetGroupId("100000085616"); #if RECEIPT_VALIDATION string appIdentifier; #if UNITY_5_6_OR_NEWER appIdentifier = Application.identifier; #else appIdentifier = Application.bundleIdentifier; #endif validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), UnityChannelTangle.Data(), appIdentifier); #endif Action initializeUnityIap = () => { // Now we're ready to initialize Unity IAP. UnityPurchasing.Initialize(this, builder); }; bool needExternalLogin = m_IsUnityChannelSelected; if (!needExternalLogin) { initializeUnityIap(); } else { // Call UnityChannel initialize and (later) login asynchronously // UnityChannel configuration settings. Required for Xiaomi MiPay. // Collect this app configuration from the Unity Developer website at // [2017-04-17 PENDING - Contact support representative] // https://developer.cloud.unity3d.com/ providing your Xiaomi MiPay App // ID, App Key, and App Secret. This permits Unity to proxy from the // user's device into the MiPay system. // IMPORTANT PRE-BUILD STEP: For mandatory Chinese Government app auditing // and for MiPay testing, enable debug mode (test mode) // using the `AppInfo.debug = true;` when initializing Unity Channel. //调用UnityChannel初始化和(稍后)异步登录 // UnityChannel配置设置。小米所需MiPay。 //从Unity开发者网站收集这个应用程序配置 //2017-04-17等待-联络支持代表 // https://developer.cloud.unity3d.com/提供你小米MiPay应用 //ID、应用程序密钥和应用程序秘密。这使得联合可以从 //用户的设备进入MiPay系统。 //重要的预构建步骤:中国强制性的政府应用审核 //对于MiPay测试,启用调试模式(测试模式) //使用AppInfo.debug=true;初始化统一通道时。 AppInfo unityChannelAppInfo = new AppInfo(); unityChannelAppInfo.appId = "abc123appId"; unityChannelAppInfo.appKey = "efg456appKey"; unityChannelAppInfo.clientId = "hij789clientId"; unityChannelAppInfo.clientKey = "klm012clientKey"; unityChannelAppInfo.debug = false; // Shared handler for Unity Channel initialization, here, and login, later unityChannelLoginHandler = new UnityChannelLoginHandler(); unityChannelLoginHandler.initializeFailedAction = (string message) => { Debug.LogError("Failed to initialize and login to UnityChannel: " + message); }; unityChannelLoginHandler.initializeSucceededAction = () => { initializeUnityIap(); }; StoreService.Initialize(unityChannelAppInfo, unityChannelLoginHandler); } }