/// <summary> /// Creates a new IAP product definition. /// </summary> /// <param name="id"></param> /// <param name="name"></param> /// <param name="type"></param> /// <param name="price"></param> /// <param name="description"></param> public IAPProduct(string id, string name, IAPProductType type, string price, string description = null) { _id = id; _name = name; _type = type; _price = price; _description = description; }
private static ProductType ConvertFromIAPProductType(IAPProductType productType) { switch (productType) { case IAPProductType.Consumable: return(ProductType.Consumable); case IAPProductType.NonConsumable: return(ProductType.NonConsumable); case IAPProductType.Subscription: return(ProductType.Subscription); } return(ProductType.Consumable); }
public static ProductType GetProductType(IAPProductType pType) { switch (pType) { case IAPProductType.Consumable: return(ProductType.Consumable); case IAPProductType.NonConsumable: return(ProductType.NonConsumable); case IAPProductType.Subscription: return(ProductType.Subscription); default: return(ProductType.Consumable); } }
public IAPPackage(string uid, IAPPackageSetting s, IAPObjectData d, Action <IAPObject> callback = null) : base(uid, d, callback) { // uid=s.productId; fetchFromStore = s.fetchFromStore; currency = s.currency; price = s.price; content = new List <IAPPackageContent>(); icon = s.icon; title = s.title; description = s.description; tags = s.tags; productType = s.productType; // Create the dictionary for finding IAPPackageContent _contentDictionary = new Dictionary <string, IAPPackageContent>(); // Loop and create IAPPackageContent for each setting foreach (IAPContentSetting c in s.content) { IAPPackageContent item = new IAPPackageContent(); item.amount = c.amount; if (c.type == IAPType.Currency) { item.obj = IAPInventoryManager.GetCurrency(c.uid); } else if (c.type == IAPType.Inventory) { item.obj = IAPInventoryManager.GetInventory(c.uid); } else if (c.type == IAPType.GameLevel) { item.obj = IAPInventoryManager.GetGameLevel(c.uid); } content.Add(item); _contentDictionary.Add(c.uid, item); } // Add event for real money purchase if (fetchFromStore) { // Debug.Log("fetchFromStore"); IAPManager.OnIAPProcessPurchase += handleOnIAPProcessPurchase; } }
public IAPPackageSetting(string id, IAPProductType type = IAPProductType.Consumable) : base(id, type) { }
public IAPProductSetting(string id, IAPProductType type) { productId = id; productType = type; }
// Testing value public IAPProduct(string id, IAPProductType type) { this.id = id; this.productType = type; }
/// <summary> /// Creates a new IAP product definition. /// </summary> /// <param name="id"></param> /// <param name="storeSpecificIds"></param> /// <param name="name"></param> /// <param name="type"></param> /// <param name="price"></param> /// <param name="description"></param> public IAPProduct(string id, StoreSpecificId[] storeSpecificIds, string name, IAPProductType type, string price, string description = null) : this(id, name, type, price, description) { _storeSpecificIds = storeSpecificIds; }
// Private Methods private static void _init(List <IAPProductSetting> productSettings) { // build the product list products = new Dictionary <string, IAPProduct>(); foreach (IAPProductSetting setting in productSettings) { string id = setting.productId; IAPProductType type = setting.productType; IAPProduct p = new IAPProduct(id, type); p.amazonProductId = (setting.amazonProductId != null && setting.amazonProductId != "") ? setting.amazonProductId : setting.productId; p.googleProductId = (setting.googleProductId != null && setting.googleProductId != "") ? setting.googleProductId : setting.productId; p.appleProductId = (setting.appleProductId != null && setting.appleProductId != "") ? setting.appleProductId : setting.productId; p.samsungProductId = (setting.samsungProductId != null && setting.samsungProductId != "") ? setting.samsungProductId : setting.productId; p.macProductId = (setting.macProductId != null && setting.macProductId != "") ? setting.macProductId : setting.productId; p.tizenProductId = (setting.tizenProductId != null && setting.tizenProductId != "") ? setting.tizenProductId : setting.productId; p.moolahProductId = (setting.moolahProductId != null && setting.moolahProductId != "") ? setting.moolahProductId : setting.productId; p.buyButtonText = setting.buyButtonText; p.disabledButtonText = setting.disabledButtonText; if (products.ContainsKey(id)) { Debug.Log("[IAPManager] Product id \"" + id + "\" already exist."); } else { Debug.Log("[IAPManager] Add product with id \"" + id + "\""); products.Add(id, p); } // Debug.Log("product id: " + p.id); } var module = StandardPurchasingModule.Instance(); // Create a builder, first passing in a suite of Unity provided stores. var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance()); // CloudMoolah Configuration setings // All games must set the configuration. the configuration need to apply on the CloudMoolah Portal. // CloudMoolah APP Key if (_setting.MoolahAppKey != null && _setting.MoolahAppKey != "") { builder.Configure <IMoolahConfiguration>().appKey = _setting.MoolahAppKey; } // CloudMoolah Hash Key if (_setting.MoolahHashKey != null && _setting.MoolahHashKey != "") { builder.Configure <IMoolahConfiguration>().hashKey = _setting.MoolahHashKey; } // Test Mode Enbled if (_setting.testMode) { // This enables the Microsoft IAP simulator for local testing. builder.Configure <IMicrosoftConfiguration>().useMockBillingSystem = true; if (_setting.GooglePublicKey != null && _setting.GooglePublicKey != "") { builder.Configure <IGooglePlayConfiguration>().SetPublicKey(_setting.GooglePublicKey); } 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 } // Add Product to builder foreach (KeyValuePair <string, IAPProduct> item in products) { IAPProduct p = item.Value; IDs ids = new IDs(); if (p.appleProductId != null) { ids.Add(p.appleProductId, AppleAppStore.Name); } if (p.googleProductId != null) { ids.Add(p.googleProductId, GooglePlay.Name); } if (p.amazonProductId != null) { ids.Add(p.amazonProductId, AmazonApps.Name); } if (p.macProductId != null) { ids.Add(p.macProductId, MacAppStore.Name); } if (p.samsungProductId != null) { ids.Add(p.samsungProductId, SamsungApps.Name); } if (p.tizenProductId != null) { ids.Add(p.tizenProductId, TizenStore.Name); } if (p.moolahProductId != null) { ids.Add(p.moolahProductId, MoolahAppStore.Name); } // Debug.Log("builder id: " + p.id); builder.AddProduct(p.id, ConvertFromIAPProductType(p.productType), ids); } // Test Mode Enabled if (_setting.testMode) { // 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 } // 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(_setting.TizenGroupId); // Check Platform _isGooglePlayStore = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.GooglePlay; _isCloudMoolahStore = Application.platform == RuntimePlatform.Android && module.appStore == AppStore.CloudMoolah; _isSamsungAppsStore = module.appStore == AppStore.SamsungApps; // build validator #if RECEIPT_VALIDATION string appIdentifier; #if UNITY_5_6_OR_NEWER appIdentifier = Application.identifier; #else appIdentifier = Application.bundleIdentifier; #endif _ReceiptValidator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), UnityChannelTangle.Data(), appIdentifier); #endif UnityPurchasing.Initialize(_instance, builder); }