Пример #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     ShopifyAuthorizationState state = HttpContext.Current.Session["Shopify.AuthState"] as ShopifyAuthorizationState;
     ShopifyAPIClient client
         = new ShopifyAPIClient(state);
     APIOutput.Text = (string)client.Get("/admin/products.json");
 }
Пример #2
0
 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     base.OnActionExecuting(filterContext);
     ShopifyAuthorizationState authState = ShopifyAuthorize.GetAuthorizationState(this.HttpContext);
     if (authState != null)
     {
         _shopify = new ShopifyAPIClient(authState);
     }
 }
Пример #3
0
        public string GetAccessToken(string code, string shopName)
        {
            authorizer = new ShopifyAPIAuthorizer(shopName, API_KEY, API_SECRET);
            var authState = authorizer.AuthorizeClient(code);

            if (authState != null && authState.AccessToken != null)
            {
                var api = new ShopifyAPIClient(authState, new JsonDataTranslator());
                return authState.AccessToken;
            }
            return null;
        }
    protected void Button2_Click(object sender, EventArgs e)
    {
        ShopifyAuthorizationState authState = new ShopifyAuthorizationState();
        authState.AccessToken = accessToken;
        authState.ShopName = shopName;

        ShopifyAPIClient api = new ShopifyAPIClient(authState);

        // by default JSON string is returned
        dynamic data = new JavaScriptSerializer().DeserializeObject(api.Get("/admin/orders.json").ToString());

        //dynamic orders = new JavaScriptSerializer().DeserializeObject(data);
    }
Пример #5
0
        public object DeleteEntity(string entity, string token, string shopName, string id)
        {
            var authState = new ShopifyAuthorizationState
            {
                AccessToken = token,
                ShopName = shopName
            };

            var api = new ShopifyAPIClient(authState, new JsonDataTranslator());

            var res = api.Delete($"/admin/{entity}/{id}.json");

            return res;
        }
Пример #6
0
        public object CreateEntity(string entity, string token, string shopName, object body)
        {
            var authState = new ShopifyAuthorizationState
            {
                AccessToken = token,
                ShopName = shopName
            };

            var api = new ShopifyAPIClient(authState, new JsonDataTranslator());

            var res = api.Post($"/admin/{entity}.json", body);

            return res;
        }
    public void FulfillOrder(int UserKey, UserAccount userAccount, string orderID, string trackingNumber, string itemID)
    {
        ShopifyAuthorizationState authState = new ShopifyAuthorizationState();
        authState.AccessToken = userAccount.Config_Value1;
        authState.ShopName = userAccount.Application_Name;

        ShopifyAPIClient api = new ShopifyAPIClient(authState, new JsonDataTranslator());

        string inputData = @"{""fulfillment"": {""tracking_number"": """ + trackingNumber + @""",""line_items"": [{id: """ + itemID + @"""}]}}";

        dynamic _inputData = new JavaScriptSerializer().DeserializeObject(inputData);

        // by default JSON string is returned
        dynamic data = new JavaScriptSerializer().DeserializeObject(api.Post("/admin/orders/" + orderID + "/fulfillments.json", _inputData).ToString());
    }
Пример #8
0
        public dynamic GetEntities(string entity, string token, string shopName, string[] fields, int top, string collectionId)
        {
            var authState = new ShopifyAuthorizationState
            {
                AccessToken = token,
                ShopName = shopName
            };
            var api = new ShopifyAPIClient(authState, new JsonDataTranslator());

            var fieldQuery = "";
            var summary = new JArray();

            if (fields.Length != 0)
            {
                var commaSeparatedFields = string.Join(",", fields);
                fieldQuery = "fields=" + commaSeparatedFields + "&";
            }

            if (collectionId != null)
            {
                fieldQuery = fieldQuery + "collection_id=" + collectionId + "&";
            }

            if (top == 0 || top > 250)
            {
                dynamic count = api.Get($"/admin/{entity}/count.json");

                var json = count;
                double realCount = int.Parse(json.GetValue("count").ToString());
                realCount = realCount / 250;
                var loops = (int)Math.Ceiling(realCount);

                if (entity == "webhooks")
                    loops = 1;

                for (var i = 1; i <= loops; i++)
                {
                    CollectEntities(api, summary, entity, 250, i, fieldQuery);
                }
            }
            else
            {
                CollectEntities(api, summary, entity, top, 1, fieldQuery);
            }

            return summary;
        }
Пример #9
0
        public JArray GetCustomerSavedSearches(string token, string shopName)
        {
            var summary = new JArray();
            var authState = new ShopifyAuthorizationState();
            authState.AccessToken = token;
            authState.ShopName = shopName;
            var api = new ShopifyAPIClient(authState, new JsonDataTranslator());

            var filterObject = (JObject)api.Get("/admin/customer_saved_searches.json");
            var filtersObject = filterObject.GetValue("customer_saved_searches");
            foreach (JObject filter in filtersObject)
            {
                summary.Add(filter);
            }

            return summary;
        }
Пример #10
0
        public JArray GetEntities(string entity, string token, string shopName, int top, string[] fields)
        {
            var authState = new ShopifyAuthorizationState();
            authState.AccessToken = token;
            authState.ShopName = shopName;
            var api = new ShopifyAPIClient(authState, new JsonDataTranslator());

            dynamic data;
            var fieldQuery = "";
            var summary = new JArray();

            if (fields.Length != 0)
            {
                var commaSeparatedFields = string.Join(",", fields);
                fieldQuery = "fields=" + commaSeparatedFields + "&";
            }

            if (top == 0 || top > 250)
            {
                dynamic count = api.Get(string.Format("/admin/{0}/count.json", entity));

                var json = count;
                data = count;
                double realCount = int.Parse(json.GetValue("count").ToString());
                realCount = realCount / 250;
                var loops = (int)Math.Ceiling(realCount);

                for (int i = 1; i <= loops; i++)
                {
                    collectEntities(api, summary, entity, 250, i, fieldQuery);
                }
            }
            else
            {
                collectEntities(api, summary, entity, top, 1, fieldQuery);
            }
            return summary;
        }
Пример #11
0
        public JArray GetCustomerSavedSearch(string token, string shopName, int id, string[] fields)
        {
            var customers = new JArray();
            var authState = new ShopifyAuthorizationState();
            authState.AccessToken = token;
            authState.ShopName = shopName;
            var api = new ShopifyAPIClient(authState, new JsonDataTranslator());
            string fieldQuery = "";

            if (fields.Length != 0)
            {
                var commaSeparatedFields = string.Join(",", fields);
                fieldQuery = "?fields=" + commaSeparatedFields;
            }

            var filterObject = (JObject)api.Get(string.Format("/admin/customer_saved_searches/{0}/customers.json{1}", id, fieldQuery));
            var customersObject = filterObject.GetValue("customers");
            foreach (JObject customer in customersObject)
            {
                customers.Add(customer);
            }

            return customers;
        }
Пример #12
0
        public ProductDataSource()
        {
            // TODO: Of course it's a bad idea to hardcode this. In fact having this in your app is a bad idea period. This really should be exposed via
            // your own custom REST API that then connected to Shopify's.
            // This is just an example to show that it can be done, not how it *should* be done.
            ShopifyAuthorizationState authState = new ShopifyAuthorizationState
            {
                ShopName = "buckridge-hyatt6895",
                AccessToken = "42d4917ed3507278c748046addb01f3d"
            };

            var api = new ShopifyAPIClient(authState, new JsonDataTranslator());

            // The JSON Data Translator will automatically decode the JSON for you
            var result = api.Get("/admin/products.json");

            result.Completed = delegate(IAsyncOperation<dynamic> asyncAction, AsyncStatus asyncStatus)
            {
                var data = asyncAction.GetResults();
                var products = data.products;

                foreach (var product in products)
                {
                    var group = new ProductDataGroup(product.id.ToString(),
                                        product.title.ToString(),
                                        product.vendor.ToString(),
                                        product.images.Count > 0 ? product.images[0].src.ToString() : "",
                                        product.body_html.ToString());

                    var imgCount = 0;
                    foreach (var variant in product.variants)
                    {
                        group.Items.Add(new ProductDataItem(variant.id.ToString(),
                                            variant.option1.ToString(),
                                            variant.option2.ToString(),
                                            imgCount < product.images.Count ? product.images[imgCount++].src.ToString() : "",
                                            "",
                                            group.Description,
                                            group));
                    }
                    this.AllGroups.Add(group);
                }
            };
        }
Пример #13
0
    public List<ParcelItem> GetPendingOrders(int userCode, int userAccountCode)
    {
        DataModelEntities context = new DataModelEntities();

        UserAccount userAccount = context.UserAccounts.First(u => u.User_Account_Code == userAccountCode);
        List<ChargeCode> chargeCodes = context.ChargeCodes.Where(u => u.Is_Active == true && u.User_Code == userCode).ToList();

        ShopifyAuthorizationState authState = new ShopifyAuthorizationState();
        authState.AccessToken = userAccount.Config_Value1;
        authState.ShopName = userAccount.Application_Name;

        ShopifyAPIClient api = new ShopifyAPIClient(authState);

        try
        {
            // by default JSON string is returned
            dynamic data = new JavaScriptSerializer().DeserializeObject(api.Get("/admin/orders.json?fulfillment_status=unshipped").ToString());

            List<PriceManagerDAL.ParcelItem> parcelItems = context.ParcelItems.Where(f => f.User_Code == userCode && f.UserAccount.Account_Code == (int)Constant.Accounts.Shopify && f.Is_Active == true).ToList();

            // delete all database entries
            foreach (PriceManagerDAL.ParcelItem existingItem in parcelItems)
            {
                context.ParcelItems.DeleteObject(existingItem);
            }
            context.SaveChanges();

            List<ParcelItem> items = new List<ParcelItem>();

            foreach (dynamic order in data["orders"])
            {
                foreach (dynamic lineItem in order["line_items"])
                {
                    ParcelItem item = new ParcelItem();

                    item.Type = "SHOPIFY";
                    item.AccountID = userAccount.User_Account_Code.ToString();
                    item.RecordNumber = order["order_number"].ToString();
                    item.ItemID = lineItem["id"].ToString();
                    item.TransactionID = order["id"].ToString();
                    item.ItemName = lineItem["title"];
                    item.CustomLabel = lineItem["sku"].ToString();
                    item.CustomLabelText = lineItem["sku"].ToString();

                    string state = order["shipping_address"]["province"];
                    string stateCode = order["shipping_address"]["province_code"];

                    if (StateHelper.States.Where(s => s.Key == stateCode).Count() > 0)
                        item.State = StateHelper.States[stateCode];
                    else
                        item.State = state;

                    item.BuyerName = order["customer"]["first_name"] + " " + order["customer"]["last_name"];
                    item.EmailAddress = order["email"];
                    item.BuyerID = order["customer"]["id"].ToString();

                    item.Street2 = order["shipping_address"]["address1"];
                    item.Street3 = order["shipping_address"]["address2"];
                    item.City = order["shipping_address"]["city"];
                    item.PostalCode = order["shipping_address"]["zip"].TrimStart('0');
                    item.Country = order["shipping_address"]["country_code"];
                    item.Phone = order["shipping_address"]["phone"];

                    item.Quantity = lineItem["quantity"];
                    if (order["shipping_lines"] != null)
                        item.ShippingCost = double.Parse(order["shipping_lines"][0]["price"]);
                    item.SaleRecordId = order["order_number"].ToString();

                    // insurance details //

                    item.Currency = order["currency"];
                    item.Price = double.Parse(lineItem["price"]);

                    item.Messages = GetMessageText(order["note"],order["created_at"]);

                    item.ShippingMethod = order["shipping_lines"][0]["title"];

                    string shippingCode = order["shipping_lines"][0]["code"];
                    ChargeCode code = chargeCodes.FirstOrDefault(u => shippingCode.ToLower().Contains(u.Ebay_Code.ToLower()) == true);
                    if (code != null && code.Charge_Code_Name.ToLower() == "ignore")
                    {
                        continue; // ignore the item
                    }

                    bool IspostCodeOK = Common.VerifyPostCode(order["shipping_address"]["zip"], order["shipping_address"]["city"]);
                    if (IspostCodeOK)
                        item.PostCodeImageURL = Constant.tickURL;
                    else
                        item.PostCodeImageURL = Constant.crossURL;

                    items.Add(item);
                }
            }

            return items;
        }
        catch (Exception ex)
        {
            return null;
        }
    }
Пример #14
0
        //
        // GET: /Shopify/Test
        public ActionResult Test()
        {
            var appID = Request.Params["id"];
            using (ShopifyAppsContext context = new ShopifyAppsContext())
            {
                var app = context.ShopifyApps.Find(new Guid(appID));
                ViewData["App"] = app;

                ShopifyAuthorizationState authState = new ShopifyAuthorizationState
                {
                    ShopName = app.ShopName,
                    AccessToken = app.AccessToken
                };

                var api = new ShopifyAPIClient(authState, new JsonDataTranslator());

                // The JSON Data Translator will automatically decode the JSON for you
                ViewData["ProductData"] = api.Get("/admin/products.json");
            }
            return View();
        }
Пример #15
0
 private void collectEntities(ShopifyAPIClient api, JArray summary, string entity, int top, int page, string fieldQuery)
 {
     var entityObject = (JObject)api.Get(string.Format("/admin/{0}.json?{1}limit={2}&page={3}", entity, fieldQuery, top, page));
     var entitiesObject = entityObject.GetValue(string.Format("{0}", entity));
     foreach (JObject customer in entitiesObject)
     {
         summary.Add(customer);
     }
 }
Пример #16
0
        public dynamic GetEntity(string entity, string id, string token, string shopName, string[] fields, int top)
        {
            var authState = new ShopifyAuthorizationState
            {
                AccessToken = token,
                ShopName = shopName
            };

            var api = new ShopifyAPIClient(authState, new JsonDataTranslator());

            var queryString = "";
            dynamic entityObject;
            if (fields.Length != 0)
            {
                var commaSeparatedFields = string.Join(",", fields);
                queryString = "fields=" + commaSeparatedFields + "&";
            }

            if (entity.Equals("collections"))
            {
                entity = "products";
                entityObject = GetEntities(entity, token, shopName, fields, top, id);
                return entityObject;
            }if (entity.Equals("customer_saved_searches"))
            {
                id = id + "/customers";
                if (top != 0)
                {
                    queryString = queryString + "limit=" + top;
                }
            }
            var urlSuffix = $"/admin/{entity}/{id}.json?{queryString}";
            entityObject = (JObject)api.Get(urlSuffix);

            return entityObject;
        }
Пример #17
0
 private static void CollectEntities(ShopifyAPIClient api, JArray summary, string entity, int top, int page, string fieldQuery)
 {
     var entityObject = (JObject)api.Get($"/admin/{entity}.json?{fieldQuery}limit={top}&page={page}");
     var entitiesObject = entityObject.GetValue($"{entity}");
     foreach (var entityObj in entitiesObject.Cast<JObject>())
     {
         summary.Add(entityObj);
     }
 }