コード例 #1
0
        private async Task CreateAppUninstalledWebhook(ShopifyStore shopifyStore)
        {
            if (shopifyStore == null)
            {
                throw new NullReferenceException();
            }

            var shopifyWebhookService = new WebhookService(shopifyStore.Shop, shopifyStore.AccessToken);

            try
            {
                await shopifyWebhookService.CreateAsync(new Webhook
                {
                    Address   = GetWebhookAddress(ShopifyWebhookTopic.AppUninstalled, shopifyStore.Id),
                    CreatedAt = DateTime.Now,
                    Format    = ShopifyConstants.Format,
                    Topic     = ShopifyWebhookTopic.AppUninstalled
                });
            }
            catch (ShopifyException e)
            {
                string message =
                    $"Couldn't create {ShopifyWebhookTopic.AppUninstalled} webhook for {shopifyStore.Shop}. Reason: " +
                    string.Join(", ", e.Errors);
                _logger.Error(message);
            }
        }
コード例 #2
0
        private Task <ShopifyStore> AddOrUpdateShopifyStore(ShopifyStore shopifyStore, string accessToken)
        {
            shopifyStore.AccessToken  = accessToken;
            shopifyStore.DeletionTime = null;
            shopifyStore.IsDeleted    = false;

            return(_shopifyStoreService.AddOrUpdateShopifyStoreAsync(shopifyStore));
        }
コード例 #3
0
        private async Task CheckShop(Shop shopProperties, string NDAAccountId, string token, int NDAShopId)
        {
            ShopifyStore shopifyStore = await _shopifyStoreService.GetShopifyStoreByNDAShopIdAsync(NDAShopId);

            if (shopifyStore is null)
            {
                return;
            }

            var res = await CreateNDAShop(shopProperties, NDAAccountId, token);
        }
コード例 #4
0
        public async Task InstallAsync(string shop, string accessToken, string NDAAccountId, int NDAShopId)
        {
            var  shopService    = new ShopService(shop, accessToken);
            Shop shopProperties = await shopService.GetAsync();

            //Continue install
            var token = await _tokenClient.GetTokenAsync();

            if (token == null)
            {
                await AppInstallationFailed(shopService, shop, "Can't get token.");

                return;
            }

            var shopifyStores = await _shopifyStoreService.GetShopifyStoreByDomainOrNDAShopId(shop, NDAShopId, 2);

            var shopifyStore = shopifyStores.FirstOrDefault(store => store.Shop == shop);

            if (shopifyStore is null)
            {
                var shopifyStoreWithShopId = shopifyStores.FirstOrDefault(store => store.NDAShopId == NDAShopId);
                if (shopifyStoreWithShopId != null) // otherwise the user has an empty NDA shop after registration
                {
                    (bool success, ShopDto NDAShop) = await CreateNDAShop(shopProperties, NDAAccountId, token);

                    if (!success)
                    {
                        await AppInstallationFailed(shopService, shop, $"Error while adding shop with token.");

                        return;
                    }

                    NDAShopId = NDAShop.Id;
                }

                shopifyStore = new ShopifyStore
                {
                    NDAShopId = NDAShopId,
                    Shop      = shop
                };

                await CreateNewNDAIntegration(shopProperties, token, NDAShopId);
            }

            _logger.Info($"shopify store  = {shopifyStore.Shop} with NDAshopID = {shopifyStore.NDAShopId}");

            shopifyStore = await AddOrUpdateShopifyStore(shopifyStore, accessToken);
            await CreateAppUninstalledWebhook(shopifyStore);
            await CreateFulfillmentService(shopifyStore);
        }
コード例 #5
0
        private async Task CreateFulfillmentsCreateWebhook(ShopifyStore shopifyStore)
        {
            var shopifyWebhookService = new WebhookService(shopifyStore.Shop, shopifyStore.AccessToken);

            try
            {
                await shopifyWebhookService.CreateAsync(new Webhook
                {
                    Address   = GetWebhookAddress(ShopifyWebhookTopic.FulfillmentsCreate, shopifyStore.Id),
                    CreatedAt = DateTime.Now,
                    Format    = ShopifyConstants.Format,
                    Topic     = ShopifyWebhookTopic.FulfillmentsCreate
                });
            }
            catch (ShopifyException e)
            {
                string message =
                    $"Couldn't create {ShopifyWebhookTopic.FulfillmentsCreate} webhook for {shopifyStore.Shop}. Reason: " +
                    string.Join(", ", e.Errors);
                _logger.Error(message);
            }
        }
コード例 #6
0
        private async Task CreateFulfillmentService(ShopifyStore shopifyStore)
        {
            if (shopifyStore == null)
            {
                throw new NullReferenceException();
            }

            FulfillmentServiceService fulfillmentServiceService =
                new FulfillmentServiceService(shopifyStore.Shop, shopifyStore.AccessToken);
            await fulfillmentServiceService.CreateAsync(
                new FulfillmentServiceEntity
            {
                Name        = _shopifyOptions.FulfillmentServiceName ?? ShopifyConstants.FulfillmentServiceName,
                CallbackUrl = (_shopifyOptions.WebhooksParameters.UseTunnel
                                      ? _shopifyOptions.WebhooksParameters.TunnelAddress
                                      : GetAppUrl()) + $"/{ShopifyConstants.ShopifyRoute}",
                Format = ShopifyConstants.Format,
                InventoryManagement    = true,
                TrackingSupport        = false,
                RequiresShippingMethod = false
            });

            await CreateFulfillmentsCreateWebhook(shopifyStore);
        }