public Trade(TradeOffers tradeOffers, SteamID partnerId, SteamWeb steamWeb) { _tradeOffers = tradeOffers; _partnerId = partnerId; _steamWeb = steamWeb; tradeStatus = new TradeStatus { version = 1, newversion = true }; tradeStatus.me = new TradeStatusUser(ref tradeStatus); tradeStatus.them = new TradeStatusUser(ref tradeStatus); }
/// <summary> /// Send the current trade offer. /// </summary> /// <param name="message">Message to send with trade offer.</param> /// <param name="token">Optional trade offer token.</param> /// <exception cref="TradeOfferSteamException">Thrown when Steam gives an unexpected response.</exception> /// <returns>ID of the newly created trade offer.</returns> public ulong SendTrade(string message, string token = "") { const string url = "https://steamcommunity.com/tradeoffer/new/send"; var referer = "https://steamcommunity.com/tradeoffer/new/?partner=" + _partnerId.AccountID; var data = new NameValueCollection { { "sessionid", _steamWeb.SessionId }, { "serverid", "1" }, { "partner", _partnerId.ConvertToUInt64().ToString() }, { "tradeoffermessage", message }, { "json_tradeoffer", JsonConvert.SerializeObject(tradeStatus) }, { "trade_offer_create_params", token == "" ? "{}" : "{\"trade_offer_access_token\":\"" + token + "\"}" } }; dynamic jsonResponse; try { var response = TradeOffers.RetryWebRequest(_steamWeb, url, "POST", data, true, referer); jsonResponse = JsonConvert.DeserializeObject <dynamic>(response); } catch { throw new TradeOfferSteamException(); } if (jsonResponse.strError != null) { throw new TradeOfferSteamException(jsonResponse.strError); } try { ulong tradeOfferId = Convert.ToUInt64(jsonResponse.tradeofferid); _tradeOffers.AddPendingTradeOfferToList(tradeOfferId); return(tradeOfferId); } catch { throw new TradeOfferSteamException(); } }