Esempio n. 1
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);
        }
Esempio n. 2
0
    private static (string accessToken, ITokenClientFactory tokenClientFactory) MockTokenClientFactory()
    {
        var        accessToken = Guid.NewGuid().ToString();
        ITokenInfo tokenInfo   = Substitute.For <ITokenInfo>();

        tokenInfo.AccessToken.Returns(accessToken);
        ITokenClient tokenClient = Substitute.For <ITokenClient>();

        tokenClient.GetTokenAsync(Arg.Any <bool>()).Returns(Result(tokenInfo));
        ITokenClientFactory tokenClientFactory = Substitute.For <ITokenClientFactory>();

        tokenClientFactory.GetTokenClient(IamClientOptions.IamTokenClientName).Returns(Result(tokenClient));
        return(accessToken, tokenClientFactory);
    }