示例#1
0
        public async Task <ShopifyOrder[]> GetOrders(string username)
        {
            var creds = await GetCredentials(username);

            if (creds == null)
            {
                return(new ShopifyOrder[0]); //Not integrated into shopify
            }
            string endpoint = ShopifyEndpoints.BaseEndpoint(creds.Shop, "orders.json") + "?fulfillment_status=unshipped,partial";

            var response = await http.Get(endpoint, (client) =>
            {
                addAuthenticatoin(client, creds.AccessToken);
            });

            string message = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                var ordersResponse = JObject.Parse(message).SelectToken("orders").ToString();
                var ret            = JsonConvert.DeserializeObject <ShopifyOrder[]>(ordersResponse, jsonSettings);
                return(ret);
            }
            else
            {
                return(new ShopifyOrder[0]);
            }
        }
示例#2
0
        public async Task <ShopifyProductModel[]> GetProductsByID(string username, string[] ids, OAuthShopifyModel creds)
        {
            string endpoint = ShopifyEndpoints.BaseEndpoint(creds.Shop, ShopifyEndpoints.Products) + $"?ids={String.Join(",", ids)}";

            var response = await http.Get(endpoint, (client) =>
            {
                addAuthenticatoin(client, creds.AccessToken);
            });

            string message = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                var productResponse = JObject.Parse(message).SelectToken("products").ToString();
                var ret             = JsonConvert.DeserializeObject <ShopifyProductModel[]>(productResponse, jsonSettings);

                foreach (var item in ret)
                {
                    item.Link = $"https://{creds.Shop}/admin/products/{item.ID}";
                }

                return(ret);
            }

            return(new ShopifyProductModel[0]);
        }
示例#3
0
        public async Task <ShopifyProductModel> UpdateProduct(string username, ShopifyProductModel product, OAuthShopifyModel creds)
        {
            string endpoint = ShopifyEndpoints.BaseEndpoint(creds.Shop, "products") + $"/{product.ID}.json";

            var requestType = new
            {
                Product = product
            };

            var requestContent = JsonConvert.SerializeObject(requestType, jsonSettings);
            var content        = new StringContent(requestContent);

            content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            var response = await http.Put(endpoint, content, (client) =>
            {
                addAuthenticatoin(client, creds.AccessToken);
            });

            string message = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                var productResponse = JObject.Parse(message).SelectToken("product").ToString();
                var ret             = JsonConvert.DeserializeObject <ShopifyProductModel>(productResponse, jsonSettings);
                return(ret);
            }
            else
            {
                return(null);
            }
        }
示例#4
0
        public async Task <ShopifyProductModel[]> GetProducts(string username)
        {
            var creds = await GetCredentials(username);

            if (creds == null)
            {
                return(new ShopifyProductModel[0]); //Not integrated into shopify
            }
            string endpoint = ShopifyEndpoints.BaseEndpoint(creds.Shop, ShopifyEndpoints.Products);

            var response = await http.Get(endpoint, (client) =>
            {
                addAuthenticatoin(client, creds.AccessToken);
            });

            string message = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                var productResponse = JObject.Parse(message).SelectToken("product").ToString();
                var ret             = JsonConvert.DeserializeObject <ShopifyProductModel[]>(productResponse, jsonSettings);
                return(ret);
            }

            return(new ShopifyProductModel[0]);
        }
示例#5
0
        public async Task <bool> AddShopifyIntegration(DropshipAccount account, ShopifyOAuthResponse oauth, ShopifyOAuth verify)
        {
            var username = account.Username;

            var endpoint = ShopifyEndpoints.OAuthEndpoint(oauth.Shop);

            var requestType = new
            {
                client_id     = config.ClientID,
                client_secret = config.ClientSecret,
                code          = oauth.Code
            };

            var requestContent = JsonConvert.SerializeObject(requestType, jsonSettings);
            var content        = new JsonContent(requestContent);

            var response = await http.Post(endpoint, content);

            string message = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                var tokenResponse = JsonConvert.DeserializeObject <ShopifyOAuthAccessResponse>(message, jsonSettings);
                verify.VerifyScope(tokenResponse.Scope);

                await oauthDb.CreateOAuth(new OAuthAccountModel()
                {
                    AccessToken = tokenResponse.AccessToken,
                    Username    = username,
                    Service     = "Shopify",
                    Extra       = new Dictionary <string, string>()
                    {
                        { "Shop", oauth.Shop }
                    },
                    AccountID = account.ID
                });

                return(true);
            }
            else
            {
                return(false);
            }
        }