Exemplo n.º 1
0
        public async Task <IAccountProvider> CreateDataProvider(ProviderDoc provider)
        {
            IAccountProvider accountProvider = null;

            switch (provider.Name)
            {
            case "Bank Hapoalim":
                //accountProvider = new HapoalimAccountProvider(provider, new HapoalimFileApi(provider));
                accountProvider = new HapoalimAccountProvider(new HapoalimApi(provider.Credentials));
                break;

            case "Bank Leumi":
                accountProvider = new LeumiAccountProvider(new LeumiApi(provider));
                break;

            case "Bank Mizrahi-Tefahot":
                accountProvider = new TefahotAccountProvider(new TefahotApi(provider));
                break;

            case "Amex":
                accountProvider = new AmexProvider(new AmexApi(provider.Credentials));
                //accountProvider = new AmexProvider(provider, new AmexFileApi(provider));
                break;

            case "Visa Cal":
                accountProvider = new CalProvider(new CalApi(provider.Credentials));
                break;

            default: break;
            }

            return(accountProvider);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetAccounts([FromBody] ProviderCreatingDto providerDto)
        {
            IEnumerable <BankAccountCreatingDto> result;

            var providerDescriptor = new ProviderDoc
            {
                Name        = providerDto.Name,
                Type        = providerDto.Type,
                Credentials = providerDto.Credentials
            };

            try
            {
                var dataProvider = await _providerFactory.CreateDataProvider(providerDescriptor);

                var accounts = (dataProvider as IBankAccountProvider)?.GetAccounts();
                dataProvider.Dispose();

                var provider    = AutoMapper.Mapper.Map <ProviderDoc>(providerDto);
                var newAccounts = FetchNewAccount(provider, accounts);

                result = AutoMapper.Mapper.Map <IEnumerable <BankAccountCreatingDto> >(newAccounts);
            }
            catch (UnauthorizedAccessException ex)
            {
                return(new UnauthorizedActionResult(ex.Message));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(Ok(result));
        }
Exemplo n.º 3
0
        public LeumiApi(ProviderDoc providerDescriptor)
        {
            if (providerDescriptor == null || providerDescriptor.Credentials.Count == 0)
            {
                throw new ArgumentNullException(nameof(providerDescriptor));
            }

            var crentialValues = providerDescriptor.Credentials.Values.ToArray();

            _userName     = crentialValues[0];
            _userPassword = crentialValues[1];
        }
Exemplo n.º 4
0
        public async Task <String> AddProvider(ProviderDoc provider)
        {
            try
            {
                await _context.Providers.InsertOneAsync(provider);
            }
            catch (Exception ex)
            {
                // log or manage the exception
                throw ex;
            }

            return(provider.Id);
        }
Exemplo n.º 5
0
        private async Task <bool> ProcessProvider(ProviderDoc provider)
        {
            var hostName = _configuration.GetSection("Host:Name").Value;
            HttpResponseMessage response = await _client.GetAsync(hostName + ":5002/accounts/" + "");

            if (!response.IsSuccessStatusCode)
            {
                return(false);
            }

            var product = await response.Content.ReadAsStringAsync();

            return(true);
        }
Exemplo n.º 6
0
        public async Task <bool> UpdateProvider(String id, ProviderDoc provider)
        {
            try
            {
                ReplaceOneResult actionResult = await _context.Providers.ReplaceOneAsync(
                    p => p.Id.Equals(id),
                    provider, new UpdateOptions { IsUpsert = true });

                return(actionResult.IsAcknowledged && actionResult.ModifiedCount > 0);
            }
            catch (Exception ex)
            {
                // log or manage the exception
                throw ex;
            }
        }
Exemplo n.º 7
0
        public TefahotApi(ProviderDoc providerDescriptor)
        {
            if (providerDescriptor == null || providerDescriptor.Credentials.Count == 0)
            {
                throw new ArgumentNullException(nameof(providerDescriptor));
            }

            var crentialValues = providerDescriptor.Credentials.Values.ToArray();

            _userName     = crentialValues[0];
            _userPassword = crentialValues[1];

            var viewstate = Login();

            RetriveSession(viewstate);
        }
Exemplo n.º 8
0
        private IEnumerable <BankAccount> FetchNewAccount(ProviderDoc provider, IEnumerable <BankAccount> accounts)
        {
            IEnumerable <BankAccount> newAccounts;

            var providerInRepo = _providerRepository.Find(provider);

            if (providerInRepo?.Result != null)
            {
                newAccounts = (from account in accounts
                               where !IsAccountExists(account)
                               select account).ToList();
            }
            else
            {
                newAccounts = accounts;
            }

            return(newAccounts);
        }
Exemplo n.º 9
0
        public async Task <IEnumerable <CreditCard> > UpdateCreditCards(ProviderDoc provider)
        {
            var result = new List <CreditCard>();

            using (var dataProvider = await _providerFactory.CreateDataProvider(provider))
            {
                foreach (var id in provider.Accounts)
                {
                    var outdatedCardDoc = await _creditAccountRepository.FindCardByCriteria(a => a.Id.Equals(id));

                    var outdatedCard = AutoMapper.Mapper.Map <CreditCard>(outdatedCardDoc);
                    var cardUpdate   = FetchCardUpdate(outdatedCardDoc, dataProvider);

                    var card = MergeCardUpdate(outdatedCard, cardUpdate);
                    result.Add(card);
                }
            }

            return(result);
        }
Exemplo n.º 10
0
        public async Task <ProviderDoc> Find(ProviderDoc provider)
        {
            try
            {
                var providers = await _context.Providers.Find(
                    p => p.Name.Equals(provider.Name) &&
                    p.UserId.Equals(provider.UserId)
                    ).ToListAsync();

                var result = (from p in providers
                              where EqualCredentials(p.Credentials, provider.Credentials)
                              select p).FirstOrDefault();

                return(result);
            }
            catch (Exception ex)
            {
                // log or manage the exception
                throw ex;
            }
        }
Exemplo n.º 11
0
 private bool HasOutdatedAccounts(ProviderDoc provider)
 {
     return(_accountRepository.GetAccountsByProviderId(provider.Id)
            .Result.ToList()
            .Any(a => a.UpdatedOn.AddHours(AccountExpirationPeriod) < DateTime.Now));
 }
Exemplo n.º 12
0
        private async Task <IEnumerable <CreditCard> > UpdateCreditCards(ProviderCreatingDto newProvider, ProviderDoc provider, List <String> accountsIds)
        {
            var creditCards = await AddCreditAccounts(newProvider, provider.Id);

            accountsIds.AddRange(creditCards.Select(a => a.Id).ToList());
            provider.Accounts = accountsIds;
            await _providerRepository.UpdateProvider(provider.Id, provider);

            var updatedCards = await _accountService.UpdateCreditCards(provider);

            foreach (var updatedCard in updatedCards)
            {
                await _creditCardRepository.UpdateCard(updatedCard.Id,
                                                       AutoMapper.Mapper.Map <CreditCardDoc>(updatedCard));
            }
            return(updatedCards);
        }
Exemplo n.º 13
0
        private async Task <IEnumerable <BankAccountDoc> > UpdateBankAccounts(ProviderCreatingDto newProvider, ProviderDoc provider, List <String> accountsIds)
        {
            var bankAccounts = await AddBankAccounts(newProvider, provider.Id);

            accountsIds.AddRange(bankAccounts.Select(a => a.Id).ToList());
            provider.Accounts = accountsIds;
            await _providerRepository.UpdateProvider(provider.Id, provider);

            var accounts = await _accountService.UpdateBankAccountsForProvider(provider);

            foreach (var account in accounts)
            {
                await _bankAccountRepository.UpdateAccount(account.Id, account);
            }
            return(accounts);
        }
Exemplo n.º 14
0
        public async Task <IEnumerable <BankAccountDoc> > UpdateBankAccountsForProvider(ProviderDoc provider)
        {
            var result = new List <BankAccountDoc>();

            using (var dataProvider = await _providerFactory.CreateDataProvider(provider))
            {
                var accounts = ((IBankAccountProvider)dataProvider).GetAccounts();
                foreach (var accountId in provider.Accounts)
                {
                    var account = await UpdateBankAccount(accountId, accounts, dataProvider);

                    result.Add(account);
                }
            }

            return(result);
        }
Exemplo n.º 15
0
 private bool HasOutdatedCards(ProviderDoc provider)
 {
     return(_cardRepository.GetCardsByProviderId(provider.Id).Result.ToList()
            .Any(a => a.UpdatedOn.AddHours(AccountService.UpdateInterval) < DateTime.Now));
 }