Exemplo n.º 1
0
        public static string generateCheckoutPostString(ProfileInfo info, String authenticity_token, String reCaptcha)
        {
            StringBuilder postString = new StringBuilder();

            postString.Append("utf8=");
            postString.Append(ProfileInfo.UTF8);
            postString.Append("&authenticity_token=");
            postString.Append(Uri.EscapeDataString(authenticity_token));
            postString.Append("&order%5Bbilling_name%5D=");
            postString.Append(info.FullName.Replace(" ", "+"));
            postString.Append("&order%5Bemail%5D=");
            postString.Append(info.Email.Replace("@", "%40"));
            postString.Append("&order%5Btel%5D=");
            postString.Append(info.TelNr.Replace("+", "%2B"));
            postString.Append("&order%5Bbilling_address%5D=");
            postString.Append(info.Address1.Replace(" ", "+"));
            postString.Append("&order%5Bbilling_address_2%5D=");
            postString.Append(info.Address2.Replace(" ", "+"));
            postString.Append("&order%5Bbilling_address_3%5D=");
            postString.Append("");    // address3 will be null - this line has no effect at all
            postString.Append("&order%5Bbilling_city%5D=");
            postString.Append(info.City.Replace(" ", "+"));
            postString.Append("&order%5Bbilling_zip%5D=");
            postString.Append(info.Postcode);
            postString.Append("&order%5Bbilling_country%5D=");
            postString.Append(CountryConverter.GetCountryCode(info.Country));
            postString.Append("&same_as_billing_address=1&store_credit_id=");
            postString.Append("&credit_card%5Btype%5D=");
            postString.Append(info.CardType.ToLower());
            postString.Append("&credit_card%5Bcnb%5D=");
            string cardno = info.CardNr;

            cardno = cardno.Trim();
            cardno = cardno.Substring(0, 4) + "+" + cardno.Substring(4, 4) + "+" + cardno.Substring(8, 4) + "+" + cardno.Substring(12, 4);
            postString.Append(cardno);
            postString.Append("&credit_card%5Bmonth%5D=");
            postString.Append(info.ExpMonth);
            postString.Append("&credit_card%5Byear%5D=");
            postString.Append(info.ExpYear);
            postString.Append("&credit_card%5Bvval%5D=");
            postString.Append(info.CVV);
            postString.Append("&order%5Bterms%5D=0&order%5Bterms%5D=1");
            postString.Append("&g-recaptcha-response=");
            postString.Append(reCaptcha);
            postString.Append("&hpcvv=");
            return(postString.ToString());
        }
Exemplo n.º 2
0
        // Goes to checkout page, gets autheticity token,
        // checks out with cookies provided in TaskInfo
        // that contain item that was put in cart
        // and profile provided in ProfileInfo
        private void checkout(ProfileInfo info, TaskInfo ti)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://www.supremenewyork.com/checkout");

            req.Method          = "GET";
            req.CookieContainer = cookies[ti.name];
            WebTools.setProxy((ProxyInfo)infoManager.GetProxyByName(ti.proxyName), req);
            req.Accept  = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
            req.Referer = ti.lastItemUri;
            req.Headers["upgrade-insecure-requests"] = "1";

            // Go to checkout page to read Authenticity Token
            HttpWebResponse res            = WebTools.SendRequestAtAllCosts(req);
            StreamReader    responseReader = new StreamReader(res.GetResponseStream());
            String          finalRes       = responseReader.ReadToEnd();

            responseReader.Close();

            Console.WriteLine(finalRes);

            String authenticity_token = new Regex("<input type=\"hidden\" name=\"authenticity_token\" value=\"(.+?)\" />").Match(finalRes).Groups[1].Value;

            Console.WriteLine("Auth=" + authenticity_token);

            StringBuilder sb = new StringBuilder();

            sb.Append("https://www.supremenewyork.com/checkout.js?utf8=%E2%9C%93&");
            sb.Append("authenticity_token=");
            sb.Append(Uri.EscapeDataString(authenticity_token));
            sb.Append("&order%5Bbilling_name%5D=");
            sb.Append(info.FullName.Replace(" ", "+"));
            sb.Append("&order%5Bemail%5D=");
            sb.Append(info.Email.Replace("@", "%40"));
            sb.Append("&order%5Btel%5D=");
            sb.Append(info.TelNr.Replace("+", "%2B"));
            sb.Append("&order%5Bbilling_address%5D=");
            sb.Append(info.Address1.Replace(" ", "+"));
            sb.Append("&order%5Bbilling_address_2%5D=");
            sb.Append(info.Address2.Replace(" ", "+"));
            sb.Append("&order%5Bbilling_address_3%5D=");
            sb.Append("");    // address3 will be null - this line has no effect at all
            sb.Append("&order%5Bbilling_city%5D=");
            sb.Append(info.City.Replace(" ", "+"));
            sb.Append("&order%5Bbilling_zip%5D=");
            sb.Append(info.Postcode);
            sb.Append("&order%5Bbilling_country%5D=");
            sb.Append(CountryConverter.GetCountryCode(info.Country));
            sb.Append("&same_as_billing_address=1&store_credit_id=");
            sb.Append("&credit_card%5Btype%5D=visa&credit_card%5Bcnb%5D=&credit_card%5Bmonth%5D=");
            sb.Append("09&credit_card%5Byear%5D=2018&credit_card%5Bvval%5D=&order%5Bterms%5D=0&g-recaptcha-response=&hpcvv=&cnt=2");
            string checkoutJsUri = sb.ToString();

            string csrfToken = SupremeParser.GetCSRFToken(finalRes);

            //// When selecting the country manually, supreme sends a GET request
            //// and gets a new supreme sessid. I don't know if it changes anything,
            //// but I wanna do everything like human does - from beginning till end.
            req        = (HttpWebRequest)WebRequest.Create(checkoutJsUri);
            req.Method = "GET";
            req.Accept = "text/html, */*; q=0.01";
            req.Headers["accept-encoding"]  = "gzip, deflate, br";
            req.Headers["x-csrf-token"]     = csrfToken;
            req.Headers["x-requested-with"] = "XMLHttpRequest";
            req.CookieContainer             = cookies[ti.name];
            WebTools.setProxy((ProxyInfo)infoManager.GetProxyByName(ti.proxyName), req);
            res = WebTools.SendRequestAtAllCosts(req);
            res.Close();
            // just cookies interest me

            //Console.WriteLine("After checkout js:");
            //foreach (var cookie in cookies[ti.name].GetCookies(new Uri("http://www.supremenewyork.com")))
            //{
            //    Console.WriteLine(cookie);
            //}


            Thread.Sleep(20);
            // Before checkout the email is being verified and we get some new supreme sessid.. so many requests

            // This site needs a custom request - it returns 404 error, yet it sets the cookies?
            // It's strange, but yeah, even with 404 exception, the cookies are being set.
            //req = (HttpWebRequest)WebRequest.Create("https://www.supremenewyork.com/store_credits/verify?email=" + info.Email.Replace("@", "%40"));
            //req.Method = "GET";
            //req.CookieContainer = cookies[ti.name];
            //req.Headers["x-csrf-token"] = csrfToken;
            //req.Headers["x-requested-with"] = "XMLHttpRequest";
            //req.Accept = "*/*";
            //req.Headers["accept-encoding"] = "gzip, deflate, br";

            //req.Referer = "https://www.supremenewyork.com/checkout";

            //WebTools.setProxy((ProxyInfo)infoManager.GetProxyByName(ti.proxyName), req);
            //try
            //{
            //    Console.WriteLine("In");
            //    req.AllowAutoRedirect = true;
            //    res = (HttpWebResponse)req.GetResponse();
            //    res.Close();
            //    Console.WriteLine("Out");
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine("ex");
            //    Console.WriteLine(ex.Message);
            //}


            //Console.WriteLine("After mail check:");
            //foreach (var cookie in cookies[ti.name].GetCookies(new Uri("http://www.supremenewyork.com")))
            //{
            //    Console.WriteLine(cookie);
            //}

            //Console.WriteLine(finalRes);



            ReCaptchaResponseInfo rcri = captchaMonitor.GetSpareReCaptcha();

            if (rcri == null)
            {
                forwardMessageToLogMonitor(Properties.Resources.errorNoCaptchasAvailable, ti.name);
                return;
            }
            String postString = PostStringGenerator.generateCheckoutPostString(info, authenticity_token, rcri.response);

            Console.WriteLine(postString);

            // Fill Post request info
            req                         = (HttpWebRequest)WebRequest.Create("https://www.supremenewyork.com/checkout");
            req.Referer                 = "https://www.supremenewyork.com/checkout";
            req.Method                  = "POST";
            req.ContentType             = "application/x-www-form-urlencoded";
            req.ContentLength           = postString.Length;
            req.Host                    = "www.supremenewyork.com";
            req.Referer                 = "https://www.supremenewyork.com/checkout";
            req.Headers["x-csrf-token"] = csrfToken;
            req.CookieContainer         = cookies[ti.name];
            WebTools.setProxy((ProxyInfo)infoManager.GetProxyByName(ti.proxyName), req);

            // Sleep for the Checkout delay
            Thread.Sleep(Int32.Parse(ti.checkoutDelay));

            // Send request
            StreamWriter postWriter = new StreamWriter(req.GetRequestStream());

            postWriter.Write(postString);
            postWriter.Close();

            res            = WebTools.SendRequestAtAllCosts(req);
            responseReader = new StreamReader(res.GetResponseStream());
            finalRes       = responseReader.ReadToEnd();
            responseReader.Close();

            Console.WriteLine(finalRes);

            // checkout OK
            if (finalRes.Contains("submitted"))
            {
                forwardMessageToLogMonitor(Properties.Resources.logCheckedOutSuc, "BOT");
            }
            else if (finalRes.Contains("Card Payment"))
            {
                forwardMessageToLogMonitor(Properties.Resources.cardError, "BOT");
            }
            else if (finalRes.Contains("Unfortunately"))
            {
                forwardMessageToLogMonitor(Properties.Resources.checkoutError, "BOT");
            }
        }