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); }