Пример #1
0
        public async Task <IActionResult> GetCardByPan(string pan)
        {
            var hashedPan = _panHashService.HashPan(pan);
            var card      = await _cardDomainRepository.GetCardByHashedPan(hashedPan);

            if (card == null)
            {
                return(NotFound());
            }

            return(Ok(new GetCardResponse(card)));
        }
        public async Task <decimal?> CreditCardPurchase(string pan, decimal amount)
        {
            var hashedPan = _panHashService.HashPan(pan);
            var card      = await _cardDomainRepository.GetCardByHashedPan(hashedPan);

            if (card == null)
            {
                return(null);
            }

            var account = await _accountDomainRepository.GetAccountById(card.State.AccountId);

            account.AddEvent(new AccountDebitedEvent
            {
                Amount = amount
            });

            await _accountDomainRepository.SaveAccount(account);

            return(account.State.Balance);
        }