Inheritance: IRestAPIType
Esempio n. 1
0
        public static long CreateCustomer(Order order)
        {
            //check if customer already exist
            var customerOld = CustomerDAL.FindCustomer(ConfigurationHelper.ConnectionString, cus => cus.billing_address == order.ShippingAddress.AddressLine1 && cus.billing_zip == order.ShippingAddress.PostalCode);

            if (customerOld != null)
            {
                return(customerOld.customer_id);
            }
            var nameSplit = order.ShippingAddress.Name.Split(' ');
            var customer  = new ACG.Customer
            {
                Email            = order.BuyerEmail,
                Password         = "******" + Guid.NewGuid().ToString("d").Substring(1, 8),
                BillingCompany   = "",
                BillingFirstName = nameSplit[0],
                BillingLastName  = string.Join(" ", nameSplit.Except(new[] { nameSplit[0] })),
                BillingAddress1  = order.ShippingAddress.AddressLine1,
                BillingAddress2  = (order.ShippingAddress.IsSetAddressLine2()
                ? order.ShippingAddress.AddressLine2
                : "") + (order.ShippingAddress.IsSetAddressLine3() ? order.ShippingAddress.AddressLine3 : ""),
                BillingCity        = order.ShippingAddress.City,
                BillingState       = order.ShippingAddress.StateOrRegion,
                BillingZipCode     = order.ShippingAddress.PostalCode,
                BillingCountry     = order.ShippingAddress.CountryCode, // order.BuyerCounty
                BillingPhoneNumber = order.ShippingAddress.Phone,
                //BillingTaxID= order.BuyerTaxInfo.,todo: Sam to check
                //ShippingCompany= "Amazon",
                ShippingFirstName = nameSplit[0],
                ShippingLastName  = string.Join(" ", nameSplit.Except(new[] { nameSplit[0] })),
                ShippingAddress1  = order.ShippingAddress.AddressLine1,
                ShippingAddress2  = (order.ShippingAddress.IsSetAddressLine2()
                                      ? order.ShippingAddress.AddressLine2
                                      : "") + (order.ShippingAddress.IsSetAddressLine3() ? order.ShippingAddress.AddressLine3 : ""),
                ShippingCity        = order.ShippingAddress.City,
                ShippingState       = order.ShippingAddress.StateOrRegion.Trim(),
                ShippingZipCode     = order.ShippingAddress.PostalCode,
                ShippingCountry     = order.ShippingAddress.CountryCode.ToUpper(),
                ShippingPhoneNumber = order.ShippingAddress.Phone,
                //ShippingAddressType= 0,
                Enabled    = true,
                MailList   = false,
                NonTaxable = true,
                DisableBillingSameAsShipping = true,
                CustomerGroupID = 13,  // Amazon
                //Comments= "string",
                //AdditionalField1= "string",
                //AdditionalField2= "string",
                //AdditionalField3= "string",
                TotalStoreCredit = ""
            };

            // check for US States
            if ((customer.ShippingCountry == "US" || customer.ShippingCountry == "USA") && customer.ShippingState.Length > 2)
            {
                customer.ShippingState = OrderDAL.GetStateCodeForUS(customer.ShippingState);
            }
            if ((customer.BillingCountry == "US" || customer.BillingCountry == "USA") && customer.BillingState.Length > 2)
            {
                customer.BillingState = OrderDAL.GetStateCodeForUS(customer.BillingState);
            }

            var recordInfo = RestHelper.AddRecord(customer, "Customers", ConfigurationHelper.PrivateKey,
                                                  ConfigurationHelper.Token, ConfigurationHelper.Store);

            if (recordInfo.Status == ACG.ActionStatus.Failed)
            {
                MandrillMail.SendEmail(ConfigurationHelper.MandrilAPIKey, "Order Has to be processed manually. ",
                                       "Order Has to be processed manually. Could not create customer. The order no is:" + order.AmazonOrderId,
                                       "*****@*****.**");
                return(0);
            }
            var customerId = Convert.ToInt32(recordInfo.ResultSet);

            customer.CustomerID = customerId;
            CustomerDAL.AddCustomers(ConfigurationHelper.ConnectionString, new List <ACG.Customer>()
            {
                customer
            }, new List <ACG.CustomerGroup>());
            return(customerId);
        }
Esempio n. 2
0
        static async Task RunAsync()
        {
            try
            {
                string sHost = string.Empty;
                string sPrivateKey = string.Empty;
                string sToken = string.Empty;
                string sSecureURL = string.Empty;
                string sVersion = string.Empty;
                string sContentType = string.Empty;
                string sCustomerID = string.Empty;
                string sType= string.Empty;
                string sID = string.Empty;

                bool IsCustomerGroup = false;

                //using (var client = new HttpClient())
                //{



                sHost = "http://apirest.3dcart.com/3dCartWebAPI/v";
                sVersion = "1";
                sPrivateKey = "bc6c0b6ae8d1fa40314b65fec3047c8b";
                sToken = "f244f1d222b5a691db32ff537281121f";
                sSecureURL = "https://3dcart-nadeem-com.3dcartstores.com";
                sContentType = "application/json";

                sID = "";

                HttpClient client = GetClient(sHost, sVersion, sPrivateKey, sToken, sSecureURL, sContentType);

                //HttpClient3dCart cartClass = new HttpClient3dCart();

                //SiteCustomers custClass = new SiteCustomers();

                //custClass.HttpHost = sHost;
                //custClass.ServiceVersion = sVersion;
                //custClass.PrivateKey = sPrivateKey;
                //custClass.Token = sToken;
                //custClass.SecureURL = sSecureURL;
                //custClass.ContentType = sContentType;
                //custClass.Type = "Customers";

                //HttpClient client = custClass.GetClient();


                //client.BaseAddress = new Uri(sHost + sVersion +"/");
                //client.DefaultRequestHeaders.Accept.Clear();
                //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(sContentType));

                //client.DefaultRequestHeaders.Add("privatekey", sPrivateKey);
                //client.DefaultRequestHeaders.Add("token", sToken);
                //client.DefaultRequestHeaders.Add("secureUrl", sSecureURL);

                if (IsCustomerGroup)
                {
                    sType = "CustomerGroups";
                }
                else
                {
                    sType = "Customers";
                }



                //GET

                if (sID != string.Empty)
                {
                    sType += "/" + sID;
                }

                
                HttpResponseMessage response = await client.GetAsync(sType);

                
                    
                if (response.IsSuccessStatusCode)
                {

                    List<Customer> custList = new List<Customer>();


                    //Customer customer = await JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync());

                        
                    string receiveStream = await response.Content.ReadAsStringAsync();

                    List<Customer> customerList = (List<Customer>)JsonConvert.DeserializeObject(receiveStream, typeof(List<Customer>));

                    //Console.WriteLine("{0}\t", receiveStream);
                    //Console.ReadKey();

                }

                
                //POST
                Customer cust = new Customer() { Email = "*****@*****.**", Password="******", BillingFirstName = "Flower", BillingLastName = "Rose" };

                response = await client.PostAsJsonAsync(sType, cust);


                if (response.IsSuccessStatusCode)
                {
                    Console.WriteLine("Customer Added");
                    Console.ReadKey();

                }
                


                //PUT
                Customer cust1 = new Customer() { BillingFirstName = "Mannay", BillingLastName = "Pacqino", CustomerID=7 };
                //cust.BillingFirstName = "John";
                response = await client.PutAsJsonAsync(sType, cust1);

                if (response.IsSuccessStatusCode)
                {
                    Console.WriteLine("Customer Updated");
                    //Console.ReadKey();
                }


                //DELETE
                response = await client.DeleteAsync(sType);

                if (response.IsSuccessStatusCode)
                {
                    Console.WriteLine("Customer Deleted");
                    Console.ReadKey();
                }




                //}
            }
            catch (Exception ex)
            {
                throw ex;
            }


        }