示例#1
0
        public order GetOrderObjectRequestByExternalRef(long external_ref, string status_description)
        {
            order o = new order();
            using (var dc = new stylusDataContext())
            {
                List<item> itm = new List<item>();
                List<tracking> trk = new List<tracking>();
                ISingleResult<sp_get_order_by_external_refResult> res = dc.sp_get_order_by_external_ref(external_ref);
                foreach (sp_get_order_by_external_refResult ret in res)
                {

                    o.id = ret.order_external_ref;
                    o.status = status_description;

                    item i = new item();
                    i.id = ret.item_external_ref;
                    itm.Add(i);

                    o.item = itm;

                    tracking t = new tracking();
                    t.number = ret.tracking;
                    trk.Add(t);

                    o.tracking = trk;
                }
            }
            return o;
        }
        public oCreateOrderResponse PostOrder(oCreateOrderRequest order)
        {
            long iRefId = 0;
            string sref = String.Empty;
            bool bOrderInserted = false;
            bool bItemsInserted = false;
            long? iDentity = 0;

            //this is if the thumnail is too big(by using a HEAD command), default to this as it makes the PDF document too big
            string stemp_thumb = "https://yourdomain.com/RedBubble/images/na.gif";

            //get custom http header code from config file
            var config = ConfigurationManager.GetSection("applicationSettings/redbubble.Properties.Settings");
            var xAuthToken = ((ClientSettingsSection)config).Settings.Get("XAuthToken").Value.ValueXml.InnerText;

            //get remote information
            IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
            var headers = request.Headers["X-Auth-Token"];
            OperationContext context = OperationContext.Current;
            MessageProperties prop = context.IncomingMessageProperties;
            RemoteEndpointMessageProperty endpoint = prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

            string ip = endpoint.Address.ToString();

                if (xAuthToken != headers)
                {
                    sref = "Auth Failed";
                    LogError(order.external_ref, "AuthFailed", sref, order,ip);
                    throw new System.ServiceModel.Web.WebFaultException(HttpStatusCode.Unauthorized);
                }
                    using (var dc = new redbubbleDataContext())
                    {
                        try
                        {
                            List<items> line_items = order.items;
                            int? iLineItemsCount = line_items.Count; //database might want this for easier count of items so a join is not needed
                            DateTime dtSaleDate;
                            dtSaleDate = Convert.ToDateTime(order.sale_datetime);
                            bool berror = false;

                            #region validate_all_fields
                            if (order.external_ref == 0  || order.external_ref == null)
                            {
                                sref = "missing purchase order external_ref order number";
                                berror = true;
                                LogError(order.external_ref, "RedBubble endpoint", sref, order,ip);
                                throw new System.ServiceModel.Web.WebFaultException(HttpStatusCode.InternalServerError);
                            }
                            //check more order fields of course

                            foreach (items itmt in line_items)
                            {
                               if(itmt.external_ref == 0 || itmt.external_ref == null)
                               {
                                   sref = "missing order line external_ref item number";
                                   berror = true;
                                   LogError(order.external_ref, "RedBubble endpoint", sref, order,ip);
                                   throw new System.ServiceModel.Web.WebFaultException(HttpStatusCode.InternalServerError);
                               }
                               //check more items of course

                            }//end for items
                            #endregion

                            if (berror == false)
                            {
                                try
                                {
                                    ISingleResult<sp_insert_orders_oheadResult> res = dc.sp_insert_orders_ohead(order.external_ref, dtSaleDate, order.purchase_complete, order.company_ref_id, order.customer_name, order.shipping_address_1, order.shipping_address_2, order.shipping_address_3, order.shipping_address_4, order.shipping_postcode, order.shipping_country, order.shipping_country_code, order.shipping_method, order.phone, iLineItemsCount, ip,ref iDentity);
                                    iDentity = (long?)order.external_ref;
                                    bOrderInserted = true;
                                }
                                catch(Exception ex)
                                {
                                    berror = true;
                                    LogError(order.external_ref, "RedBubble endpoint", ex.Message.ToString(), order,ip);

                                }

                                //insert into orders_oline
                                try
                                {
                                    foreach (items itm in line_items)
                                    {
                                        dc.sp_insert_orders_oline(iDentity, itm.external_ref, itm.sku, itm.description, itm.quantity, itm.external_url, stemp_thumb, itm.artist_name, itm.title, itm.color, itm.size);
                                        bItemsInserted = true;
                                    }
                                }
                                catch(Exception ex2)
                                {
                                    berror = true;
                                    LogError(order.external_ref, "RedBubble endpoint", ex2.Message.ToString(),order,ip);
                                }

                                if(berror == true)
                                {
                                    try
                                    {
                                         if(bOrderInserted == true)
                                         {
                                            dc.sp_delete_orders_ohead(iDentity);
                                         }

                                        if(bItemsInserted == true)
                                        {
                                            dc.sp_delete_orders_oline(iDentity);
                                        }
                                    }
                                    catch{}

                                    throw new System.ServiceModel.Web.WebFaultException(HttpStatusCode.InternalServerError);
                                }
                                else
                                {
                                    iRefId = order.external_ref;
                                    sref = iDentity.ToString();
                                }
                                try
                                {
                                    order = null;
                                }
                                catch { }
                            }
                            else
                            {
                                throw new System.ServiceModel.Web.WebFaultException(HttpStatusCode.InternalServerError);
                            }
                        }//end try
                        catch (Exception ex)
                        {
                            try
                            {
                                sref = ex.Message;
                                if(bOrderInserted == true)
                                {
                                    dc.sp_delete_orders_ohead(iDentity);
                                }

                                if(bItemsInserted == true)
                                {
                                    dc.sp_delete_orders_oline(iDentity);
                                }
                                using (var dc2 = new stylusDataContext())
                                {
                                    dc2.sp_insert_orders_error_log(order.external_ref, "RedBubble endpoint", ex.Message.ToString(),ip);
                                }
                            }
                            catch{}
                            throw new System.ServiceModel.Web.WebFaultException(HttpStatusCode.InternalServerError);
                        }
            }//end using

            var resp2 = new oCreateOrderResponse();
            resp2.id = iRefId;
            resp2.sref = sref;
            return resp2;
        }
示例#3
0
        public oShipStationCreateLabelRequest GetShipStationCreateLabelRequestByExternalRef(long external_ref, long? orderId)
        {
            oShipStationCreateLabelRequest o = new oShipStationCreateLabelRequest();
            List<customsItems> Custom = new List<customsItems>();
            oShipInternational intl = new oShipInternational();

            using (var dc = new stylusDataContext())
            {
                ISingleResult<sp_get_order_by_external_refResult> res = dc.sp_get_order_by_external_ref(external_ref);
                foreach (sp_get_order_by_external_refResult ret in res)
                {
                    o.orderId = orderId;

                    if (ret.shipping_method.ToLower().Trim() == "standard" && ret.shipping_country_code == "US")
                    {
                        o.carrierCode = "ups";
                        o.serviceCode = "expedited_mail_innovations";
                    }

                    if (ret.shipping_method.ToLower().Trim() == "express" && ret.shipping_country_code == "US")
                    {
                        o.carrierCode = "ups";
                        o.serviceCode = "ups_2nd_day_air";
                    }

                    if (ret.shipping_method.ToLower().Trim() == "standard" && ret.shipping_country_code != "US")
                    {
                        o.carrierCode = "apc";
                        o.serviceCode = "apc_priority_ddu";
                    }

                    if (ret.shipping_method.ToLower().Trim() == "express" && ret.shipping_country_code != "US")
                    {
                        o.carrierCode = "ups";
                        o.serviceCode = "ups_worldwide_saver";
                    }

                    o.packageCode = "package";
                    if (o.serviceCode == "expedited_mail_innovations")
                    {
                        o.packageCode = "mi_irregulars";
                    }
                    else
                    {
                        o.packageCode = "package";
                    }

                    o.confirmation = "delivery";
                    o.shipDate = DateTime.Now.ToString();

                    weight w = new weight();
                    w.units = "ounces";
                    if (ret.size == "XS")
                    {
                        w.value = 8 * ret.quantity;
                    }
                    if (ret.size == "SMALL")
                    {
                        w.value = 8 * ret.quantity;
                    }
                    if (ret.size == "MEDIUM")
                    {
                        w.value = 9 * ret.quantity;
                    }
                    if (ret.size == "LARGE")
                    {
                        w.value = 8 * ret.quantity;
                    }
                    if (ret.size == "XL")
                    {
                        w.value = 10 * ret.quantity;
                    }
                    if (ret.size == "2XL")
                    {
                        w.value = 10 * ret.quantity;
                    }
                    if (ret.size == "3XL")
                    {
                        w.value = 11 * ret.quantity;
                    }

                    o.weight = w;

                    if (ret.shipping_country_code != "US")
                    {
                        intl.contents = "merchandise";
                        intl.nonDelivery = "return_to_sender";
                        customsItems c = new customsItems();
                        c.description = ret.description;
                        c.quantity = ret.quantity;
                        c.value = 14 * ret.quantity;
                        c.harmonizedTariffCode = "";
                        c.countryOfOrigin = "US";
                        Custom.Add(c);
                        intl.customsItems = Custom;
                        o.internationalOptions = intl;
                    }

                    o.testLabel = false;
                }
            }
            return o;
        }
示例#4
0
        public oShipStationCreateOrderRequest GetShipStationCreateOrderRequestByExternalRef(long external_ref)
        {
            oShipStationCreateOrderRequest o = new oShipStationCreateOrderRequest();
            billTo b = new billTo();
            shipTo s = new shipTo();
            List<customsItems> Custom = new List<customsItems>();
            oShipInternational intl = new oShipInternational();
            using (var dc = new stylusDataContext())
            {
                ISingleResult<sp_get_order_by_external_refResult> res = dc.sp_get_order_by_external_ref(external_ref);
                foreach (sp_get_order_by_external_refResult ret in res)
                {
                    o.orderNumber = external_ref.ToString();
                    o.orderDate = ret.sale_datetime.ToString();

                    o.orderStatus = "awaiting_shipment";

                    b.name = "Your department.";
                    b.company = "Your company";
                    b.street1 = "Your address";
                    b.city = "city";
                    b.state = "ST";
                    b.postalCode = "06902";
                    b.country = "US";
                    b.phone = "888-888-5555";
                    b.residential = false;

                    o.billTo = b;

                    shipTo st = new shipTo();
                    st.name = ret.customer_name;
                    st.company = null;
                    st.street1 = ret.shipping_address_1;
                    st.street2 = ret.shipping_address_2;
                    //st.street3 = ret.shipping_address_3;
                    if (ret.shipping_country_code != "US")
                    {
                        intl.contents = "merchandise";
                        intl.nonDelivery = "return_to_sender";
                        customsItems c = new customsItems();
                        c.description = ret.description;
                        c.quantity = ret.quantity;
                        c.value = 14 * ret.quantity;
                        c.harmonizedTariffCode = "";
                        c.countryOfOrigin = "US";
                        Custom.Add(c);
                        intl.customsItems = Custom;
                        o.internationalOptions = intl;
                    }

                    st.city = ret.shipping_address_3;
                    st.state = ret.shipping_address_4;
                    st.postalCode = ret.shipping_postcode;
                    st.country = ret.shipping_country_code;
                    st.phone = ret.phone;
                    st.residential = true;

                    o.shipTo = st;
                }
                return o;
            }
            return o;
        }
示例#5
0
        public oCreateOrderResponse PostOrder(oCreateOrderRequest order)
        {
            long   iRefId         = 0;
            string sref           = String.Empty;
            bool   bOrderInserted = false;
            bool   bItemsInserted = false;
            long?  iDentity       = 0;

            //this is if the thumnail is too big(by using a HEAD command), default to this as it makes the PDF document too big
            string stemp_thumb = "https://yourdomain.com/RedBubble/images/na.gif";

            //get custom http header code from config file
            var config     = ConfigurationManager.GetSection("applicationSettings/redbubble.Properties.Settings");
            var xAuthToken = ((ClientSettingsSection)config).Settings.Get("XAuthToken").Value.ValueXml.InnerText;

            //get remote information
            IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
            var headers = request.Headers["X-Auth-Token"];
            OperationContext              context  = OperationContext.Current;
            MessageProperties             prop     = context.IncomingMessageProperties;
            RemoteEndpointMessageProperty endpoint = prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

            string ip = endpoint.Address.ToString();


            if (xAuthToken != headers)
            {
                sref = "Auth Failed";
                LogError(order.external_ref, "AuthFailed", sref, order, ip);
                throw new System.ServiceModel.Web.WebFaultException(HttpStatusCode.Unauthorized);
            }
            using (var dc = new redbubbleDataContext())
            {
                try
                {
                    List <items> line_items      = order.items;
                    int?         iLineItemsCount = line_items.Count; //database might want this for easier count of items so a join is not needed
                    DateTime     dtSaleDate;
                    dtSaleDate = Convert.ToDateTime(order.sale_datetime);
                    bool berror = false;

                    #region validate_all_fields
                    if (order.external_ref == 0 || order.external_ref == null)
                    {
                        sref   = "missing purchase order external_ref order number";
                        berror = true;
                        LogError(order.external_ref, "RedBubble endpoint", sref, order, ip);
                        throw new System.ServiceModel.Web.WebFaultException(HttpStatusCode.InternalServerError);
                    }
                    //check more order fields of course

                    foreach (items itmt in line_items)
                    {
                        if (itmt.external_ref == 0 || itmt.external_ref == null)
                        {
                            sref   = "missing order line external_ref item number";
                            berror = true;
                            LogError(order.external_ref, "RedBubble endpoint", sref, order, ip);
                            throw new System.ServiceModel.Web.WebFaultException(HttpStatusCode.InternalServerError);
                        }
                        //check more items of course
                    }        //end for items
                    #endregion

                    if (berror == false)
                    {
                        try
                        {
                            ISingleResult <sp_insert_orders_oheadResult> res = dc.sp_insert_orders_ohead(order.external_ref, dtSaleDate, order.purchase_complete, order.company_ref_id, order.customer_name, order.shipping_address_1, order.shipping_address_2, order.shipping_address_3, order.shipping_address_4, order.shipping_postcode, order.shipping_country, order.shipping_country_code, order.shipping_method, order.phone, iLineItemsCount, ip, ref iDentity);
                            iDentity       = (long?)order.external_ref;
                            bOrderInserted = true;
                        }
                        catch (Exception ex)
                        {
                            berror = true;
                            LogError(order.external_ref, "RedBubble endpoint", ex.Message.ToString(), order, ip);
                        }

                        //insert into orders_oline
                        try
                        {
                            foreach (items itm in line_items)
                            {
                                dc.sp_insert_orders_oline(iDentity, itm.external_ref, itm.sku, itm.description, itm.quantity, itm.external_url, stemp_thumb, itm.artist_name, itm.title, itm.color, itm.size);
                                bItemsInserted = true;
                            }
                        }
                        catch (Exception ex2)
                        {
                            berror = true;
                            LogError(order.external_ref, "RedBubble endpoint", ex2.Message.ToString(), order, ip);
                        }

                        if (berror == true)
                        {
                            try
                            {
                                if (bOrderInserted == true)
                                {
                                    dc.sp_delete_orders_ohead(iDentity);
                                }

                                if (bItemsInserted == true)
                                {
                                    dc.sp_delete_orders_oline(iDentity);
                                }
                            }
                            catch {}

                            throw new System.ServiceModel.Web.WebFaultException(HttpStatusCode.InternalServerError);
                        }
                        else
                        {
                            iRefId = order.external_ref;
                            sref   = iDentity.ToString();
                        }
                        try
                        {
                            order = null;
                        }
                        catch { }
                    }
                    else
                    {
                        throw new System.ServiceModel.Web.WebFaultException(HttpStatusCode.InternalServerError);
                    }
                }        //end try
                catch (Exception ex)
                {
                    try
                    {
                        sref = ex.Message;
                        if (bOrderInserted == true)
                        {
                            dc.sp_delete_orders_ohead(iDentity);
                        }

                        if (bItemsInserted == true)
                        {
                            dc.sp_delete_orders_oline(iDentity);
                        }
                        using (var dc2 = new stylusDataContext())
                        {
                            dc2.sp_insert_orders_error_log(order.external_ref, "RedBubble endpoint", ex.Message.ToString(), ip);
                        }
                    }
                    catch {}
                    throw new System.ServiceModel.Web.WebFaultException(HttpStatusCode.InternalServerError);
                }
            }//end using

            var resp2 = new oCreateOrderResponse();
            resp2.id   = iRefId;
            resp2.sref = sref;
            return(resp2);
        }