private void OnInitDeal(BuyResponse resp) { m_LabelOtherName.text = resp.SellerName; m_SpriteMyIcon.gameObject.SetActive(true); m_SpriteMyIcon.spriteName = MessageTreeLogic.ConvertIdToName(resp.ItemId); m_SpriteOtherIcon.gameObject.SetActive(false); }
public BuyResponse Post(BuyRequest request) { if (request == null) { return(new BuyResponse(BuyResponseStatus.DeserializationException)); } User user; BuyReceipt buyReceipt; var isFree = Lottery.IsFree(); try { user = _userService.GetUserByBadge(request.Badge); request.Validate(ConfigurationFacade.RemoteHashKey); buyReceipt = _transactionService.Buy(request); } catch (InvalidBadgeException) { return(new BuyResponse(request.Badge)); } catch (InvalidHashException) { return(new BuyResponse(BuyResponseStatus.InvalidHash)); } catch (InvalidProductException) { return(new BuyResponse(BuyResponseStatus.InvalidProduct)); } catch (InvalidTimestampException) { return(new BuyResponse(BuyResponseStatus.InvalidTimestamp)); } catch (InsufficientFundsException) { return(new BuyResponse(BuyResponseStatus.InsufficientFunds)); } var balanceString = buyReceipt.NewBalance.ToString("N", CultureInfo.InvariantCulture.NumberFormat); var validResponse = new BuyResponse(user.Name, balanceString, request.Product); if (!isFree) { return(validResponse); } try { Reimburse(buyReceipt.AmountDebited, user.Id); } catch (Exception e) { _logService.Log(e.ToString()); return(validResponse); } return(new BuyResponse(BuyResponseStatus.Free)); }
private IEnumerator BuyRequest() { String loginToken = PlayerPrefs.GetString("login_token"); if (loginToken == null || loginToken.Length < 1) { Debug.Log("No login token"); yield break; } BuyRequest buyRequest = new BuyRequest(); buyRequest.token = loginToken; buyRequest.buildingType = Constants.Buildings.TYPE_FARM; WWWForm form = new WWWForm(); Debug.Log("json request: " + JsonUtility.ToJson(buyRequest)); form.AddField("json", JsonUtility.ToJson(buyRequest)); using (UnityWebRequest www = UnityWebRequest.Post(ENDPOINT + "/buy", form)) { yield return(www.Send()); Debug.Log("text: " + www.downloadHandler.text); if (www.isNetworkError) { Debug.Log(www.error); } else if (www.responseCode != 200) { Debug.Log("Failed with response code: " + www.responseCode); } else { BuyResponse resp = JsonUtility.FromJson <BuyResponse>(www.downloadHandler.text); if (resp == null) { Debug.Log("null resp"); yield break; } if (resp.error != null) { Debug.Log("error: " + resp.error); } else if (resp.building == null) { Debug.Log("no building returned"); } else { Debug.Log("Bought building: " + resp.building.id + " last collected: " + resp.building.lastCollected); } }; } }
private bool CheckToTip(BuyResponse buy, SellResponse sell) { if (null != buy) { return(buy.Success); } if (null != sell) { return(sell.Success); } return(false); }
public BuyResponse Buy(BuyRequest request) { var response = new BuyResponse(); try { // Подсчитываем общее кол-во монет с учетом вновь прибывших var coinsBuffer = _coinService.GetAllCoins().OrderByDescending(x => x.Value); var totalCoins = 0; foreach (var coin in coinsBuffer) { foreach (var coinOrder in request.Coins) { if (coin.Id == coinOrder.Key) { totalCoins += coin.Value * coinOrder.Value; coin.Count += coinOrder.Value; } } } var refund = totalCoins - request.TotalCost; if (refund != 0) { response.Refund = CalculateRefund(refund, coinsBuffer); } foreach (var drinkId in request.Drinks) { var drink = _drinkService.GetDrinkById(drinkId); if (drink != null) { drink.Count += -1; _drinkService.Update(drink); } } if (response.Refund != null && response.Refund.Count > 0) { foreach (var itemDictionary in response.Refund) { itemDictionary.Key.Count += -itemDictionary.Value; _coinService.Update(itemDictionary.Key); } } } catch (Exception e) { response.ErrorCode = 1; response.Message = e.Message; } return(response); }
public void TestAppstoreBuyXmlGetAttributes() { string xml = @"<roar tick=""130695522924""> <appstore> <buy status=""ok""/> </appstore> </roar>" ; System.Xml.XmlElement nn = RoarExtensions.CreateXmlElement(xml); Roar.DataConversion.Responses.Appstore.Buy buy_parser = new Roar.DataConversion.Responses.Appstore.Buy(); BuyResponse response = buy_parser.Build(nn); Assert.IsNotNull(response); }
public ActionResult ZnalezionePolaczenia(FormCollection form) { BuyResponse response = new BuyResponse(); string train = form["checkTrain"].ToString(); int amount = int.Parse(form["ILOSC"]); string ticket_type = form["ticket"].ToString(); Rpc rpc = new Rpc(); BuyRequest buyRequest = new BuyRequest() { TravelId = train, UserId = Session["userID"].ToString(), FromStation = Session["from"].ToString(), ToStation = Session["to"].ToString(), Amount = amount.ToString(), TicketType = ticket_type }; bool buyResponse = rpc.SendBuyRequest(buyRequest); return(RedirectToAction("konto")); }
public void OnBuyResponse(BuyResponse resp) { if (CheckToTip(resp, null)) { m_iSellerItemId = resp.ItemId; m_iChatId = resp.ChatId; m_iSaleId = resp.SaleId; ChangeMTStatus(MTStatus.Buy); ChangeChatStatus(ChatStatus.ConnectFree); WindowManager.Instance.OpenWindow(WindowID.MsgTreeBuy); if (null != m_OnInitBuyDealCallBack) { m_OnInitBuyDealCallBack(resp); } } else { TipManager.Instance.Alert("没有在线卖家"); // show tip WindowManager.Instance.OpenWindow(WindowID.MsgTreeSelectPanel); } }
/// <summary> /// Совершает покупку наптка(ов) /// </summary> /// <param name="cost"></param> /// <returns></returns> public ActionResult BuyDrink(int cost) { var paid = (int?)Session["paid"] ?? 0; // Проверяем хватает ли внесенной суммы для совершения покупки if (cost > paid) { TempData["errors"] = "Не достаточно денег для завершения покупки!"; return(RedirectToAction("Index", "Home")); } //Проверяем наличие напитков в корзине if ((Session["drinks"] == null) || ((List <int>)Session["drinks"]).Count == 0) { TempData["errors"] = "Корзина пуста!"; return(RedirectToAction("Index", "Home")); } BuyResponse response = new BuyResponse(); try { BuyRequest request = new BuyRequest { Drinks = (List <int>)Session["drinks"], Coins = (Dictionary <int, int>)Session["coins"], TotalCost = cost }; HttpResponseMessage result = HttpService.PostAsync("api/machine/Buy", request).Result; if (result.IsSuccessStatusCode) { response = result.Content.ReadAsAsync <BuyResponse>().Result; //Если АПИ вернул успех, очищаем корзину, монеты в автомате, выдаем сдачу и сообщение if (response.ErrorCode == 0 && string.IsNullOrEmpty(response.Message)) { Session.Remove("drinks"); Session.Remove("coins"); Session.Remove("paid"); Session.Remove("refund"); var message = "Напиток куплен. "; if (response.Refund != null && response.Refund.Count > 0) { message += "СДАЧА = "; var refund = 0; foreach (var refundItem in response.Refund) { refund += refundItem.Key.Value * refundItem.Value; message += refundItem.Key.Caption + " - " + refundItem.Value + " шт.; "; } Session["refund"] = refund; } TempData["success"] = message; } else { TempData["errors"] = response.Message; } return(RedirectToAction("Index", "Home")); } response.ErrorCode = 1; response.Message = "Ошибка получения данных"; } catch (Exception ex) { response.ErrorCode = 2; response.Message = ex.Message; } return(RedirectToAction("Index", "Home")); }
public void TestShopBuyXmlGetAttributes() { string xml = @"<roar tick=""125555445657""> <shop> <buy status=""ok""> <costs> <cost type=""stat_change"" ikey=""coins"" value=""-5""/> <cost type=""stat_change"" ikey=""premium_currency"" value=""-67""/> <cost type=""stat_change"" ikey=""coins"" value=""-4""/> <cost type=""removed_items"" ikey=""talisman"" count=""4""/> <cost type=""removed_items"" ikey=""talisman"" count=""3""/> <cost type=""removed_items"" ikey=""ring_of_power"" count=""1""/> </costs> <modifiers> <modifier type=""add_xp"" value=""100""/> <modifier type=""add_item"" ikey=""item_key"" item_id=""16268470388190951200""/> <modifier type=""add_xp"" value=""45""/> <modifier type=""add_item"" ikey=""talisman"" item_id=""1117206301""/> <modifier type=""add_item"" ikey=""talisman"" item_id=""1039149107""/> <modifier type=""removed_items"" ikey=""talisman"" count=""2""/> <modifier type=""stat_change"" ikey=""premium_currency"" value=""16""/> <modifier type=""stat_change"" ikey=""premium_currency"" value=""7""/> <modifier type=""add_xp"" value=""9""/> <modifier type=""stat_change"" ikey=""premium_currency"" value=""177""/> <modifier type=""add_xp"" value=""1567""/> <modifier type=""add_xp"" value=""3456""/> <modifier type=""stat_change"" ikey=""premium_currency"" value=""9876""/> </modifiers> <tags> <tag value=""special""/> <tag value=""magic""/> </tags> </buy> </shop> <!--Server block shows server updates below--> <server> <update type=""currency"" ikey=""coins"" value=""203""/> <inventory_changed/> </server> </roar>" ; System.Xml.XmlElement nn = RoarExtensions.CreateXmlElement(xml); Roar.DataConversion.Responses.Shop.Buy converter = new Roar.DataConversion.Responses.Shop.Buy(); BuyResponse response = converter.Build(nn); Assert.IsNotNull(response.buy_response); Assert.AreEqual(response.buy_response.stat_change.Count, 2); Assert.AreEqual(response.buy_response.stat_change["coins"], -9); Assert.AreEqual(response.buy_response.stat_change["premium_currency"], 10009); Assert.AreEqual(response.buy_response.removed_items.Count, 2); Assert.AreEqual(response.buy_response.removed_items["talisman"], 9); Assert.AreEqual(response.buy_response.removed_items["ring_of_power"], 1); Assert.AreEqual(response.buy_response.add_xp, 5177); Assert.AreEqual(response.buy_response.add_item.Count, 2); Assert.AreEqual(response.buy_response.add_item["item_key"][0], "16268470388190951200"); Assert.AreEqual(response.buy_response.add_item["talisman"][0], "1117206301"); Assert.AreEqual(response.buy_response.add_item["talisman"][1], "1039149107"); Assert.AreEqual(response.buy_response.tags.Count, 2); Assert.AreEqual(response.buy_response.tags[0], "special"); Assert.AreEqual(response.buy_response.tags[1], "magic"); }