Exemple #1
0
        public static void PopulateShipping(RestClient Client)
        {
            var countries = GetCountryMapping(Client);

            List <string> USAOnly = new List <string>
            {
                "United States",
                "Puerto Rico",
                "Guam",
                "U.S. Virgin Islands",
                "American Samoa",
                "Northern Mariana Islands",
                "Midway Islands",
                "Wake Island",
                "Johnston Atoll",
                "Baker, Howland, and Jarvis Islands",
                "Kingman Reef",
                "Navassa Island",
                "Palmyra Atoll",
            };
            string usonly = "USPS - First Class (USA Only)";
            string intl   = "USPS - First Class International";

            string shipmethod;

            foreach (var country in countries.Values)
            {
                if (USAOnly.Contains(country))
                {
                    shipmethod = usonly;
                }
                else
                {
                    shipmethod = intl;
                }
                CountryService.CreateCountyShippingMethod(country, shipmethod);
            }
        }
Exemple #2
0
        public void ImportListing(RestClient RestClient)
        {
            var dictListings = ImportHelpers.ImportTabDelimitedFile(@"C:\Internal\Etsy\listingimport.txt");
            var gclient      = InternalClientService.GetInternalClientByID(dictListings.Where(x => x.Key == 2).First().Value[0].ToString());
            //GETTING SHIPPING TEMPLATE
            string shiptempId = ShippingTemplateService.GetShippingTemplateId(RestClient, gclient.EtsyUserName);
            //string status = ShippingTemplateService.CreateShippingTemplate(RestClient, "Test Shipping Template", countries.Where(x => x.Value == "United States").FirstOrDefault().Key.ToString(), "2.00", "1.00");
            var countries = CountryService.GetCountryMapping(RestClient);

            foreach (var row in dictListings.Skip(1))
            {
                if (row.Key != 1)
                {
                    Console.WriteLine("CREATING A DRAFT LISTING");
                    var     obj         = row.Value;
                    Listing testListing = new Listing
                    {
                        title                = obj[1].ToString(),
                        description          = obj[2].ToString(),
                        price                = obj[3].ToString(),
                        quantity             = obj[7].ToString(),
                        shipping_template_id = shiptempId,
                        state                = "draft",
                        is_supply            = "false",
                        who_made             = "i_did",
                        when_made            = "made_to_order",
                    };
                    //var listing = CreateListing(RestClient, testListing);

                    Console.WriteLine("CREATING A LISTING IMAGE");
                    string filepath = string.Format(@"C:\Internal\EtsyProductImages\{0}", obj[4].ToString());
                    //CreateListingItemImage(RestClient, listing, obj[4].ToString(), filepath);

                    Console.WriteLine("CREATE LISTING VARIATIONS");
                    List <ListingVariation> variations = new List <ListingVariation>();
                    ListingVariation        variation;

                    List <string> sizes = new List <string> {
                        "S", "M", "L", "XL", "XXL"
                    };
                    string style = obj[6].ToString();
                    foreach (var size in sizes)
                    {
                        variation             = new ListingVariation();
                        variation.property_id = "513";
                        //variation.is_available = "TRUE";
                        variation.value = string.Format("{0}-{1}", size, style);
                        variations.Add(variation);
                    }

                    List <string> designs = obj[5].ToString().Split(';').ToList();
                    foreach (var design in designs)
                    {
                        string[] designcolor = design.Split(':');
                        variation             = new ListingVariation();
                        variation.property_id = "200";
                        variation.value       = string.Format("{0}-{1}", designcolor[0], designcolor[1]);
                        variations.Add(variation);
                    }
                    string output = JsonConvert.SerializeObject(variations.ToArray());
                    //UpdateListingVariations(RestClient, listing, output);
                    Console.WriteLine("Listing Created");
                    Thread.Sleep(1000);
                }
            }
        }
Exemple #3
0
        public static List <ExtractionModel> CreateExtractionFromReceipt(InternalClient GClient, bool allReceipts)
        {
            //Creation New Rest Client
            var client = new RestClient();

            client.BaseUrl       = AppKeys.GetBaseUri();
            client.Authenticator = OAuth1Authenticator.ForProtectedResource(AppKeys.GetApiKey(), AppKeys.GetSharedSecretKey(), GClient.AccessToken, GClient.AccessSecretKey);

            //The shop servce is where we pull receipts because functionally
            //The call is related to the shop object and te shop id
            ShopService    shopservice = new ShopService();
            List <Receipt> receipts;

            //This is just in case for some reason we want every transaction from a shop
            if (allReceipts)
            {
                receipts = shopservice.GetShopReceipts(client, GClient.EtsyShopIDs.FirstOrDefault());
            }
            else
            {
                receipts = shopservice.GetOpenShopReceipts(client, GClient.EtsyShopIDs.FirstOrDefault());
            }

            //Get the country list from etsy in advance so it doesn't
            //Have to be called per receipt request
            var countries = CountryService.GetCountryMapping(client);

            List <ExtractionModel> extractions = new List <ExtractionModel>();

            //make sure we actually pulled back client data
            if (GClient != null)
            {
                //iteract through receipts
                foreach (Receipt r in receipts)
                {
                    //iterrate through transactions of receipts
                    foreach (var t in r.transactions)
                    {
                        string country = countries[int.Parse(r.country_id)];

                        ExtractionModel em = new ExtractionModel();
                        em.company_id             = GClient.clientID;
                        em.Order_ID               = r.receipt_id;
                        em.date_purchased         = FormattingHelpers.FromEpochUnixTime(t.creation_tsz).ToString("g");
                        em.customer_email_address = r.buyer_email;
                        var FirstnameLastname = FormattingHelpers.FirstNameLastNameFormatter(r.name);
                        em.first_name = FirstnameLastname.Item1;
                        em.last_name  = FirstnameLastname.Item2;

                        em.delivery_address_1 = r.first_line;
                        em.delivery_address_2 = r.second_line;
                        em.delivery_city      = r.city;
                        em.delivery_state     = r.state;
                        em.delivery_zipCode   = r.zip;
                        em.country            = country;

                        //This is for the variation that is assuming
                        //it follows the format "Color - Design"
                        string[] color_design = t.variations.Where(x => x.formatted_name == "Color").FirstOrDefault().formatted_value.Split('-');

                        //If there is not a "-" then it automatically
                        //is the wrong format
                        if (color_design.Length > 1)
                        {
                            //This is making sure that the Design actually is associated
                            //with the client
                            //TODO: Eventually check that the design is actually available in the color
                            //that is provided.
                            if (GClient.ClientDesigns.Where(x => x.design_number.Trim() == color_design[1].Trim()).Any())
                            {
                                em.color         = color_design[0].Trim();
                                em.design_number = FormattingHelpers.DesignNumberFormatCheck(color_design[1].Trim());
                            }
                            else
                            {
                                em.color         = color_design[0].Trim();
                                em.design_number = string.Format("{0} Is Not a Correct Design Id", color_design[1]);
                            }
                        }
                        else
                        {
                            em.color         = color_design[0].Trim();
                            em.design_number = "Color_Design Incorrect Format";
                        }
                        em.design_description = "TBD";
                        em.print_location     = "TBD";


                        //This is for the variation that is assuming
                        //it follows the format "Style - Size"
                        string[] size_style = t.variations.Where(x => x.formatted_name == "Size").FirstOrDefault().formatted_value.Split('-');

                        if (size_style.Length > 1)
                        {
                            string etsystyle = size_style[1].Trim();
                            em.size = size_style[0].Trim();

                            //Check to see if the style from the variation
                            //has a mapping otherwise we can't know what
                            //prodct style its suposed to be
                            var style = GClient.ClientStyles.Where(x => x.etsy_style_descripion == etsystyle).FirstOrDefault();
                            if (style != null)
                            {
                                em.style_number      = style.style_number;
                                em.style_description = style.style_description;
                            }
                            else
                            {
                                em.style_number      = "ESTY STYLE '" + etsystyle + "' NOT FOUND";
                                em.style_description = "ESTY STYLE '" + etsystyle + "' NOT FOUND";
                            }
                        }
                        else
                        {
                            em.style_number      = size_style[0].Trim();
                            em.style_description = "Size_Style Incorrect Format";
                        }

                        em.product_quantity = t.quantity;
                        em.gift_message     = r.message_from_buyer;
                        em.Insured_Order    = "No";
                        em.shipping_method  = CountryService.GetCountryShippingMethodByCountry(country).Shipping_Method;
                        em.order_status     = "2";

                        extractions.Add(em);
                    }
                }
            }
            return(extractions);
        }