public static TwocheckoutResponse Check(Dictionary <string, string> args, String secret)
        {
            TwocheckoutResponse Result = new TwocheckoutResponse();
            String Notice = JsonConvert.SerializeObject(Result, Formatting.Indented);

            if (!String.IsNullOrEmpty(secret) && args.ContainsKey("sid") &&
                args.ContainsKey("order_number") && args.ContainsKey("total") &&
                args.ContainsKey("key"))
            {
                String HashString = secret + args["sid"] + args["order_number"] + args["total"];
                String CheckHash  = TwocheckoutUtil.Md5Hash(HashString);
                if (CheckHash != args["key"])
                {
                    Result.response_code    = "Fail";
                    Result.response_message = "Hash Mismatch";
                }
                else
                {
                    Result.response_code    = "Success";
                    Result.response_message = "Hash Matched";
                }
            }
            else
            {
                Result.response_code    = "Notice";
                Result.response_message = "You must pass a sid, order_number, total, key and secret word.";
            }
            return(Result);
        }
Esempio n. 2
0
        public static String Link(Dictionary <string, string> args)
        {
            StringBuilder Link       = new StringBuilder("https://www.2checkout.com/checkout/spurchase?");
            String        Parameters = TwocheckoutUtil.ConstructQueryString(args);

            Link.Append(Parameters);
            return(Link.ToString());
        }
Esempio n. 3
0
        public String ApiPost(String urlSuffix, Dictionary <string, string> args)
        {
            String          Url     = TwocheckoutConfig.BaseUrl + urlSuffix;
            String          Data    = TwocheckoutUtil.ConstructQueryString(args);
            Uri             Address = new Uri(Url);
            String          Result  = null;
            HttpWebRequest  Request;
            HttpWebResponse Response = null;

            try
            {
                Request             = WebRequest.Create(Address) as HttpWebRequest;
                Request.Credentials = new NetworkCredential(ApiUsername, ApiPassword);
                Request.Method      = "POST";
                Request.UserAgent   = "2Checkout .NET/0.1.0";
                Request.ContentType = "application/x-www-form-urlencoded";
                Request.Accept      = "application/json";
                byte[] byteData = UTF8Encoding.UTF8.GetBytes(Data.ToString());
                Request.ContentLength = byteData.Length;
                using (Stream postStream = Request.GetRequestStream())
                {
                    postStream.Write(byteData, 0, byteData.Length);
                }
                using (Response = Request.GetResponse() as HttpWebResponse)
                {
                    StreamReader reader = new StreamReader(Response.GetResponseStream());
                    Result = reader.ReadToEnd();
                }
            }
            catch (WebException wex)
            {
                if (wex.Response != null)
                {
                    using (HttpWebResponse ErrorResponse = (HttpWebResponse)wex.Response)
                    {
                        StreamReader Reader = new StreamReader(ErrorResponse.GetResponseStream());
                        Result = Reader.ReadToEnd();
                        throw new TwocheckoutException(Result);
                    }
                    throw;
                }
                return(Result);
            }
            finally
            {
                if (Response != null)
                {
                    Response.Close();
                }
            }
            return(Result);
        }
Esempio n. 4
0
        public String ApiGet(String urlSuffix, Dictionary <string, string> args = null)
        {
            String Url         = TwocheckoutConfig.BaseUrl + urlSuffix;
            String QueryString = null;

            if (args != null)
            {
                QueryString = TwocheckoutUtil.ConstructQueryString(args);
            }
            String          RequestUrl = Url + "?" + QueryString;
            String          Result     = null;
            HttpWebRequest  Request;
            HttpWebResponse Response = null;

            try
            {
                Request = WebRequest.Create(RequestUrl) as HttpWebRequest;
                ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); };
                Request.Credentials = new NetworkCredential(ApiUsername, ApiPassword);
                Request.Accept      = "application/json";
                Request.UserAgent   = "2Checkout .NET/0.1.0";
                using (Response = Request.GetResponse() as HttpWebResponse)
                {
                    StreamReader reader = new StreamReader(Response.GetResponseStream());
                    Result = reader.ReadToEnd();
                    return(Result);
                }
            }
            catch (WebException wex)
            {
                if (wex.Response != null)
                {
                    using (HttpWebResponse errorResponse = (HttpWebResponse)wex.Response)
                    {
                        StreamReader reader = new StreamReader(errorResponse.GetResponseStream());
                        Result = reader.ReadToEnd();
                        throw new TwocheckoutException(Result);
                    }
                    throw;
                }
                return(Result);
            }
            finally
            {
                if (Response != null)
                {
                    Response.Close();
                }
            }
        }
Esempio n. 5
0
        public static TwocheckoutResponse Stop(Dictionary <string, string> parameters)
        {
            String Result = null;
            TwocheckoutResponse activeObj = new TwocheckoutResponse();

            if (parameters.ContainsKey("sale_id"))
            {
                String UrlSuffix = "sales/detail_sale";
                var    Request   = new TwocheckoutApi {
                };
                Result = Request.ApiGet(UrlSuffix, parameters);
                Dictionary <string, string> Active = TwocheckoutUtil.Active(Result);
                if (Active.ContainsKey("lineitem_id0"))
                {
                    UrlSuffix = "sales/stop_lineitem_recurring";
                    var    Response         = new Dictionary <string, string>();
                    String stoppedLineitems = null;
                    foreach (var entry in Active)
                    {
                        var Params = new Dictionary <string, string>();
                        Params.Add("lineitem_id", entry.Value);
                        Result            = Request.ApiPost(UrlSuffix, Params);
                        stoppedLineitems += "," + entry.Value;
                    }
                    stoppedLineitems = stoppedLineitems.Remove(0, 1);
                    Response.Add("response_code", "OK");
                    Response.Add("response_message", stoppedLineitems);
                    String Json = JsonConvert.SerializeObject(Response, Formatting.Indented);
                    activeObj = Newtonsoft.Json.JsonConvert.DeserializeObject <TwocheckoutResponse>(Json);
                    return(activeObj);
                }
                else
                {
                    TwocheckoutResponse Error = new TwocheckoutResponse();
                    Error.response_code    = "Notice";
                    Error.response_message = "No active recurring lineitems.";
                    return(Error);
                }
            }
            else
            {
                String UrlSuffix = "sales/stop_lineitem_recurring";
                var    Request   = new TwocheckoutApi {
                };
                Result    = Request.ApiPost(UrlSuffix, parameters);
                activeObj = Newtonsoft.Json.JsonConvert.DeserializeObject <TwocheckoutResponse>(Result);
            }
            return(activeObj);
        }
        public static TwocheckoutResponse Check(Dictionary <string, string> args, String secret)
        {
            TwocheckoutResponse Result = new TwocheckoutResponse();
            String Notice = JsonConvert.SerializeObject(Result, Formatting.Indented);

            if (!String.IsNullOrEmpty(secret) && args.ContainsKey("sale_id") &&
                args.ContainsKey("vendor_id") && args.ContainsKey("invoice_id") &&
                args.ContainsKey("md5_hash"))
            {
                String HashString = args["sale_id"] + args["vendor_id"] + args["invoice_id"] + secret;
                String CheckHash  = TwocheckoutUtil.Md5Hash(HashString);
                if (CheckHash != args["md5_hash"])
                {
                    Result.response_code    = "Fail";
                    Result.response_message = "Hash Mismatch";
                }
                else
                {
                    Result.response_code    = "Success";
                    Result.response_message = "Hash Matched";
                }
            }
            else
            {
                Result.response_code    = "Notice";
                Result.response_message = "You must pass a sale_id, vendor_id, invoice_id, md5_hash and secret word.";
            }
            return(Result);
        }