예제 #1
0
 //Setup this class as a Scoped dependency injection and call SetupScope
 public ShopifyService(IHttpService http, IApplicationCache cache,
                       ShopifyOAuth oauth, OAuthPostgres oauthDb, OAuthService oauthRetriever, IRavenClient raven, IOptions <ShopifyOptions> config)
 {
     this.http           = http;
     this.raven          = raven;
     this.config         = config.Value;
     this.oauthDb        = oauthDb;
     this.cache          = cache;
     this.oauthRetriever = oauthRetriever;
 }
예제 #2
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);
            }
        }