private void OnItemPurchased(PurchasableVirtualItem pvi, string paylod) { Debug.Log(string.Format("GNOME: ItemPurchased - ItemId: {0}", pvi.ItemId)); // Set the item information ItemHitBuilder itemHitBuilder = new ItemHitBuilder().SetTransactionID(pvi.ID).SetName(pvi.Name).SetSKU(pvi.ItemId); // Then set the price PurchaseWithMarket marketItem = pvi.PurchaseType as PurchaseWithMarket; PurchaseWithVirtualItem virtualItem = pvi.PurchaseType as PurchaseWithVirtualItem; if (marketItem != null) { itemHitBuilder.SetPrice(marketItem.MarketItem.Price).SetCurrencyCode(marketItem.MarketItem.MarketCurrencyCode); } if (virtualItem != null) { itemHitBuilder.SetPrice(virtualItem.Amount).SetCurrencyCode("Tokens"); } // Now log it GoogleAnalyticsV3.instance.LogItem(itemHitBuilder); Debug.Log(string.Format("GNOME: Analytics: {0}, {1}, {2}", "Purchase", this.PurchaseButtonLocation, pvi.ItemId)); }
/// <summary> /// Initializes a new instance of the <see cref="PurchasableVirtualItem"/> class. /// </summary> /// <param name="jsonObject">The json object.</param> public PurchasableVirtualItem(JObject jsonObject) : base(jsonObject) { JObject purchasableObj = jsonObject.Value <JObject>(StoreJSONConsts.PURCHASABLE_ITEM); String purchaseType = purchasableObj.Value <String>(StoreJSONConsts.PURCHASE_TYPE); if (purchaseType == StoreJSONConsts.PURCHASE_TYPE_MARKET) { JObject marketItemObj = purchasableObj.Value <JObject>(StoreJSONConsts.PURCHASE_MARKET_ITEM); mPurchaseType = new PurchaseWithMarket(new MarketItem(marketItemObj)); } else if (purchaseType == StoreJSONConsts.PURCHASE_TYPE_VI) { String itemId = purchasableObj.Value <String>(StoreJSONConsts.PURCHASE_VI_ITEMID); int amount = purchasableObj.Value <int>(StoreJSONConsts.PURCHASE_VI_AMOUNT); mPurchaseType = new PurchaseWithVirtualItem(itemId, amount); } else { SoomlaUtils.LogError(TAG, "IabPurchase type not recognized !"); } if (mPurchaseType != null) { mPurchaseType.setAssociatedItem(this); } }
public VirtualGood Complete() { PurchaseType purchase; if (currency == StoreItem.Currency.Dollars) { purchase = new PurchaseWithMarket(sku, price); } else { purchase = new PurchaseWithVirtualItem("seed", Mathf.CeilToInt(price)); } return(new SingleUsePackVG(itemId, itemCount, name, description, id, purchase)); }
private static void OnMarketPurchase(PurchasableVirtualItem pvi, string payload, Dictionary <string, string> extra) { PurchaseWithMarket purchaseWithMarket = pvi.PurchaseType as PurchaseWithMarket; if (purchaseWithMarket != null) { MarketItem marketItem = purchaseWithMarket.MarketItem; if (Application.platform == RuntimePlatform.Android) { EventTracker tracker = AdBoostUnity.getEventTracker(); tracker.sendRevenueEvent( marketItem.MarketCurrencyCode, marketItem.Price, pvi.ItemId ); } } }
// Get the virtual and real money cost of the item public string[] getPrices(string item_id) { string[] price_list = new string[2]; PurchasableVirtualItem virtual_item = (PurchasableVirtualItem)StoreInfo.GetItemByItemId(item_id); PurchasableVirtualItem market_item = (PurchasableVirtualItem)StoreInfo.GetItemByItemId("soap_" + item_id); // Get cost in coins PurchaseWithVirtualItem virtual_purchase = (PurchaseWithVirtualItem)virtual_item.PurchaseType; price_list[0] = virtual_purchase.Amount.ToString(); // Get cost in real money PurchaseWithMarket market_purchase = (PurchaseWithMarket)market_item.PurchaseType; price_list[1] = market_purchase.MarketItem.Price.ToString(); return(price_list); }
public VirtualGood Complete() { VirtualGood good; PurchaseType purchase = null; if (currency == Currency.Dollars) { purchase = new PurchaseWithMarket(sku, price); } if (currency == Currency.Seeds) { purchase = new PurchaseWithVirtualItem("seed", Mathf.CeilToInt(price)); } if (consumable) { good = new SingleUseVG(name, description, id, purchase); } else { good = new LifetimeVG(name, description, id, purchase); } return(good); }
private void buildShopLine(VirtualItem item) { StackPanel stackP = new StackPanel(); stackP.Orientation = System.Windows.Controls.Orientation.Horizontal; stackP.Margin = new Thickness(0, 15, 0, 0); StackPanel buttonStack = new StackPanel(); buttonStack.Orientation = System.Windows.Controls.Orientation.Vertical; StackPanel textStack = new StackPanel(); textStack.Orientation = System.Windows.Controls.Orientation.Vertical; stackP.Children.Add(buttonStack); stackP.Children.Add(textStack); Button buy = new Button(); buy.Margin = new Thickness(0, 0, 10, 0); buy.Click += buyItem; buy.Content = "buy"; buy.CommandParameter = item.getItemId(); buy.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; buy.VerticalAlignment = System.Windows.VerticalAlignment.Center; buttonStack.Children.Add(buy); if (item is EquippableVG) { Button equip = new Button(); equip.Name = item.getItemId() + "equip"; equip.Margin = new Thickness(0, 0, 10, 0); equip.CommandParameter = item.getItemId(); equip.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; equip.VerticalAlignment = System.Windows.VerticalAlignment.Center; EquippableVG evg = (EquippableVG)item; if (StoreInventory.isVirtualGoodEquipped(item.getItemId())) { equip.Content = "unequip"; equip.Click += unequipItem; } else { equip.Content = "equip"; equip.Click += equipItem; } buttonStack.Children.Add(equip); } TextBlock balance = new TextBlock(); balance.VerticalAlignment = System.Windows.VerticalAlignment.Center; balance.Margin = new Thickness(0, 0, 10, 0); if (!(item is VirtualCurrencyPack) && !(item is NonConsumableItem)) { balance.Text = "balance: " + StoreInventory.getVirtualItemBalance(item.getItemId()).ToString(); } balance.Name = item.getItemId() + "balance"; textStack.Children.Add(balance); TextBlock name = new TextBlock(); name.Margin = new Thickness(0, 0, 10, 0); name.VerticalAlignment = System.Windows.VerticalAlignment.Center; name.Text = "id: " + item.getItemId(); textStack.Children.Add(name); TextBlock price = new TextBlock(); price.Margin = new Thickness(0, 0, 10, 0); price.VerticalAlignment = System.Windows.VerticalAlignment.Center; TextBlock currency = new TextBlock(); currency.Margin = new Thickness(0, 0, 10, 0); currency.VerticalAlignment = System.Windows.VerticalAlignment.Center; if (item is PurchasableVirtualItem) { PurchasableVirtualItem pvi = (PurchasableVirtualItem)item; if (pvi.GetPurchaseType() is PurchaseWithVirtualItem) { PurchaseWithVirtualItem purchaseType = (PurchaseWithVirtualItem)pvi.GetPurchaseType(); price.Text = "price: " + purchaseType.getAmount().ToString(); currency.Text = "currency: " + purchaseType.getTargetItemId(); } if (pvi.GetPurchaseType() is PurchaseWithMarket) { PurchaseWithMarket purchaseType = (PurchaseWithMarket)pvi.GetPurchaseType(); price.Text = "price: " + purchaseType.getMarketItem().getMarketPrice(); } textStack.Children.Add(price); textStack.Children.Add(currency); } if (item is VirtualCurrencyPack) { VirtualCurrencyPack vcp = (VirtualCurrencyPack)item; TextBlock currencyId = new TextBlock(); currencyId.Text = "give currency: " + vcp.getCurrencyItemId().ToString(); TextBlock currencyAmount = new TextBlock(); currencyAmount.Text = "give amount: " + vcp.getCurrencyAmount().ToString(); textStack.Children.Add(currencyId); textStack.Children.Add(currencyAmount); } MainStackPanel.Children.Add(stackP); }
/// <summary> /// Initializes this instance. /// </summary> public void Initialize(CharacterResource charResource, Action <string> charPurchaseSucceededDelegate, Action <string> charPurchaseCancelledDelegate, Action restoreTransactionsCompletedDelegate, Action restoreTransactionsFailedDelegate, Action <int> coinBalanceChangedDelegate, Action <int> gachaBalanceChangedDelegate) { // Initialize only once if (m_isInitialized) { return; } // Set up character data in Soomla's StoreAssets CRCAssets.CharactersLTVGArray = new EquippableVG[charResource.CharacterCount]; m_charItemIDDictionary.Clear(); // For testing: Index used for assigning test product IDs //int testIDIndex = 0; for (int index = 0; index < charResource.CharacterCount; ++index) { CharacterType character = (CharacterType)index; CharacterResource.CharacterStruct charData = charResource.GetCharacterStruct(character); // Check if character is buyable PurchaseType purchaseType = new PurchaseWithMarket(charData.ItemID, charData.Price); /* * // For testing: Use test product IDs for the first four purchasable characters * PurchaseType purchaseType = null; * string productID = charData.ItemID; * if (charData.IsBuyable) * { * if (testIDIndex == 0) productID = CRCAssets.PURCHASED_TEST_ID; * else if (testIDIndex == 1) productID = CRCAssets.CANCELED_TEST_ID; * else if (testIDIndex == 2) productID = CRCAssets.REFUNDED_TEST_ID; * else if (testIDIndex == 3) productID = CRCAssets.UNAVAILABLE_TEST_ID; * testIDIndex++; * } * purchaseType = new PurchaseWithMarket(productID, charData.Price); * //purchaseType = new PurchaseWithMarket(CRCAssets.PURCHASED_TEST_ID, charData.Price); */ // Create equippable virtual good instance for each character CRCAssets.CharactersLTVGArray[index] = new EquippableVG( EquippableVG.EquippingModel.CATEGORY, charData.Name, "", charData.ItemID, purchaseType); // Add the item ID and character type to a dictionary if (!m_charItemIDDictionary.ContainsKey(charData.ItemID)) { m_charItemIDDictionary.Add(charData.ItemID, character); } } // Create an instance of the in-game implementation of IStoreAssets CRCAssets crcAssets = new CRCAssets(); // Update the list of character goods for (int index = 0; index < charResource.CharacterCount; ++index) { crcAssets.AddToCharacterGoodsList(CRCAssets.CharactersLTVGArray[index]); } // Finalize character goods collections before initializing Soomla Store crcAssets.FinalizeCharacterGoods(); // Save delegates m_charPurchaseSucceededDelegate = charPurchaseSucceededDelegate; m_charPurchaseCancelledDelegate = charPurchaseCancelledDelegate; m_restoreTransactionsCompletedDelegate = restoreTransactionsCompletedDelegate; m_restoreTransactionsFailedDelegate = restoreTransactionsFailedDelegate; m_coinBalanceChangedDelegate = coinBalanceChangedDelegate; m_gachaBalanceChangedDelegate = gachaBalanceChangedDelegate; // Subscribe to Store events StoreEvents.OnSoomlaStoreInitialized += OnSoomlaStoreInitialized; StoreEvents.OnCurrencyBalanceChanged += OnCurrencyBalanceChanged; StoreEvents.OnMarketPurchaseStarted += OnMarketPurchaseStarted; StoreEvents.OnMarketPurchase += OnMarketPurchase; StoreEvents.OnMarketPurchaseCancelled += OnMarketPurchaseCancelled; StoreEvents.OnMarketRefund += OnMarketRefund; StoreEvents.OnRestoreTransactionsStarted += OnRestoreTransactionsStarted; StoreEvents.OnRestoreTransactionsFinished += OnRestoreTransactionsFinished; StoreEvents.OnUnexpectedStoreError += OnUnexpectedStoreError; // Initialize rewards m_firstLaunchReward = new VirtualItemReward( "first-launch", "Give coins at first launch", CRCAssets.COIN_CURRENCY_ITEM_ID, FIRST_LAUNCH_REWARD_AMOUNT); // Initialize the store with the in-game implementation of IStoreAssets // Note: This must be done after setting up values in the store assets class SoomlaStore.Initialize(crcAssets); }
//each VirtualGood gets created seperately VirtualGood CreateGood(IAPObject obj, bool market) { PurchaseType purchaseType = null; if (market) purchaseType = new PurchaseWithMarket(obj.GetIdentifier(), 0.00); else purchaseType = new PurchaseWithVirtualItem(obj.virtualPrice.name, obj.virtualPrice.amount); switch (obj.type) { case IAPType.SingleUseVG: return new SingleUseVG(obj.title, obj.description, obj.id, purchaseType); case IAPType.SingleUsePackVG: return new SingleUsePackVG(obj.specific, obj.amount, obj.title, obj.description, obj.id, purchaseType); case IAPType.LifetimeVG: return new LifetimeVG(obj.title, obj.description, obj.id, purchaseType); case IAPType.EquippableVG: EquippableVG.EquippingModel equipModel = EquippableVG.EquippingModel.LOCAL; if (obj.specific == EquippableVG.EquippingModel.CATEGORY.ToString()) equipModel = EquippableVG.EquippingModel.CATEGORY; else if (obj.specific == EquippableVG.EquippingModel.GLOBAL.ToString()) equipModel = EquippableVG.EquippingModel.GLOBAL; return new EquippableVG(equipModel, obj.title, obj.description, obj.id, purchaseType); case IAPType.UpgradeVG: string[] props = obj.specific.Split(';'); return new UpgradeVG(props[0], string.IsNullOrEmpty(props[2]) ? null : props[2], string.IsNullOrEmpty(props[1]) ? null : props[1], obj.title, obj.description, obj.id, purchaseType); default: return null; } }
//each CurrencyPack gets created seperately VirtualCurrencyPack CreateCurrencyPack(IAPObject obj, bool market) { PurchaseType purchaseType = null; if(market) purchaseType = new PurchaseWithMarket(obj.GetIdentifier(), 0.00); else purchaseType = new PurchaseWithVirtualItem(obj.virtualPrice.name, obj.virtualPrice.amount); return new VirtualCurrencyPack(obj.title, obj.description, obj.id, obj.amount, obj.specific, purchaseType); }
/** * Constructor * * @param mName see parent * @param mDescription see parent * @param mItemId see parent * @param purchaseType see parent */ public NonConsumableItem(String mName, String mDescription, String mItemId, PurchaseWithMarket purchaseType) : base(mName, mDescription, mItemId, purchaseType) { }