/// <summary> /// Accepts a pending trade offer. /// </summary> /// <param name="trade">A 'TradeStatus' object</param> /// <returns>True if successful, false if not</returns> public bool AcceptTrade(Trade.TradeStatus trade) { int tradeId = trade.tradeid; var url = "https://steamcommunity.com/tradeoffer/" + tradeId + "/accept"; var referer = "http://steamcommunity.com/tradeoffer/" + tradeId + "/"; var sessionid = SessionId; var data = new NameValueCollection(); data.Add("sessionid", sessionid); data.Add("tradeofferid", tradeId.ToString()); data.Add("partner", trade.them.steamId.ConvertToUInt64().ToString()); string response = RetryWebRequest(url, "POST", data, Cookies, true, referer); if (string.IsNullOrEmpty(response)) { return(ValidateTradeAccept(trade)); } else { try { dynamic json = JsonConvert.DeserializeObject(response); var id = json.tradeid; return(true); } catch { return(ValidateTradeAccept(trade)); } } }
/// <summary> /// Manually validate if a trade offer went through by checking /inventoryhistory/ /// </summary> /// <param name="trade">A 'TradeStatus' object</param> /// <returns>True if the trade offer was successfully accepted, false if otherwise</returns> public bool ValidateTradeAccept(Trade.TradeStatus trade) { var history = GetTradeHistory(1); foreach (var completedTrade in history) { var givenItems = new List <Trade.TradeAsset>(); foreach (var myItem in trade.me.assets) { var genericItem = new Trade.TradeAsset(myItem.appid, myItem.contextid, myItem.assetid, myItem.amount); givenItems.Add(genericItem); } var receivedItems = new List <Trade.TradeAsset>(); foreach (var otherItem in trade.them.assets) { var genericItem = new Trade.TradeAsset(otherItem.appid, otherItem.contextid, otherItem.assetid, otherItem.amount); receivedItems.Add(genericItem); } if (givenItems.Count == completedTrade.GivenItems.Count && receivedItems.Count == completedTrade.ReceivedItems.Count) { foreach (var item in completedTrade.GivenItems) { var genericItem = new Trade.TradeAsset(item.appid, item.contextid, item.assetid, item.amount); if (!givenItems.Contains(genericItem)) { return(false); } } foreach (var item in completedTrade.ReceivedItems) { var genericItem = new Trade.TradeAsset(item.appid, item.contextid, item.assetid, item.amount); if (!receivedItems.Contains(genericItem)) { return(false); } } return(true); } } return(false); }
/// <summary> /// Declines a pending trade offer /// </summary> /// <param name="trade">A 'TradeStatus' object</param> /// <returns>True if successful, false if not</returns> public bool DeclineTrade(Trade.TradeStatus trade) { var url = "https://steamcommunity.com/tradeoffer/" + trade.tradeid + "/decline"; var referer = "http://steamcommunity.com/"; var sessionid = SessionId; var data = new NameValueCollection(); data.Add("sessionid", sessionid); string response = RetryWebRequest(url, "POST", data, Cookies, true, referer); try { dynamic json = JsonConvert.DeserializeObject(response); var id = json.tradeofferid; } catch { return(false); } return(true); }