void RequestNonConsumableProduct(ShopInApp inapp, ShopDelegate callback) { Flow.game_native.startLoading(); #if UNITY_ANDROID string id = inapp.androidBundle; #elif UNITY_IPHONE string id = inapp.appleBundle; #else Flow.game_native.stopLoading(); Flow.game_native.showMessage("Currently Unavailable","Purchasing only available in mobile devices."); return; #endif IAP.purchaseNonconsumableProduct(id, didSucceed => { Flow.game_native.stopLoading(); if(didSucceed) { if(inapp.type == ShopInAppType.NonConsumable && inapp.appleBundle.ToLower().Contains("noads")) { Save.Set(PlayerPrefsKeys.NOADS, true); Save.SaveAll(); } callback(ShopResultStatus.Success, id); } else { callback(ShopResultStatus.Failed, id); } }); }
public void PurchaseInApp(string id, ShopDelegate callback) { ShopInApp inapp = GetInApp(id); if(inapp.type == ShopInAppType.Consumable) RequestConsumableProduct(inapp, callback); else RequestNonConsumableProduct(inapp, callback); }
public void PurchaseInApp(string id, ShopDelegate callback) { //Debug.Log("PurchaseInApp"); ShopInApp inapp = GetInApp(id); if (inapp.type == ShopInAppType.Consumable) { //Debug.Log("Consumable"); RequestConsumableProduct(inapp, callback); } else { //Debug.Log("NonConsumable"); RequestNonConsumableProduct(inapp, callback); } }
public void RestoreTransactions(ShopDelegate callback) { IAP.restoreCompletedTransactions(productID => { if (productID.Contains("noads")) { Save.Set(PlayerPrefsKeys.NOADS, true); } else { Save.Set(PlayerPrefsKeys.ITEM + productID, true); } callback(ShopResultStatus.Success, productID); }); }
public void PurchaseInApp(string id, ShopDelegate callback) { //Debug.Log("PurchaseInApp"); ShopInApp inapp = GetInApp(id); if(inapp.type == ShopInAppType.Consumable) { //Debug.Log("Consumable"); RequestConsumableProduct(inapp, callback); } else { //Debug.Log("NonConsumable"); RequestNonConsumableProduct(inapp, callback); } }
public void OfferCoinPackAndBuyItem(ShopDelegate callback, ShopItem item) { // nao tem coins int difference = item.coinPrice - Flow.header.coins; ShopInApp coinPackToOffer = new ShopInApp(); ShopInApp biggestPack = new ShopInApp(); foreach (ShopInApp pack in coinPacks) { Debug.Log(pack.coinsCount); if (pack.coinsCount >= difference) { Debug.Log("coinpack selecionado: " + pack.appleBundle); coinPackToOffer = pack; break; } int mostCoins = 0; if (mostCoins < pack.coinsCount) { mostCoins = pack.coinsCount; biggestPack = pack; } } if (coinPackToOffer.name == null) { coinPackToOffer = biggestPack; } #if UNITY_ANDROID && !UNITY_EDITOR string packBundle = coinPackToOffer.androidBundle; #elif UNITY_IPHONE && !UNITY_EDITOR string packBundle = coinPackToOffer.appleBundle; Debug.Log("caiu no iOS e o packBundle: " + coinPackToOffer.appleBundle); #else string packBundle; Flow.game_native.showMessage("Not Enough Coins", "You don't have enough coins to buy this item"); return; #endif //List<string> tList = new List<string>(); Flow.game_native.startLoading(); UIManager.instance.blockInput = true; IAP.purchaseConsumableProduct(packBundle, purchased => { Flow.game_native.stopLoading(); UIManager.instance.blockInput = false; if (purchased) { Flow.header.coins += coinPackToOffer.coinsCount; if (Flow.header.coins >= item.coinPrice) { Flow.header.coins -= item.coinPrice; foreach (ShopItem iw in item.itemsWithin) { //comprou o pack e agora tem coins suficientes pra comprar o item if (Save.HasKey(PlayerPrefsKeys.ITEM + iw.id) && iw.type == ShopItemType.Consumable) { int userStock = Save.GetInt(PlayerPrefsKeys.ITEM + iw.id); userStock += iw.count; Save.Set(PlayerPrefsKeys.ITEM + iw.id, userStock); } else if (!Save.HasKey(PlayerPrefsKeys.ITEM + iw.id) && iw.type == ShopItemType.NonConsumable) { Save.Set(PlayerPrefsKeys.ITEM + iw.id, 1); } else { Save.Set(PlayerPrefsKeys.ITEM + iw.id, iw.count); } } Save.SaveAll(); callback(ShopResultStatus.Success, item.id); if (Save.HasKey(PlayerPrefsKeys.TOKEN)) { // se a compra deu sucesso e o cara esta logado, registrar no server GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/shop/buy.php", BuyingConfirmation); WWWForm form = new WWWForm(); for (int i = 0; i < item.itemsWithin.Length; i++) { form.AddField("items[" + i + "][id]", item.itemsWithin[i].id); form.AddField("items[" + i + "][count]", Save.GetInt(PlayerPrefsKeys.ITEM + item.itemsWithin[i].id)); form.AddField("coins", Flow.header.coins); } conn.connect(form); } } else { // comprou o pack e mesmo assim nao tem coins suficientes pra comprar o item Flow.game_native.showMessage("Not Enough Coins", "You'll need to buy another pack to buy this item!"); callback(ShopResultStatus.Failed, item.id); } //Save.Set(PlayerPrefsKeys.COINS.ToString(),Flow.header.coins); } else { // nao tem coins para comprar o item Flow.game_native.showMessage("Not Enough Coins", "You don't have enough coins to buy this item"); callback(ShopResultStatus.Failed, item.id); } }); }
public void BuyItem(ShopDelegate callback, ShopItem item) { Debug.Log(item.id); foreach (ShopItem itemWithin in item.itemsWithin) { if (Save.HasKey(PlayerPrefsKeys.ITEM + itemWithin.id) && itemWithin.type == ShopItemType.NonConsumable) { // ja tem o item Flow.game_native.showMessage("Already has item", "You already have this item."); callback(ShopResultStatus.Failed, item.id); return; } //else if(itemWithin.forFree } //Flow.game_native.startLoading(); if (item.coinPrice > Flow.header.coins) { // nao tem coins OfferCoinPackAndBuyItem(callback, item); } else { Debug.Log("tem coins, soma eh: " + item.coinPrice); // tem coins Flow.header.coins -= item.coinPrice; foreach (ShopItem iw in item.itemsWithin) { Debug.Log(iw.id); Debug.Log(Save.HasKey(PlayerPrefsKeys.ITEM + iw.id)); Debug.Log(iw.type.ToString()); if (Save.HasKey(PlayerPrefsKeys.ITEM + iw.id) && iw.type == ShopItemType.Consumable) { int userStock = Save.GetInt(PlayerPrefsKeys.ITEM + iw.id); userStock += iw.count; Save.Set(PlayerPrefsKeys.ITEM + iw.id, userStock); Debug.Log("tem item, eh consumivel"); } else if (!Save.HasKey(PlayerPrefsKeys.ITEM + iw.id) && iw.type == ShopItemType.NonConsumable) { Save.Set(PlayerPrefsKeys.ITEM + iw.id, 1); Debug.Log("nao tem item, eh nao consumivel"); } else { Save.Set(PlayerPrefsKeys.ITEM + iw.id, iw.count); Debug.Log("nao tem item, eh consumivel"); } } if (item.type == ShopItemType.NonConsumable) { Save.Set(PlayerPrefsKeys.ITEMSPACK + item.id, true); } //Save.Set(PlayerPrefsKeys.COINS,Flow.header.coins); Save.SaveAll(); callback(ShopResultStatus.Success, item.id); if (Save.HasKey(PlayerPrefsKeys.TOKEN)) { // se a compra deu sucesso e o cara esta logado, registrar no server GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/shop/buy.php", BuyingConfirmation); WWWForm form = new WWWForm(); for (int i = 0; i < item.itemsWithin.Length; i++) { form.AddField("items[" + i + "][id]", item.itemsWithin[i].id); form.AddField("items[" + i + "][count]", Save.GetInt(PlayerPrefsKeys.ITEM + item.itemsWithin[i].id)); form.AddField("coins", Flow.header.coins); } conn.connect(form); } } }
public void OfferCoinPackAndBuyItem(ShopDelegate callback, ShopItem item) { // nao tem coins int difference = item.coinPrice - Flow.header.coins; ShopInApp coinPackToOffer = new ShopInApp(); ShopInApp biggestPack = new ShopInApp(); foreach(ShopInApp pack in coinPacks) { Debug.Log(pack.coinsCount); if(pack.coinsCount >= difference) { Debug.Log("coinpack selecionado: "+ pack.appleBundle); coinPackToOffer = pack; break; } int mostCoins = 0; if(mostCoins < pack.coinsCount) { mostCoins = pack.coinsCount; biggestPack = pack; } } if(coinPackToOffer.name == null) { coinPackToOffer = biggestPack; } #if UNITY_ANDROID && !UNITY_EDITOR string packBundle = coinPackToOffer.androidBundle; #elif UNITY_IPHONE && !UNITY_EDITOR string packBundle = coinPackToOffer.appleBundle; Debug.Log("caiu no iOS e o packBundle: "+ coinPackToOffer.appleBundle); #else string packBundle; Flow.game_native.showMessage("Not Enough Coins", "You don't have enough coins to buy this item"); return; #endif //List<string> tList = new List<string>(); Flow.game_native.startLoading(); UIManager.instance.blockInput = true; IAP.purchaseConsumableProduct(packBundle, purchased => { Flow.game_native.stopLoading(); UIManager.instance.blockInput = false; if(purchased) { Flow.header.coins += coinPackToOffer.coinsCount; if(Flow.header.coins >= item.coinPrice) { Flow.header.coins -= item.coinPrice; foreach(ShopItem iw in item.itemsWithin) { //comprou o pack e agora tem coins suficientes pra comprar o item if(Save.HasKey(PlayerPrefsKeys.ITEM+iw.id) && iw.type == ShopItemType.Consumable) { int userStock = Save.GetInt(PlayerPrefsKeys.ITEM+iw.id); userStock += iw.count; Save.Set (PlayerPrefsKeys.ITEM+iw.id,userStock); } else if(!Save.HasKey(PlayerPrefsKeys.ITEM+iw.id) && iw.type == ShopItemType.NonConsumable) { Save.Set(PlayerPrefsKeys.ITEM+iw.id,1); } else { Save.Set(PlayerPrefsKeys.ITEM+iw.id, iw.count); } } Save.SaveAll(); callback(ShopResultStatus.Success, item.id); if(Save.HasKey(PlayerPrefsKeys.TOKEN)) { // se a compra deu sucesso e o cara esta logado, registrar no server GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/shop/buy.php", BuyingConfirmation); WWWForm form = new WWWForm(); for(int i = 0 ; i < item.itemsWithin.Length ; i++) { form.AddField("items["+i+"][id]", item.itemsWithin[i].id); form.AddField("items["+i+"][count]", Save.GetInt(PlayerPrefsKeys.ITEM+item.itemsWithin[i].id)); form.AddField("coins", Flow.header.coins); } conn.connect(form); } } else { // comprou o pack e mesmo assim nao tem coins suficientes pra comprar o item Flow.game_native.showMessage("Not Enough Coins", "You'll need to buy another pack to buy this item!"); callback(ShopResultStatus.Failed, item.id); } //Save.Set(PlayerPrefsKeys.COINS.ToString(),Flow.header.coins); } else { // nao tem coins para comprar o item Flow.game_native.showMessage("Not Enough Coins", "You don't have enough coins to buy this item"); callback(ShopResultStatus.Failed, item.id); } }); }
public void BuyItem(ShopDelegate callback, ShopItem item) { Debug.Log(item.id); foreach(ShopItem itemWithin in item.itemsWithin) { if(Save.HasKey(PlayerPrefsKeys.ITEM+itemWithin.id) && itemWithin.type == ShopItemType.NonConsumable) { // ja tem o item Flow.game_native.showMessage("Already has item","You already have this item."); callback(ShopResultStatus.Failed, item.id); return; } //else if(itemWithin.forFree } //Flow.game_native.startLoading(); if(item.coinPrice > Flow.header.coins) { // nao tem coins OfferCoinPackAndBuyItem(callback, item); } else { Debug.Log("tem coins, soma eh: "+item.coinPrice); // tem coins Flow.header.coins -= item.coinPrice; foreach(ShopItem iw in item.itemsWithin) { Debug.Log(iw.id); Debug.Log(Save.HasKey(PlayerPrefsKeys.ITEM+iw.id)); Debug.Log(iw.type.ToString()); if(Save.HasKey(PlayerPrefsKeys.ITEM+iw.id) && iw.type == ShopItemType.Consumable) { int userStock = Save.GetInt(PlayerPrefsKeys.ITEM+iw.id); userStock += iw.count; Save.Set(PlayerPrefsKeys.ITEM+iw.id,userStock); Debug.Log("tem item, eh consumivel"); } else if(!Save.HasKey(PlayerPrefsKeys.ITEM+iw.id) && iw.type == ShopItemType.NonConsumable) { Save.Set(PlayerPrefsKeys.ITEM+iw.id,1); Debug.Log("nao tem item, eh nao consumivel"); } else { Save.Set(PlayerPrefsKeys.ITEM+iw.id, iw.count); Debug.Log("nao tem item, eh consumivel"); } } if(item.type == ShopItemType.NonConsumable) Save.Set(PlayerPrefsKeys.ITEMSPACK+item.id,true); //Save.Set(PlayerPrefsKeys.COINS,Flow.header.coins); Save.SaveAll(); callback(ShopResultStatus.Success, item.id); if(Save.HasKey(PlayerPrefsKeys.TOKEN)) { // se a compra deu sucesso e o cara esta logado, registrar no server GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/shop/buy.php", BuyingConfirmation); WWWForm form = new WWWForm(); for(int i = 0 ; i < item.itemsWithin.Length ; i++) { form.AddField("items["+i+"][id]", item.itemsWithin[i].id); form.AddField("items["+i+"][count]", Save.GetInt(PlayerPrefsKeys.ITEM+item.itemsWithin[i].id)); form.AddField("coins", Flow.header.coins); } conn.connect(form); } } }
void RequestConsumableProduct(ShopInApp inapp, ShopDelegate callback) { Flow.game_native.startLoading(); UIManager.instance.blockInput = true; #if UNITY_ANDROID string id = inapp.androidBundle; #elif UNITY_IPHONE string id = inapp.appleBundle; #else Flow.game_native.stopLoading(); Flow.game_native.showMessage("Currently Unavailable","Purchasing only available in mobile devices."); return; #endif IAP.purchaseConsumableProduct(id, didSucceed => { Flow.game_native.stopLoading(); UIManager.instance.blockInput = false; if(didSucceed) { if(inapp.isPackOfCoins) { //int coinStock = Save.GetInt(PlayerPrefsKeys.COINS); Flow.header.coins += inapp.coinsCount; //Save.Set(PlayerPrefsKeys.COINS,coinStock); //Save.SaveAll(); } callback(ShopResultStatus.Success, id); if(Save.HasKey(PlayerPrefsKeys.TOKEN)) { // se a compra deu sucesso e o cara esta logado, registrar no server GameJsonAuthConnection conn = new GameJsonAuthConnection(Flow.URL_BASE + "login/shop/coins.php", BuyingConfirmation); WWWForm form = new WWWForm(); form.AddField("coins", Flow.header.coins); conn.connect(form); } } else { callback(ShopResultStatus.Failed, id); /*Debug.Log("Falha na compra de "+id); purchaseDialog.Show(); purchaseDialog.SetMessage("Purchase failed"); purchaseDialog.SetType(PurchaseDialog.DialogTypeEnum.OK);*/ } /*slider.RefreshSliceValues(); cashMachineSound.audio.Play();*/ }); }
public void RestoreTransactions(ShopDelegate callback) { IAP.restoreCompletedTransactions(productID => { if(productID.Contains("noads")) { Save.Set(PlayerPrefsKeys.NOADS, true); } else { Save.Set (PlayerPrefsKeys.ITEM+productID, true); } callback(ShopResultStatus.Success, productID); }); }
void RequestConsumableProduct(ShopInApp inapp, ShopDelegate callback) { Flow.game_native.startLoading(); #if UNITY_ANDROID string id = inapp.androidBundle; #elif UNITY_IPHONE string id = inapp.appleBundle; #else Flow.game_native.stopLoading(); Flow.game_native.showMessage("Currently Unavailable","Purchasing only available in mobile devices."); return; #endif IAP.purchaseConsumableProduct(id, didSucceed => { Flow.game_native.stopLoading(); if(didSucceed) { if(inapp.isPackOfCoins) { int coinStock = Save.GetInt(PlayerPrefsKeys.COINS); coinStock += inapp.coinsCount; Save.Set(PlayerPrefsKeys.COINS,coinStock); Save.SaveAll(); } callback(ShopResultStatus.Success, id); /*Debug.Log("Sucesso na compra de "+id); int currentCoins = PlayerPrefs.GetInt(PlayerPrefsKeys.Coins.ToString()); if(id.Contains("coins_10k")) { PlaceOrder(currentCoins, Coins_Package_1); } else if(id.Contains("coins_25k")) { PlaceOrder(currentCoins, Coins_Package_2); } else if(id.Contains("coins_50k")) { PlaceOrder(currentCoins, Coins_Package_3); } else if(id.Contains("coins_100k")) { PlayerPrefs.SetInt(PlayerPrefsKeys.DoNotBotherTheUsers.ToString(), 1); PlaceOrder(currentCoins, Coins_Package_4); }*/ } else { callback(ShopResultStatus.Failed, id); /*Debug.Log("Falha na compra de "+id); purchaseDialog.Show(); purchaseDialog.SetMessage("Purchase failed"); purchaseDialog.SetType(PurchaseDialog.DialogTypeEnum.OK);*/ } /*slider.RefreshSliceValues(); cashMachineSound.audio.Play();*/ }); }
public void RestoreTransactions(ShopDelegate callback) { IAP.restoreCompletedTransactions(productID => { callback(ShopResultStatus.Success, productID); }); }