Beispiel #1
0
        public async Task <TransactionDto> GetPaymentDetails(string clientId, string paymentId)
        {
            var merchant = await merchantRepository.Get(clientId);

            var transaction = await paymentRepository.Get(paymentId, merchant.Id);

            return(mapper.Map <TransactionDto>(transaction));
        }
        public MerchantDetailsDto GetDetails(int id)
        {
            var merchant = _repository.Get(id);
            var dto      = AutoMapperHelper.Map <Merchant, MerchantDetailsDto>(merchant);

            return(dto);
        }
Beispiel #3
0
        public Fee Handle(CalculateFee command)
        {
            var merchant = _merchantRepository.Get(command.Transaction.MerchantName);

            if (merchant == null)
            {
                throw new DomainObjectNotFoundException($"Merchant {command.Transaction.MerchantName} not found");
            }

            var standardFee = _calculateFeeHandler.Handle(command);

            return(merchant.ApplyTransactionPercentageFeeDiscount(standardFee));
        }
        public async Task <Payment> Process(Payment payment)
        {
            var dbPayment = await _paymentRepository.GetByIdempotencyId(payment.IdempotencyId);

            if (dbPayment != null)
            {
                _logger.LogWarning($"IDEMPOTENT :: An identical request was already made for this Payment (Id - {dbPayment.Id}");
                return(dbPayment);
            }

            var dbMerchant = await _merchantRepository.Get(payment.MerchantId);

            if (dbMerchant == null)
            {
                throw new BusinessException(
                          BusinessExceptionCodes.MerchantHasNoContract,
                          "This Merchant has no contract with us, therefore we cannot accept payment requests.");
            }

            var paymentValidator = new PaymentValidator();
            var validationResult = paymentValidator.Validate(payment);

            HandleErrors.HandleValidatorResult(validationResult);

            var transactionResults = await _bankApiClient.PostTransaction(payment);

            payment.Id                = Guid.NewGuid();
            payment.Status            = transactionResults.Status;
            payment.BankTransactionId = transactionResults.BankTransactionId;
            payment.HasError          = payment.Status != PaymentStatus.Approved;
            payment.ErrorCode         = transactionResults.ErrorCode;
            payment.ErrorMessage      = transactionResults.Message;
            payment.CreatedOn         = DateTime.UtcNow;
            payment.UpdatedOn         = DateTime.UtcNow;

            return(await _paymentRepository.Add(payment));
        }
Beispiel #5
0
 public async Task <Merchant> Get(Guid id)
 {
     return(await _merchantRepository.Get(id));
 }
Beispiel #6
0
 public List <Merchant> Get()
 {
     return(_merchantRepository.Get());
 }