예제 #1
0
        public bool PostOrder(int orderId)
        {
            bool result = false;
            Dictionary <string, AttributeValue> orderAttributes = new Dictionary <string, AttributeValue>();

            try
            {
                Order orderItem = new OrderManager().GetBatchProcessOrder(orderId);

                bool MainOrderPosted = false;

                // This is Duplicate Order Check with Innotrac CRM Production. If you want enable it please add below web services.
                // https://gateway.west.innotrac.com:8443/invoke/INOC_ATS_CRMS.SOA.WebSelfHelp.DM:wsdl
                //if (SearchByExternalOrderId(orderItem.OrderId, orderItem.OrderStatusId))
                //{
                //    // Order found in Innotrac CRM  WEBSelfHelp
                //    MainOrderPosted = true;
                //    result = true;
                //}
                // else
                if (IsMainOrderPosted(orderItem.OrderId))
                {
                    // Order was posted by Conversion Systems to Innotrac successfully previously
                    MainOrderPosted = true;
                    result          = true;
                }
                if (MainOrderPosted == false)
                {
                    InnotracWS.InocOrdersSoapClient RequestOrder = new InnotracWS.InocOrdersSoapClient();
                    //RequestOrder.Timeout = 30000; // Time outs of 30 seconds should be implemented for every web service call.
                    PostOrderBatchRequest PostOrderBatchRequest1 = GetRequest(orderItem);
                    XmlSerializer         serializer             = new XmlSerializer(typeof(PostOrderBatchRequest));
                    StringWriter          writer = new StringWriter();
                    serializer.Serialize(writer, PostOrderBatchRequest1);
                    writer.Close();
                    string req = writer.ToString();

                    PostOrderBatchResponse PostOrderBatchResponse1 = RequestOrder.PostOrderBatch(PostOrderBatchRequest1);


                    string        res         = "";
                    XmlSerializer serializer2 = new XmlSerializer(typeof(PostOrderBatchResponse));
                    StringWriter  writer2     = new StringWriter();
                    serializer2.Serialize(writer2, PostOrderBatchResponse1);
                    writer2.Close();
                    res = writer2.ToString();
                    // orderAttributes.Add("Request", new CSBusiness.Attributes.AttributeValue(req));
                    orderAttributes.Add("Response", new CSBusiness.Attributes.AttributeValue(res));
                    if (PostOrderBatchResponse1.Orders[0].OrderStatus[0].Code == 0 || PostOrderBatchResponse1.Orders[0].OrderStatus[0].Code >= 100)
                    {
                        //InnotracDAL.InsertInnoTracLog(orderId, 2);
                        CSResolve.Resolve <IOrderService>().UpdateOrderAttributes(orderId, orderAttributes, 2);
                        result = true;
                    }
                    else
                    {
                        //InnotracDAL.InsertInnoTracLog(orderId, 8);
                        CSResolve.Resolve <IOrderService>().UpdateOrderAttributes(orderId, orderAttributes, 5);
                        result = false;
                        OrderHelper.SendOrderFailedEmail(orderId, "main", "");
                    }
                }

                // Below code is for Posting Orders with Continuity Products.
                //if (result == true)
                //{
                //    if (GetContinuityFlag(orderItem) == "Y")
                //        PostOrderContinuity(orderItem);
                //}
            }
            catch (Exception ex)
            {
                //InnotracDAL.InsertInnoTracLog(orderId, 8);
                string errormessage = ex.Message + " StackTrace:: " + ex.StackTrace;
                CSResolve.Resolve <IOrderService>().UpdateOrderStatus(orderId, 5);
                result = false;
                OrderHelper.SendOrderFailedEmail(orderId, "custom", errormessage);
            }
            return(result);
        }
예제 #2
0
        public PostOrderBatchRequest GetRequest(Order orderItem)
        {
            String strXml = String.Empty;

            orderItem.LoadAttributeValues();

            string ShippingStateProvinceAbbreviation = "";
            string BillingStateProvinceAbbreviation  = "";
            List <StateProvince> states = StateManager.GetAllStates(0);
            StateProvince        itemShippingStateProvince = states.FirstOrDefault(x => x.StateProvinceId == Convert.ToInt32(orderItem.CustomerInfo.ShippingAddress.StateProvinceId));

            if (itemShippingStateProvince != null)
            {
                ShippingStateProvinceAbbreviation = itemShippingStateProvince.Abbreviation.Trim();
            }
            StateProvince itemBillingStateProvince = states.FirstOrDefault(x => x.StateProvinceId == Convert.ToInt32(orderItem.CustomerInfo.BillingAddress.StateProvinceId));

            if (itemBillingStateProvince != null)
            {
                BillingStateProvinceAbbreviation = itemBillingStateProvince.Abbreviation.Trim();
            }

            Sku ShippingSku = GetShippingSku(orderItem);
            //string ShipCodeService = GetShippingSku(orderItem).SkuCode;

            PostOrderBatchRequest PostOrderBatchRequest1 = new PostOrderBatchRequest();

            InnotracWS.WSAuthorization WSAuthorization1 = new InnotracWS.WSAuthorization();
            WSAuthorization1.Username = config.Attributes["Username"].Value;
            WSAuthorization1.Password = config.Attributes["Password"].Value;
            PostOrderBatchRequest1.WSAuthorization = WSAuthorization1;

            int TransmissionBatchID = 0; // GetTransmissionBatchID();

            PostOrderBatchRequestOrderBatch OrderBatch1 = new PostOrderBatchRequestOrderBatch();

            OrderBatch1.TransmissionBatchID = Convert.ToDouble(TransmissionBatchID);
            OrderBatch1.TransmissionSource  = config.Attributes["TransmissionSource"].Value;
            OrderBatch1.TransmissionDate    = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd H:mm:ss"));
            OrderBatch1.Telemarketer        = config.Attributes["Telemarketer"].Value;
            OrderBatch1.RerunCount          = Convert.ToInt32(config.Attributes["RerunCount"].Value);
            OrderBatch1.NumberOfOrders      = Convert.ToInt32(config.Attributes["NumberOfOrders"].Value);
            OrderBatch1.CustomerInfoOnly    = config.Attributes["CustomerInfoOnly"].Value;

            PostOrderBatchRequestOrderBatchCustomer Customer = new PostOrderBatchRequestOrderBatchCustomer();

            Customer.SerialID                = config.Attributes["SerialID"].Value;
            Customer.Project                 = Convert.ToInt32(config.Attributes["Project"].Value);
            Customer.CustomerNo              = Convert.ToInt32(config.Attributes["CustomerNo"].Value);
            Customer.CustomerNoSpecified     = true;
            Customer.ClientCustomer          = Convert.ToInt32(config.Attributes["ClientCustomer"].Value);
            Customer.ClientCustomerSpecified = true;
            Customer.FirstName               = orderItem.CustomerInfo.BillingAddress.FirstName;
            Customer.LastName                = orderItem.CustomerInfo.BillingAddress.LastName;
            Customer.Address1                = orderItem.CustomerInfo.BillingAddress.Address1;
            Customer.Address2                = orderItem.CustomerInfo.BillingAddress.Address2;
            Customer.City = orderItem.CustomerInfo.BillingAddress.City;

            Customer.State = BillingStateProvinceAbbreviation; //  orderItem.CustomerInfo.BillingAddress.StateProvinceName;
            Customer.Zip   = orderItem.CustomerInfo.BillingAddress.ZipPostalCode;
            if (orderItem.CustomerInfo.BillingAddress.CountryId == 46)
            {
                Customer.Country = "CN";
            }
            else
            {
                Customer.Country = CountryManager.CountryCode(orderItem.CustomerInfo.BillingAddress.CountryId).Trim();
            }
            Customer.DayPhoneSpecified = true;
            Customer.DayPhone          = Convert.ToDouble(OrderHelper.GetCleanPhoneNumber(orderItem.CustomerInfo.BillingAddress.PhoneNumber));

            PostOrderBatchRequestOrderBatchCustomerEmail CustomerEmail = new PostOrderBatchRequestOrderBatchCustomerEmail();

            CustomerEmail.EmailAddress = orderItem.Email;
            CustomerEmail.EmailFlag    = config.Attributes["EmailFlag"].Value;
            Customer.Email             = new PostOrderBatchRequestOrderBatchCustomerEmail[1];
            Customer.Email[0]          = CustomerEmail;

            Customer.CustomerMailFlag = config.Attributes["CustomerMailFlag"].Value;
            Customer.RentNameFlag     = config.Attributes["RentNameFlag"].Value;
            Customer.OrderEmailsFlag  = config.Attributes["OrderEmailsFlag"].Value;
            string MarketingEmailsFlag = "N";

            //if (orderItem.AttributeValues.ContainsAttribute("sendoffers") && orderItem.AttributeValues["sendoffers"].Value != null)
            //{
            //    if (orderItem.AttributeValues["sendoffers"].Value.Equals("1"))
            //    {
            //        MarketingEmailsFlag = "Y";
            //    }
            //    else
            //    {
            //        MarketingEmailsFlag = "N";
            //    }
            //}
            Customer.MarketingEmailsFlag = MarketingEmailsFlag.ToUpper();
            Customer.Language            = config.Attributes["Language"].Value;

            PostOrderBatchRequestOrderBatchCustomerOrder CustomerOrder = new PostOrderBatchRequestOrderBatchCustomerOrder();

            CustomerOrder.ServiceBeforeShip = config.Attributes["ServiceBeforeShip"].Value;
            CustomerOrder.OrderNo           = Convert.ToInt32(config.Attributes["OrderNo"].Value);
            CustomerOrder.OrderNoSpecified  = true;
            CustomerOrder.PurchaseOrder     = config.Attributes["OrderIdPrefix"].Value + orderItem.OrderId.ToString();
            CustomerOrder.Promotion         = config.Attributes["Promotion"].Value;


            string Media = config.Attributes["MediaCode"].Value;

            //if (orderItem.AttributeValues.ContainsAttribute("mediacode") && orderItem.AttributeValues["mediacode"].Value != null && !orderItem.AttributeValues["mediacode"].Value.Equals(""))
            //{
            //    Media = orderItem.AttributeValues["mediacode"].Value;
            //}
            CustomerOrder.Media = Media;
            //CustomerOrder.BackEndCode = config.Attributes["BackEndCode"].Value;
            CustomerOrder.BaseContinuityOrderFlag = GetContinuityFlag(orderItem);                               // config.Attributes["BaseContinuityOrderFlag"].Value;
            CustomerOrder.OrderCategory           = config.Attributes["OrderCategory"].Value;
            CustomerOrder.OrderDate = Convert.ToDateTime(orderItem.CreatedDate.ToString("yyyy-MM-dd H:mm:ss")); // .ToString("MM/dd/yy hh:mm:ss"));
            // These should instead have a T separating date from time, like this: <inoc:OrderDate>2014-05-13T19:24:02</inoc:OrderDate>
            CustomerOrder.OrderReferenceNo1         = config.Attributes["OrderIdPrefix"].Value + orderItem.OrderId.ToString();
            CustomerOrder.UserId                    = config.Attributes["UserId"].Value;
            CustomerOrder.ShipFeeService            = ShippingSku.SkuCode; // ShipFeeService; //  GetShipFeeService(orderItem);
            CustomerOrder.ShipCodeService           = ShippingSku.SkuCode; // ShipCodeService; // GetShipCodeService(orderItem);
            CustomerOrder.ResidentialCommercialFlag = config.Attributes["ResidentialCommercialFlag"].Value;
            CustomerOrder.PricingCalculationMethod  = config.Attributes["PricingCalculationMethod"].Value;
            CustomerOrder.ShippingCalculationMethod = config.Attributes["ShippingCalculationMethod"].Value;
            CustomerOrder.PaymentPlan               = GetPaymentPlan(orderItem);
            CustomerOrder.Language                  = config.Attributes["Language"].Value;

            PostOrderBatchRequestOrderBatchCustomerOrderOrderShipTo OrderOrderShipTo = new PostOrderBatchRequestOrderBatchCustomerOrderOrderShipTo();

            OrderOrderShipTo.ShipToFirstName = orderItem.CustomerInfo.ShippingAddress.FirstName;
            OrderOrderShipTo.ShipToLastName  = orderItem.CustomerInfo.ShippingAddress.LastName;
            OrderOrderShipTo.ShipToAddress1  = orderItem.CustomerInfo.ShippingAddress.Address1;
            OrderOrderShipTo.ShipToAddress2  = orderItem.CustomerInfo.ShippingAddress.Address2;
            OrderOrderShipTo.ShipToCity      = orderItem.CustomerInfo.ShippingAddress.City;
            OrderOrderShipTo.ShipToState     = ShippingStateProvinceAbbreviation; // orderItem.CustomerInfo.ShippingAddress.StateProvinceName;
            OrderOrderShipTo.ShipToZip       = orderItem.CustomerInfo.ShippingAddress.ZipPostalCode;
            if (orderItem.CustomerInfo.ShippingAddress.CountryId == 46)
            {
                OrderOrderShipTo.ShipToCountry = "CN";
            }
            else
            {
                OrderOrderShipTo.ShipToCountry = CountryManager.CountryCode(orderItem.CustomerInfo.ShippingAddress.CountryId).Trim();
            }
            OrderOrderShipTo.ShipFeeService  = ShippingSku.SkuCode; // GetShipFeeService(orderItem);
            OrderOrderShipTo.ShipCodeService = ShippingSku.SkuCode; // GetShipCodeService(orderItem);

            OrderOrderShipTo.OrderItems = new PostOrderBatchRequestOrderBatchCustomerOrderOrderShipToOrderItems[orderItem.SkuItems.Count];
            PostOrderBatchRequestOrderBatchCustomerOrderOrderShipToOrderItems OrderShipToOrderItems;
            int        LineNo       = 1;
            int        arrayCounter = 0;
            decimal    ItemPrice    = 0;
            SkuManager skuManager   = new SkuManager();
            List <Sku> SkuItems1    = new List <Sku>();

            foreach (Sku Item in orderItem.SkuItems)
            {
                // Add BASE SKU for Sending to Innotrac
                //if (skuManager.GetSkuByID(Item.SkuId).CategoryId == 1)
                //{
                SkuItems1.Add(Item);
                //}
            }
            // Add FREEGIFT at LAST for SEnding to Innotrac
            //foreach (Sku Item in orderItem.SkuItems)
            //{
            //    // FREEGIFT CategoryId 16
            //    if (skuManager.GetSkuByID(Item.SkuId).CategoryId == 16)
            //    {
            //        SkuItems1.Add(Item);
            //    }
            //}
            foreach (Sku Item in SkuItems1)
            {
                //if (skuManager.GetSkuByID(Item.SkuId).CategoryId == 1)
                //{
                //ItemPricing ItemPricing1 = ItemPricingBySkuID[Item.SkuId];
                OrderShipToOrderItems     = new PostOrderBatchRequestOrderBatchCustomerOrderOrderShipToOrderItems();
                OrderShipToOrderItems.SKU = Item.SkuCode;
                //if (orderItem.CustomerInfo.ShippingAddress.CountryId == 46)
                //{
                //    Item.LoadAttributeValues();
                //    if (Item.GetAttributeValue<string>("skucode_canada", string.Empty) != string.Empty)
                //    {
                //        OrderShipToOrderItems.SKU = Item.GetAttributeValue<string>("skucode_canada", string.Empty);
                //    }
                //}
                OrderShipToOrderItems.Quantity            = Item.Quantity;
                OrderShipToOrderItems.LineNumber          = LineNo;
                OrderShipToOrderItems.LineNumberSpecified = true;

                PostOrderBatchRequestOrderBatchCustomerOrderOrderShipToOrderItemsItemPricing OrderItemsItemPricing = new PostOrderBatchRequestOrderBatchCustomerOrderOrderShipToOrderItemsItemPricing();
                ItemPrice = 0;
                ItemPrice = Item.FullPrice * Item.Quantity;
                //Pass P for PricingCalculationMethod (M). you need to remove the ItemPricing section, since we will be calculating each of the prices for you, at the line level.
                //OrderItemsItemPricing.ExtendedPrice = Convert.ToDecimal(ItemPrice.ToString("N2"));
                //OrderItemsItemPricing.ExtendedPriceSpecified = true;
                //OrderItemsItemPricing.ExtendedShipFee =(decimal)0;//ItemPricing1.SKU_Shipping_Price.ToString("N2"));
                //OrderItemsItemPricing.ExtendedShipFeeSpecified = true;
                //OrderItemsItemPricing.ExtendedTax = GetSkuTaxCost(orderItem.CustomerInfo.ShippingAddress, Item);// ItemPricing1.SKU_Total_Tax.ToString("N2"));
                //OrderItemsItemPricing.ExtendedTaxSpecified = true;
                OrderShipToOrderItems.ItemPricing         = OrderItemsItemPricing;
                OrderOrderShipTo.OrderItems[arrayCounter] = OrderShipToOrderItems;
                LineNo++;
                arrayCounter++;
                // }
            }

            // IF order contains more than one unique SKU -AND- is trying to do an install payment, flag as 'Y'
            //string InstallPaymentPlanCode = config.Attributes["InstallPaymentPlanCode"].Value.ToUpper();
            //if (LineNo > 2 && CustomerOrder.PaymentPlan.ToUpper().Equals(InstallPaymentPlanCode))
            //{
            //    CustomerOrder.ServiceBeforeShip = "Y";
            //}
            //else
            //{
            CustomerOrder.ServiceBeforeShip = config.Attributes["ServiceBeforeShip"].Value;
            //}

            CustomerOrder.OrderShipTo    = new PostOrderBatchRequestOrderBatchCustomerOrderOrderShipTo[1];
            CustomerOrder.OrderShipTo[0] = OrderOrderShipTo;

            PostOrderBatchRequestOrderBatchCustomerOrderPayment           OrderPayment      = new PostOrderBatchRequestOrderBatchCustomerOrderPayment();
            PostOrderBatchRequestOrderBatchCustomerOrderPaymentCreditCard PaymentCreditCard = new PostOrderBatchRequestOrderBatchCustomerOrderPaymentCreditCard();

            PaymentCreditCard.SequenceNo       = Convert.ToInt32(config.Attributes["SequenceNo"].Value);
            PaymentCreditCard.CreditCardNumber = orderItem.CreditInfo.CreditCardNumber;
            PaymentCreditCard.ExpirationDate   = orderItem.CreditInfo.CreditCardExpired.ToString("MMyy");
            if ((orderItem.CustomerInfo.BillingAddress.Address1.Equals(orderItem.CustomerInfo.ShippingAddress.Address1)) && (orderItem.CustomerInfo.BillingAddress.City.Equals(orderItem.CustomerInfo.ShippingAddress.City)) &&
                (orderItem.CustomerInfo.BillingAddress.ZipPostalCode.Equals(orderItem.CustomerInfo.ShippingAddress.ZipPostalCode)))
            {
                PaymentCreditCard.CardHolderFlag = CardHolderFlag.S; // If Bill To Address = Ship To Address, then S - Otherwise M
            }
            else
            {
                PaymentCreditCard.CardHolderFlag = CardHolderFlag.M; // If Bill To Address = Ship To Address, then S - Otherwise M
            }
            PaymentCreditCard.CVV2Code = "";

            PostOrderBatchRequestOrderBatchCustomerOrderPaymentCreditCardBillingAddress CreditCardBillingAddress = new PostOrderBatchRequestOrderBatchCustomerOrderPaymentCreditCardBillingAddress();

            CreditCardBillingAddress.BillingFirstName = orderItem.CustomerInfo.BillingAddress.FirstName;
            CreditCardBillingAddress.BillingLastName  = orderItem.CustomerInfo.BillingAddress.LastName;
            CreditCardBillingAddress.BillingAddress1  = orderItem.CustomerInfo.BillingAddress.Address1;
            CreditCardBillingAddress.BillingAddress2  = orderItem.CustomerInfo.BillingAddress.Address2;
            CreditCardBillingAddress.BillingCity      = orderItem.CustomerInfo.BillingAddress.City;
            CreditCardBillingAddress.BillingState     = BillingStateProvinceAbbreviation; // orderItem.CustomerInfo.BillingAddress.StateProvinceName;
            CreditCardBillingAddress.BillingZip       = orderItem.CustomerInfo.BillingAddress.ZipPostalCode;
            if (orderItem.CustomerInfo.BillingAddress.CountryId == 46)
            {
                CreditCardBillingAddress.BillingCountry = "CN";
            }
            else
            {
                CreditCardBillingAddress.BillingCountry = orderItem.CustomerInfo.BillingAddress.CountryCode.Trim();
            }
            PaymentCreditCard.BillingAddress = CreditCardBillingAddress;
            OrderPayment.CreditCard          = new PostOrderBatchRequestOrderBatchCustomerOrderPaymentCreditCard[1];
            OrderPayment.CreditCard[0]       = PaymentCreditCard;
            OrderPayment.CurrencyCode        = config.Attributes["CurrencyCode"].Value;
            CustomerOrder.Payment            = OrderPayment;

            PostOrderBatchRequestOrderBatchCustomerOrderOrderSourceTotals OrderOrderSourceTotals = new PostOrderBatchRequestOrderBatchCustomerOrderOrderSourceTotals();
            decimal SubTotalFullPrice_ContinuityProducts = 0;                                                                                                      // GetFullPriceSubTotal_ContinuitySKU(orderItem);

            OrderOrderSourceTotals.ProductTotal = Convert.ToDecimal(String.Format("{0:.00}", orderItem.FullPriceSubTotal - SubTotalFullPrice_ContinuityProducts)); // SubTotal)); // FullPriceSubTotal));
            if (orderItem.CustomerInfo.ShippingAddress.CountryId == 46)
            {
                // setup the tax as a flat 10% for Canadian orders
                // it would be best if you sent the 10 percent charge as S&H as that is the way we display it in our CRM and the customer pack slip.
                OrderOrderSourceTotals.TaxTotal     = Convert.ToDecimal(String.Format("{0:.00}", "0.00"));
                OrderOrderSourceTotals.ShipFeeTotal = orderItem.ShippingCost + orderItem.AdditionalShippingCharge + orderItem.FullPriceTax;
            }
            else
            {
                OrderOrderSourceTotals.TaxTotal     = Convert.ToDecimal(String.Format("{0:.00}", orderItem.FullPriceTax));
                OrderOrderSourceTotals.ShipFeeTotal = orderItem.ShippingCost + orderItem.AdditionalShippingCharge;  // ShippingSku.FullPrice + orderItem.AdditionalShippingCharge;// Convert.ToDecimal(String.Format("{0:.00}", orderItem.ShippingCost));
            }
            OrderOrderSourceTotals.GiftCertificateTotalSpecified = true;
            OrderOrderSourceTotals.GiftCertificateTotal          = 0;
            CustomerOrder.OrderSourceTotals = OrderOrderSourceTotals;
            CustomerOrder.ShipCompleteFlag  = "";
            Customer.Order                    = new PostOrderBatchRequestOrderBatchCustomerOrder[1];
            Customer.Order[0]                 = CustomerOrder;
            OrderBatch1.Customer              = new PostOrderBatchRequestOrderBatchCustomer[1];
            OrderBatch1.Customer[0]           = Customer;
            PostOrderBatchRequest1.OrderBatch = OrderBatch1;
            return(PostOrderBatchRequest1); // strXml;
        }