public async Task BuyAsync(CommandContext ctx, [Description("Item ID.")] int id) { PurchasableItem item = await this.Database.GetPurchasableItemAsync(ctx.Guild.Id, id); if (item == null) { throw new CommandFailedException("Item with such ID does not exist in this guild's shop!"); } if (await this.Database.UserHasPurchasedItemAsync(ctx.User.Id, item.Id)) { throw new CommandFailedException("You have already purchased this item!"); } if (!await ctx.WaitForBoolReplyAsync($"Are you sure you want to buy a {Formatter.Bold(item.Name)} for {Formatter.Bold(item.Price.ToString())} {this.Shared.GetGuildConfig(ctx.Guild.Id).Currency ?? "credits"}?")) { return; } if (!await this.Database.DecreaseBankAccountBalanceAsync(ctx.User.Id, ctx.Guild.Id, item.Price)) { throw new CommandFailedException("You do not have enough money to purchase that item!"); } await this.Database.AddPurchaseAsync(ctx.User.Id, item.Id); await this.InformAsync(ctx, StaticDiscordEmoji.MoneyBag, $"{ctx.User.Mention} bought a {Formatter.Bold(item.Name)} for {Formatter.Bold(item.Price.ToString())} {this.Shared.GetGuildConfig(ctx.Guild.Id).Currency ?? "credits"}!", important : false); }
public bool processPurchase(PurchasableItem item_purchased, AwardedPurchaseCallback purchase_callback, AwardedPurchaseCallback awarded_callback) { //this handles all backend aspects of the purchase, including the awarding of bonuses, application of global discounts //returns true if purchase is successful, otherwise false if (!canAffordPurchase(item_purchased)) { Debug.LogError("Not enough currency to buy this"); return(false); } //charge the user for the purchase m_currency_owned -= Mathf.RoundToInt(item_purchased.currency_cost * GlobalDiscountManager.GetDiscountFactor()); pushCurrencyToBackend(); //invoke the callback for this purchase, if any if (purchase_callback != null) { purchase_callback(item_purchased); } //call any on_purchase methods specified if (item_purchased.on_purchase_methods != null) { MethodCallUtility.CallOnPurchaseMethods(item_purchased.on_purchase_methods); } return(true); }
public string serialisePurchasable (PurchasableItem item) { XElement element = inventoryDocument.XPathSelectElement(string.Format ("//item[@id='{0}']", item.Id)); XElement screenshotElement = element.XPathSelectElement("platforms/AppleAppStore/screenshotPath"); string screenshotPath = string.Empty; if (screenshotElement == null) { // logger.Log ("Missing screenshot for purchasable:{0}", item.id); } else { string templatePath = "Assets/Plugins/unibill/generated/storekit/MassImportTemplate"; templatePath = new FileInfo (templatePath).FullName; screenshotPath = new FileInfo (util.guidToAssetPath((string)screenshotElement)).FullName; } var records = new string[] { sku, remapper.mapItemIdToPlatformSpecificId(item), remapper.mapItemIdToPlatformSpecificId(item), // This is the 'reference' field that is used to refer to the product within iTunes connect. item.PurchaseType == PurchaseType.Consumable ? "Consumable" : "Non-Consumable", "yes", (string) element.XPathSelectElement("platforms/AppleAppStore/appleAppStorePriceTier"), item.name, item.description, screenshotPath, }; return string.Join("\t", records); }
public string mapItemIdToPlatformSpecificId(PurchasableItem item) { if (!genericToPlatformSpecificIds.ContainsKey (item.Id)) { throw new ArgumentException ("Unknown product id: " + item.Id); } return genericToPlatformSpecificIds[item.Id]; }
public string serialisePurchasable(PurchasableItem item) { string screenshotPath = item.platformBundles[BillingPlatform.AppleAppStore].get <string>("screenshotPath"); string templatePath = "Assets/Plugins/unibill/generated/storekit/MassImportTemplate"; templatePath = new FileInfo(templatePath).FullName; screenshotPath = string.Empty; if (!string.IsNullOrEmpty(screenshotPath)) { screenshotPath = new FileInfo(util.guidToAssetPath((string)screenshotPath)).FullName; } var records = new string[] { this.config.iOSSKU, item.LocalIds[BillingPlatform.AppleAppStore], item.LocalIds[BillingPlatform.AppleAppStore], // This is the 'reference' field that is used to refer to the product within iTunes connect. item.PurchaseType == PurchaseType.Consumable ? "Consumable" : "Non-Consumable", "yes", item.platformBundles[BillingPlatform.AppleAppStore].getString("appleAppStorePriceTier"), item.name, item.description, screenshotPath, }; return(string.Join("\t", records)); }
/// <summary> /// Initiate purchasing of the specified PurchasableItem. /// </summary> public static void initiatePurchase(PurchasableItem purchasable) { if (null != biller) { biller.purchase(purchasable); } }
public void finishTransaction(PurchasableItem item, string transactionId) { if (item.PurchaseType == PurchaseType.Consumable) { this.wp8.FinaliseTransaction(item.LocalId); } }
void purchaseFailed( PurchasableItem item ) { if( item != null ) { FuseLog( "purchase failed for item " + item.Id ); } }
void purchaseCancelled( PurchasableItem item ) { if( item != null ) { FuseLog( "purchase cancelled for item : " + item.Id ); } }
public void downloadContentFor(PurchasableItem item) { if (!item.hasDownloadableContent) { if (null != onDownloadFailedEvent) { onDownloadFailedEvent(item, "The item has no downloadable content"); } return; } if (isDownloaded(item.downloadableContentId)) { onDownloadCompletedEvent(item, getContentPath(item.downloadableContentId)); return; } if (!receiptStore.hasItemReceiptForFilebundle(item.downloadableContentId)) { if (null != onDownloadFailedEvent) { onDownloadFailedEvent(item, "The item is not owned"); } return; } if (!scheduledDownloads.Contains(item.downloadableContentId)) { scheduledDownloads.Add(item.downloadableContentId); serialiseDownloads(); } }
private async Task InternalPurchaseAsync(CommandContext ctx, PurchasableItem item) { if (await this.Service.Purchases.ContainsAsync(ctx.User.Id, item.Id)) { throw new CommandFailedException(ctx, "cmd-err-shop-purchased", item.Name); } string currency = ctx.Services.GetRequiredService <GuildConfigService>().GetCachedConfig(ctx.Guild.Id).Currency; if (!await ctx.WaitForBoolReplyAsync("q-shop-buy", args: new object[] { item.Name, item.Price, currency })) { return; } if (!await ctx.Services.GetRequiredService <BankAccountService>().TryDecreaseBankAccountAsync(ctx.Guild.Id, ctx.User.Id, item.Price)) { throw new CommandFailedException(ctx, "cmd-err-funds-insuf"); } await this.Service.Purchases.AddAsync(new PurchasedItem { ItemId = item.Id, UserId = ctx.User.Id, }); await ctx.ImpInfoAsync(this.ModuleColor, Emojis.MoneyBag, "fmt-shop-buy", ctx.User.Mention, item.Name, item.Price, currency); }
public Slot(string slotNumber, PurchasableItem item) { this.SlotNumber = slotNumber; this.Item = item; this.FillSlot(); }
public void purchase(PurchasableItem item, string developerPayload = "") { if (State == BillerState.INITIALISING) { logError(UnibillError.BILLER_NOT_READY); onPurchaseFailed(item); return; } else if (State == BillerState.INITIALISED_WITH_CRITICAL_ERROR) { logError(UnibillError.UNIBILL_INITIALISE_FAILED_WITH_CRITICAL_ERROR); onPurchaseFailed(item); return; } if (null == item) { logger.LogError("Trying to purchase null PurchasableItem"); return; } if (item.PurchaseType == PurchaseType.NonConsumable && transactionDatabase.getPurchaseHistory(item) > 0) { logError(UnibillError.UNIBILL_ATTEMPTING_TO_PURCHASE_ALREADY_OWNED_NON_CONSUMABLE); onPurchaseFailed(item); return; } billingSubsystem.purchase(remapper.mapItemIdToPlatformSpecificId(item), developerPayload); logger.Log("purchase({0})", item.Id); }
public bool recordPurchase(PurchasableItem item, string transactionId) { int previousCount = getPurchaseHistory(item); if (item.PurchaseType == PurchaseType.NonConsumable && previousCount != 0) { logger.LogWarning("Apparently multi purchased a non consumable:{0}", item.Id); return(false); } // Consumables have additional de duplication logic. if (item.PurchaseType == PurchaseType.Consumable && transactionId != null) { // If we've seen this before, we shouldn't record it again. if (recentTransactionIdentifiers.Contains(transactionId)) { logger.Log("Transaction {0} already recorded.", transactionId); return(false); } if (recentTransactionIdentifiers.Count > 20) { recentTransactionIdentifiers.RemoveAt(0); } recentTransactionIdentifiers.Add(transactionId); storage.SetString(TRANSACTION_SET_KEY, Unibill.Impl.MiniJSON.jsonEncode(recentTransactionIdentifiers)); } storage.SetInt(getKey(item.Id), previousCount + 1); return(true); }
/// <summary> /// Initiate purchasing of the specified PurchasableItem. /// </summary> /// <param name="developerPayload"> /// Optional and relevant only to Google Play. /// </param> public static void initiatePurchase(PurchasableItem purchasable, string developerPayload = "") { if (null != biller) { biller.purchase(purchasable, developerPayload); } }
private static void _onPurchaseCancelled(PurchasableItem item) { if (null != onPurchaseCancelled) { onPurchaseCancelled(item); } }
void purchaseCancelled(PurchasableItem item) { if (item != null) { FuseLog("purchase cancelled for item : " + item.Id); } }
public DefaultPlatformEditor(PurchasableItem item, BillingPlatform platform) { this.platform = platform; this.item = item; this.localId = item.LocalIds[platform]; overridden = localId != item.Id; }
private void extractReceiptAndSignature(PurchasableItem item, out string receipt, out string signature) { receipt = null; signature = null; switch (platform) { case BillingPlatform.AppleAppStore: receipt = item.receipt; signature = null; break; case BillingPlatform.GooglePlay: var dic = item.receipt.hashtableFromJson(); if (null != dic) { if (dic.ContainsKey("json")) { receipt = (string)dic ["json"]; } if (dic.ContainsKey("signature")) { signature = (string)dic ["signature"]; } } break; } }
public static async Task <PurchasableItem> GetPurchasableItemAsync(this DBService db, ulong gid, int id) { PurchasableItem item = null; await db.ExecuteCommandAsync(async (cmd) => { cmd.CommandText = "SELECT id, gid, name, price FROM gf.items WHERE id = @id AND gid = @gid LIMIT 1;"; cmd.Parameters.Add(new NpgsqlParameter <long>("gid", (long)gid)); cmd.Parameters.Add(new NpgsqlParameter <int>("id", id)); using (var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false)) { if (await reader.ReadAsync().ConfigureAwait(false)) { item = new PurchasableItem() { GuildId = (ulong)(long)reader["gid"], Id = (int)reader["id"], Name = (string)reader["name"], Price = (long)reader["price"] }; } } }); return(item); }
public void onPurchaseSucceeded(string id, string receipt) { if (!verifyPlatformId(id)) { return; } if (null != receipt) { this.onPurchaseReceiptRetrieved(id, receipt); } PurchasableItem item = remapper.getPurchasableItemFromPlatformSpecificId(id); if (item.PurchaseType == PurchaseType.NonConsumable) { if (transactionDatabase.getPurchaseHistory(item) > 0) { logger.Log("Ignoring multi purchase of non consumable"); return; } } logger.Log("onPurchaseSucceeded({0})", item.Id); transactionDatabase.onPurchase(item); currencyManager.OnPurchased(item.Id); if (null != onPurchaseComplete) { onPurchaseComplete(new PurchaseEvent(item, receipt)); } }
internal PurchaseEvent(PurchasableItem purchasedItem, bool isNewPurchase, string receipt, string transactionId) { this.PurchasedItem = purchasedItem; this.IsNewPurchase = isNewPurchase; this.Receipt = receipt; this.TransactionId = transactionId; }
public async Task SellAsync(CommandContext ctx, [Description("Item ID.")] int id) { PurchasableItem item = await this.Database.GetPurchasableItemAsync(ctx.Guild.Id, id); if (item == null) { throw new CommandFailedException("Item with such ID does not exist in this guild's shop!"); } if (!await this.Database.UserHasPurchasedItemAsync(ctx.User.Id, item.Id)) { throw new CommandFailedException("You did not purchase this item!"); } long retval = item.Price / 2; if (!await ctx.WaitForBoolReplyAsync($"Are you sure you want to sell a {Formatter.Bold(item.Name)} for {Formatter.Bold(retval.ToString())} {this.Shared.GetGuildConfig(ctx.Guild.Id).Currency ?? "credits"}?")) { return; } await this.Database.IncreaseBankAccountBalanceAsync(ctx.User.Id, ctx.Guild.Id, retval); await this.Database.RemovePurchaseAsync(ctx.User.Id, item.Id); await this.InformAsync(ctx, StaticDiscordEmoji.MoneyBag, $"{ctx.User.Mention} sold a {Formatter.Bold(item.Name)} for {Formatter.Bold(retval.ToString())} {this.Shared.GetGuildConfig(ctx.Guild.Id).Currency ?? "credits"}!", important : false); }
public PurchasableItem AddItem() { var item = new PurchasableItem(); inventory.Add(item); return(item); }
public string serialisePurchasable(PurchasableItem item, BillingPlatform platform) { string screenshotPath = item.platformBundles[BillingPlatform.AppleAppStore].get <string>("screenshotPath"); if (!string.IsNullOrEmpty(screenshotPath)) { string assetPath = util.guidToAssetPath((string)screenshotPath); if (!string.IsNullOrEmpty(assetPath)) { screenshotPath = new FileInfo(assetPath).FullName; } } var records = new string[] { platform == BillingPlatform.AppleAppStore ? config.iOSSKU : config.macAppStoreSKU, item.LocalIds[platform], item.name, // This is the 'reference' field that is used to refer to the product within iTunes connect. item.PurchaseType == PurchaseType.Consumable ? "Consumable" : "Non-Consumable", "yes", item.platformBundles[BillingPlatform.AppleAppStore].getString("appleAppStorePriceTier"), item.name, item.description, screenshotPath, }; return(string.Join("\t", records)); }
public string[] getReceiptsForPurchasable (PurchasableItem item) { if (receiptMap.ContainsKey (item)) { return receiptMap[item].ToArray(); } return new string[0]; }
public void onRefunded(PurchasableItem item) { int previousCount = getPurchaseHistory(item); previousCount = Math.Max(0, previousCount - 1); storage.SetInt(getKey(item.Id), previousCount); }
void purchaseFailed(PurchasableItem item) { if (item != null) { FuseLog("purchase failed for item " + item.Id); } }
private static void _onPurchaseRefunded(PurchasableItem item) { if (null != onPurchaseRefunded) { onPurchaseRefunded(item); } }
private static void _onPurchaseDeferred(PurchasableItem item) { if (null != onPurchaseDeferred) { onPurchaseDeferred(item); } }
void purchaseCancelled(PurchasableItem item) { if (item != null) { byte[] receipt = { 0 }; FuseSDK.RegisterIOSInAppPurchase(item.Id, "", receipt, FuseMisc.IAPState.FAILED); } }
public string mapItemIdToPlatformSpecificId(PurchasableItem item) { if (!genericToPlatformSpecificIds.ContainsKey(item.Id)) { throw new ArgumentException("Unknown product id: " + item.Id); } return(genericToPlatformSpecificIds[item.Id]); }
public void showFreeItemRewardedResults(PurchasableItem awarded_item) { //called when an item is awarded for free, as a result of a random reward from another purchase string concatenated_purchase_confirmation = string.Format(m_free_item_confirmation_text, awarded_item.visible_name); showInformativeModal(concatenated_purchase_confirmation); //trigger any animations the purchase specifies }
/// <summary> /// Get the number of times this PurchasableItem has been purchased. /// Returns 0 for unpurchased items, a maximum of 1 for Non-Consumable items. /// </summary> public static int GetPurchaseCount(PurchasableItem item) { if (null != biller) { return(biller.getPurchaseHistory(item)); } return(0); }
void Start() { foreach (TextAsset t in client_defined_purchases) { PurchasableItem deserialized_purchase = JsonUtility.FromJson <PurchasableItem>(t.text); m_purchase_manager.addOrModifyPurchase(deserialized_purchase); } }
void purchaseFailed( PurchasableItem item ) { if( item != null ) { byte[] receipt = { 0 }; FuseSDK.RegisterIOSInAppPurchase(item.Id, "", receipt, FuseMisc.IAPState.FAILED); } }
public void onPurchase (PurchasableItem item) { int previousCount = getPurchaseHistory (item); if (item.PurchaseType != PurchaseType.Consumable && previousCount != 0) { logger.LogWarning("Apparently multi purchased a non consumable:{0}", item.Id); return; } storage.SetInt(getKey(item.Id), previousCount + 1); }
public Hashtable purchasableDetailsToHashtable (PurchasableItem item) { var dic = new Hashtable(); dic ["itemType"] = item.PurchaseType == PurchaseType.Consumable ? "CONSUMABLE" : item.PurchaseType == PurchaseType.NonConsumable ? "ENTITLED" : "SUBSCRIPTION"; dic ["title"] = item.name == null ? string.Empty : item.name; dic ["description"] = item.description == null ? string.Empty : item.description; dic["price"] = 0.99; dic ["smallIconUrl"] = "http://example.com"; if (PurchaseType.Subscription == item.PurchaseType) { dic["subscriptionParent"] = "does.not.exist"; } return dic; }
public string[] serialiseItem(PurchasableItem item) { decimal priceInLocalCurrency; decimal.TryParse(item.platformBundles[BillingPlatform.GooglePlay].getString("priceInLocalCurrency"), out priceInLocalCurrency); string defaultLocale = item.platformBundles[BillingPlatform.GooglePlay].get<string>("defaultLocale"); HashSet<string> otherLocales = new HashSet<string>(Enum.GetNames(typeof(GooglePlayLocale))); otherLocales.Remove(defaultLocale); return new string[] { item.LocalIds[BillingPlatform.GooglePlay], "published", "managed_by_android", "false", // Auto translate no longer supported. string.Format ("\"{0};{1};{2}{3}\"", defaultLocale, escape(item.name), escape(item.description), string.Empty), "true", // Auto fill prices. string.Format("{0}", (long) (1000000 * priceInLocalCurrency)), }; }
//Handles all armoury purchases public void _OverworldUI_ArmouryUI_OnPurchasedItem(PurchasableItem purchasedItem) { //We don't know item purchased at compile time, so use as keyword instead of casting PurchasableUnit purchasedUnit = purchasedItem as PurchasableUnit; PurchasableCard purchasedCard = purchasedItem as PurchasableCard; PurchasableCastlePiece purchasedCastlePiece = purchasedItem as PurchasableCastlePiece; //Give player the item and take money away if(purchasedUnit != null) { _GameStateHolder._ActivePlayer.PlayerArmy.AddUnit(purchasedUnit.UNITTYPE); _GameStateHolder._ActivePlayer.Currency.addPoints(-purchasedUnit.cost); } else if(purchasedCard != null) { _GameStateHolder._ActivePlayer.AddCard(purchasedCard.Card); _GameStateHolder._ActivePlayer.Currency.addPoints(-purchasedCard.cost); } else if(purchasedCastlePiece != null) { _GameStateHolder._ActivePlayer.CastleProgress++; _GameStateHolder._ActivePlayer.Currency.addPoints(-purchasedCastlePiece.cost); } }
public string[] serialiseItem(PurchasableItem item) { XElement rawElement = inventory.XPathSelectElement(string.Format ("//item[@id='{0}']", item.Id)); decimal priceInLocalCurrency = (decimal) rawElement.XPathSelectElement("platforms/GooglePlay/priceInLocalCurrency"); string defaultLocale = (string) rawElement.XPathSelectElement("platforms/GooglePlay/defaultLocale"); HashSet<string> otherLocales = new HashSet<string>(Enum.GetNames(typeof(GooglePlayLocale))); otherLocales.Remove(defaultLocale); // If we auto translate we must specify every other locale to translate to. string localesToTranslateTo = ""; return new string[] { remapper.mapItemIdToPlatformSpecificId(item), "published", "managed_by_android", "false", // Auto translate no longer supported. string.Format ("\"{0};{1};{2}{3}\"", defaultLocale, escape(item.name), escape(item.description), localesToTranslateTo), "true", // Auto fill prices. string.Format("{0}", (int) (1000000 * priceInLocalCurrency)), }; }
public string serialisePurchasable(PurchasableItem item, BillingPlatform platform) { string screenshotPath = item.platformBundles[BillingPlatform.AppleAppStore].get<string>("screenshotPath"); if (!string.IsNullOrEmpty (screenshotPath)) { string assetPath = util.guidToAssetPath((string)screenshotPath); if (!string.IsNullOrEmpty(assetPath)) { screenshotPath = new FileInfo(assetPath).FullName; } } var records = new string[] { platform == BillingPlatform.AppleAppStore ? config.iOSSKU : config.macAppStoreSKU, item.LocalIds[platform], item.LocalIds[platform], // This is the 'reference' field that is used to refer to the product within iTunes connect. item.PurchaseType == PurchaseType.Consumable ? "Consumable" : "Non-Consumable", "yes", item.platformBundles[BillingPlatform.AppleAppStore].getString("appleAppStorePriceTier"), item.name, item.description, screenshotPath, }; return string.Join("\t", records); }
public string serialisePurchasable (PurchasableItem item) { string screenshotPath = item.platformBundles[BillingPlatform.AppleAppStore].get<string>("screenshotPath"); string templatePath = "Assets/Plugins/unibill/generated/storekit/MassImportTemplate"; templatePath = new FileInfo (templatePath).FullName; screenshotPath = string.Empty; if (!string.IsNullOrEmpty(screenshotPath)) { screenshotPath = new FileInfo(util.guidToAssetPath((string)screenshotPath)).FullName; } var records = new string[] { this.config.iOSSKU, item.LocalIds[BillingPlatform.AppleAppStore], item.LocalIds[BillingPlatform.AppleAppStore], // This is the 'reference' field that is used to refer to the product within iTunes connect. item.PurchaseType == PurchaseType.Consumable ? "Consumable" : "Non-Consumable", "yes", item.platformBundles[BillingPlatform.AppleAppStore].getString("appleAppStorePriceTier"), item.name, item.description, screenshotPath, }; return string.Join("\t", records); }
public static void setLocalizedPrice (PurchasableItem item, string price) { item.localizedPriceString = price; }
public static void setLocalizedPrice (PurchasableItem item, decimal price) { item.localizedPrice = price; item.localizedPriceString = price.ToString (); }
public UnibillConfiguration(string json, RuntimePlatform runtimePlatform, ILogger logger) { this.logger = logger; var root = (Dictionary<string, object>)Unibill.Impl.MiniJSON.jsonDecode(json); this.iOSSKU = root.getString("iOSSKU"); this.macAppStoreSKU = root.getString ("macAppStoreSKU"); this.AndroidBillingPlatform = root.getEnum<BillingPlatform>("androidBillingPlatform"); this.GooglePlayPublicKey = root.get<string>("GooglePlayPublicKey"); this.AmazonSandboxEnabled = root.getBool("useAmazonSandbox"); this.WP8SandboxEnabled = root.getBool("UseWP8MockingFramework"); this.UseHostedConfig = root.getBool("useHostedConfig"); this.HostedConfigUrl = root.get<string>("hostedConfigUrl"); this.UseWin8_1Sandbox = root.getBool("UseWin8_1Sandbox"); this.SamsungAppsMode = root.getEnum<SamsungAppsMode> ("samsungAppsMode"); this.SamsungItemGroupId = root.getString ("samsungAppsItemGroupId"); this.UnibillAnalyticsAppId = root.getString ("unibillAnalyticsAppId"); this.UnibillAnalyticsAppSecret = root.getString ("unibillAnalyticsAppSecret"); switch (runtimePlatform) { case RuntimePlatform.Android: CurrentPlatform = AndroidBillingPlatform; break; case RuntimePlatform.IPhonePlayer: CurrentPlatform = BillingPlatform.AppleAppStore; break; case RuntimePlatform.OSXPlayer: CurrentPlatform = BillingPlatform.MacAppStore; break; #if UNITY_3_5_0 #else case RuntimePlatform.WP8Player: CurrentPlatform = BillingPlatform.WindowsPhone8; break; case RuntimePlatform.MetroPlayerARM: case RuntimePlatform.MetroPlayerX64: case RuntimePlatform.MetroPlayerX86: CurrentPlatform = BillingPlatform.Windows8_1; break; #endif case RuntimePlatform.OSXEditor: case RuntimePlatform.WindowsEditor: CurrentPlatform = BillingPlatform.UnityEditor; break; default: CurrentPlatform = BillingPlatform.UnityEditor; break; } var items = (Dictionary<string, object>)root["purchasableItems"]; foreach (var kvp in items) { var item = new PurchasableItem(kvp.Key, (Dictionary<string, object>)kvp.Value, CurrentPlatform); inventory.Add(item); } loadCurrencies(root); }
void OnPurchaseFailed(PurchasableItem item) //购买失败 { GlobalVars.PurchaseFailed = true; }
void OnPurchaseCancelled(PurchasableItem item) //主动取消购买 { GlobalVars.PurchaseCancel = true; }
/// <summary> /// This will be called if a user opts to cancel a purchase /// after going to the billing system's purchase menu. /// </summary> private void onCancelled(PurchasableItem item) { Debug.Log("Purchase cancelled: " + item.Id); }
public int getPurchaseHistory (PurchasableItem item) { return transactionDatabase.getPurchaseHistory(item); }
public void purchase (PurchasableItem item) { if (State == BillerState.INITIALISING) { logError (UnibillError.BILLER_NOT_READY); return; } else if (State == BillerState.INITIALISED_WITH_CRITICAL_ERROR) { logError (UnibillError.UNIBILL_INITIALISE_FAILED_WITH_CRITICAL_ERROR); return; } if (null == item) { logger.LogError ("Trying to purchase null PurchasableItem"); return; } if (item.PurchaseType == PurchaseType.NonConsumable && transactionDatabase.getPurchaseHistory (item) > 0) { logError(UnibillError.UNIBILL_ATTEMPTING_TO_PURCHASE_ALREADY_OWNED_NON_CONSUMABLE); return; } billingSubsystem.purchase(remapper.mapItemIdToPlatformSpecificId(item)); logger.Log("purchase({0})", item.Id); }
public int getPurchaseHistory (PurchasableItem item) { return storage.GetInt(getKey(item.Id), 0); }
public void clearPurchases(PurchasableItem item) { storage.SetInt (getKey (item.Id), 0); }
/// <summary> /// This will be called is an attempted purchase fails. /// </summary> private void onFailed(PurchasableItem item) { Debug.Log("Purchase failed: " + item.Id); }
public static void setLocalizedTitle (PurchasableItem item, string title) { item.localizedTitle = title; }
public static void setISOCurrencySymbol(PurchasableItem item, string code) { item.isoCurrencySymbol = code; }
public static void setLocalizedDescription (PurchasableItem item, string description) { item.localizedDescription = description; }
public static void setPriceInLocalCurrency(PurchasableItem item, decimal amount) { item.priceInLocalCurrency = amount; }
public void downloadContentFor(PurchasableItem item) { if (!item.hasDownloadableContent) { if (null != onDownloadFailedEvent) { onDownloadFailedEvent (item, "The item has no downloadable content"); } return; } if (isDownloaded (item.downloadableContentId)) { onDownloadCompletedEvent (item, new DirectoryInfo (getContentPath (item.downloadableContentId))); return; } if (!receiptStore.hasItemReceiptForFilebundle (item.downloadableContentId)) { if (null != onDownloadFailedEvent) { onDownloadFailedEvent (item, "The item is not owned"); } return; } if (!scheduledDownloads.Contains (item.downloadableContentId)) { scheduledDownloads.Add (item.downloadableContentId); workQueue.Add (item.downloadableContentId); serialiseDownloads (); } }