Exemple #1
0
        public Boolean Check(ReturnCheckServiceOptions options)
        {
            Boolean Result;
            var     HashString = new StringBuilder();

            HashString.Append(TwoCheckoutConfig.SecretWord);
            HashString.Append(TwoCheckoutConfig.SellerID);
            if (TwoCheckoutConfig.Demo)
            {
                HashString.Append("1");
            }
            else
            {
                HashString.Append(options.order_number);
            }
            HashString.Append(options.total);
            string CheckHash = TwoCheckoutUtil.Md5Hash(HashString.ToString());

            if (CheckHash != options.key)
            {
                Result = false;
            }
            else
            {
                Result = true;
            }
            return(Result);
        }
        public Option Retrieve(OptionRetrieveServiceOptions options)
        {
            String  Result       = TwoCheckoutUtil.Request("api/products/detail_option", "GET", "admin", options);
            Options OptionResult = TwoCheckoutUtil.MapToObject <Options>(Result);

            return(OptionResult.option[0]);
        }
        public Authorization Authorize(ChargeAuthorizeServiceOptions options)
        {
            options.privateKey = TwoCheckoutConfig.PrivateKey;
            options.sellerId   = TwoCheckoutConfig.SellerID;
            string Result = TwoCheckoutUtil.Request("checkout/api/1/" + TwoCheckoutConfig.SellerID + "/rs/authService", "POST", "payment", options);

            return(TwoCheckoutUtil.MapToObject <Authorization>(Result, "response"));
        }
        public static string Link(Dictionary <string, string> args)
        {
            StringBuilder Link       = new StringBuilder(CheckoutUrl);
            string        Parameters = TwoCheckoutUtil.DictionaryToQueryString(args);

            Link.Append("?");
            Link.Append(Parameters);
            return(Link.ToString());
        }
Exemple #5
0
 public TwoCheckoutResponse Refund(SaleRefundServiceOptions options)
 {
     String Result = null;
     if (options.lineitem_id != null)
     {
         Result = TwoCheckoutUtil.Request("api/sales/refund_lineitem", "POST", "admin", options);
     }
     else
     {
         Result = TwoCheckoutUtil.Request("api/sales/refund_invoice", "POST", "admin", options);
     }
     return TwoCheckoutUtil.MapToObject<TwoCheckoutResponse>(Result);
 }
        public Boolean Check(NotificationCheckServiceOptions options)
        {
            Boolean Result;
            var     HashString = new StringBuilder();

            HashString.Append(options.sale_id);
            HashString.Append(TwoCheckoutConfig.SellerID);
            HashString.Append(options.invoice_id);
            HashString.Append(TwoCheckoutConfig.SecretWord);
            string CheckHash = TwoCheckoutUtil.Md5Hash(HashString.ToString());

            if (CheckHash != options.md5_hash)
            {
                Result = false;
            }
            else
            {
                Result = true;
            }
            return(Result);
        }
        public static string StopActiveLineitems(Dictionary <string, string> active)
        {
            string stoppedLineitems        = null;
            SaleStopServiceOptions options = new SaleStopServiceOptions();

            foreach (var entry in active)
            {
                options.lineitem_id = Convert.ToInt64(entry.Value);
                try
                {
                    TwoCheckoutUtil.Request("api/sales/stop_lineitem_recurring", "POST", "admin", options);
                    stoppedLineitems += "," + entry.Value; //log the stopped lineitem in response mesage
                }
                catch (TwoCheckoutException)
                {
                    return("{ 'response_code': 'NOTICE', 'response_message': 'Linetiem " + entry.Value + " could not be stopped.' }");
                }
            }
            stoppedLineitems = stoppedLineitems.Remove(0, 1); //drop the leading comma
            return("{ 'response_code': 'OK', 'response_message': '" + stoppedLineitems + "' }");
        }
Exemple #8
0
 public TwoCheckoutResponse Stop(SaleStopServiceOptions options)
 {
     String Result = null;
     if (options.sale_id != null)
     {
         Result = TwoCheckoutUtil.Request("api/sales/detail_sale", "GET", "admin", options);
         Dictionary<string, string> Active = TwoCheckoutUtil.Active(Result);
         if (Active.ContainsKey("lineitem_id0"))
         {
             Result = TwoCheckoutUtil.StopActiveLineitems(Active);
         }
         else
         {
             Result = "{ 'response_code': 'NOTICE', 'response_message': " + "'No active recurring lineitems.'" + " }";
         }
     }
     else
     {
         Result = TwoCheckoutUtil.Request("api/sales/stop_lineitem_recurring", "POST", "admin", options);
     }
     return TwoCheckoutUtil.MapToObject<TwoCheckoutResponse>(Result);
 }
        public Payment PendingPayment()
        {
            string Result = TwoCheckoutUtil.Request("api/acct/detail_pending_payment", "GET", "admin");

            return(TwoCheckoutUtil.MapToObject <Payment>(Result, "payment"));
        }
Exemple #10
0
        public CouponList List()
        {
            String Result = TwoCheckoutUtil.Request("api/products/list_coupons", "GET", "admin");

            return(TwoCheckoutUtil.MapToObject <CouponList>(Result));
        }
        public static string Request(string urlSuffix, string method, string type, Object args = null)
        {
            HttpWebRequest    Request;
            string            Url         = string.Concat(TwoCheckoutConfig.BaseUrl, urlSuffix);
            string            Params      = null;
            string            Result      = null;
            string            ContentType = null;
            HttpWebResponse   Response    = null;
            NetworkCredential Credential  = null;

            if (type == "admin")
            {
                ContentType = (method == "POST") ? "application/x-www-form-urlencoded" : "*/*";
                Params      = (args != null) ? TwoCheckoutUtil.SerializeObjectToQueryString(args) : null;
                Url         = (method == "GET") ? string.Concat(Url, "?", Params) : Url;
                Credential  = new NetworkCredential(TwoCheckoutConfig.ApiUsername, TwoCheckoutConfig.ApiPassword);
            }
            else
            {
                ContentType = "application/json";
                Params      = TwoCheckoutUtil.ConvertToJson(args);
            }

            try
            {
                Request = WebRequest.Create(Url.ToString()) as HttpWebRequest;
                ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); };
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
                Request.Credentials = Credential;
                Request.Method      = method;
                Request.ContentType = ContentType;
                Request.Accept      = "application/json";
                Request.UserAgent   = "2Checkout .NET/" + TwoCheckoutConfig.Version;
                if (method == "POST" && Params != "")
                {
                    byte[] byteData = UTF8Encoding.UTF8.GetBytes(Params);
                    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();
                    return(Result);
                }
            }
            catch (WebException wex)
            {
                string ResultCode = null;
                if (wex.Response != null)
                {
                    using (HttpWebResponse errorResponse = (HttpWebResponse)wex.Response)
                    {
                        StreamReader reader = new StreamReader(errorResponse.GetResponseStream());
                        Result = reader.ReadToEnd();
                        JObject RawError = JObject.Parse(Result);
                        if (RawError["errors"] != null)
                        {
                            Result     = RawError["errors"][0]["message"].ToString();
                            ResultCode = RawError["errors"][0]["code"].ToString();
                        }
                        else if (RawError["exception"] != null)
                        {
                            Result     = RawError["exception"]["errorMsg"].ToString();
                            ResultCode = RawError["exception"]["errorCode"].ToString();
                        }
                    }
                }
                else
                {
                    Result     = wex.Message;
                    ResultCode = "500";
                }
                throw new TwoCheckoutException(Result)
                      {
                          Code = ResultCode
                      };
            }
            finally
            {
                if (Response != null)
                {
                    Response.Close();
                }
            }
        }
        public List <Payment> ListPayments()
        {
            string Result = TwoCheckoutUtil.Request("api/acct/list_payments", "GET", "admin");

            return(TwoCheckoutUtil.MapToObject <List <Payment> >(Result, "payments"));
        }
Exemple #13
0
        public Sale Retrieve(SaleRetrieveServiceOptions options)
        {
            string Result = TwoCheckoutUtil.Request("api/sales/detail_sale", "GET", "admin", options);

            return(TwoCheckoutUtil.MapToObject <Sale>(Result, "sale"));
        }
        public Company CompanyInfo()
        {
            string Result = TwoCheckoutUtil.Request("api/acct/detail_company_info", "GET", "admin");

            return(TwoCheckoutUtil.MapToObject <Company>(Result, "vendor_company_info"));
        }
Exemple #15
0
        public TwoCheckoutResponse Comment(SaleCommentServiceOptions options)
        {
            string Result = TwoCheckoutUtil.Request("api/sales/create_comment", "POST", "admin", options);

            return(TwoCheckoutUtil.MapToObject <TwoCheckoutResponse>(Result));
        }
Exemple #16
0
        public TwoCheckoutResponse Ship(SaleShipServiceOptions options)
        {
            string Result = TwoCheckoutUtil.Request("api/sales/mark_shipped", "POST", "admin", options);

            return(TwoCheckoutUtil.MapToObject <TwoCheckoutResponse>(Result));
        }
Exemple #17
0
        public TwoCheckoutResponse Update(ProductUpdateServiceOptions options = null)
        {
            string Result = TwoCheckoutUtil.Request("api/products/update_product", "POST", "admin", options);

            return(TwoCheckoutUtil.MapToObject <TwoCheckoutResponse>(Result));
        }
Exemple #18
0
        public SaleList List(SaleListServiceOptions options = null)
        {
            string Result = TwoCheckoutUtil.Request("api/sales/list_sales", "GET", "admin", options);

            return(TwoCheckoutUtil.MapToObject <SaleList>(Result));
        }
Exemple #19
0
        public TwoCheckoutResponse Reauth(SaleReauthServiceOptions options)
        {
            String Result = TwoCheckoutUtil.Request("api/sales/reauth", "POST", "admin", options);

            return(TwoCheckoutUtil.MapToObject <TwoCheckoutResponse>(Result));
        }
Exemple #20
0
        public TwoCheckoutResponse Delete(CouponDeleteServiceOptions options = null)
        {
            String Result = TwoCheckoutUtil.Request("api/products/delete_coupon", "POST", "admin", options);

            return(TwoCheckoutUtil.MapToObject <TwoCheckoutResponse>(Result));
        }
Exemple #21
0
        public Product Retrieve(ProductRetrieveServiceOptions options)
        {
            string Result = TwoCheckoutUtil.Request("api/products/detail_product", "GET", "admin", options);

            return(TwoCheckoutUtil.MapToObject <Product>(Result, "product"));
        }
        public TwoCheckoutResponse Create(OptionCreateServiceOptions options)
        {
            String Result = TwoCheckoutUtil.Request("api/products/create_option", "POST", "admin", options);

            return(TwoCheckoutUtil.MapToObject <TwoCheckoutResponse>(Result));
        }
        public OptionList List(OptionListServiceOptions options = null)
        {
            String Result = TwoCheckoutUtil.Request("api/products/list_options", "GET", "admin", options);

            return(TwoCheckoutUtil.MapToObject <OptionList>(Result));
        }
Exemple #24
0
        public Coupon Retrieve(CouponRetrieveServiceOptions options)
        {
            String Result = TwoCheckoutUtil.Request("api/products/detail_coupon", "GET", "admin", options);

            return(TwoCheckoutUtil.MapToObject <Coupon>(Result, "coupon"));
        }
Exemple #25
0
        public Contact ContactInfo()
        {
            String Result = TwoCheckoutUtil.Request("api/acct/detail_contact_info", "GET", "admin");

            return(TwoCheckoutUtil.MapToObject <Contact>(Result, "vendor_contact_info"));
        }