Ejemplo n.º 1
0
        public PaymentResponse Create(PaymentRequest request)
        {
            _logger.LogDebug($"PaymentService.Create() request", request);

            // Validate payment request
            _paymentRequestValidator.ValidateAndThrow(request);

            // Send to payment provider
            var paymentResult = _cardPaymentProvider.RequestPayment(request);

            _logger.LogDebug($"CardPaymentProvider.RequestPayment() response", paymentResult);

            // Save payment infos in repo
            var payment = _repo.Create(
                new Entities.Payment(
                    paymentResult.PaymentId,
                    request.Card.Number.Mask(),
                    request.Card.ExpiryDate,
                    paymentResult.Status)
                );

            _logger.LogDebug($"PaymentRepo.Create() response", payment);

            return(_mapper.Map <PaymentResponse>(payment));
        }