Beispiel #1
0
        public async Task <Guid> Handle(SavePaymentCommand request, CancellationToken cancellationToken)
        {
            var payment = _mapper.Map <Payment>(request.Payment);

            var guid = await _repository.CreatePayment(payment);

            await _repository.SaveAsync(cancellationToken);

            return(guid);
        }
        public IActionResult Create(
            [Bind("Id,CredictCard,OwnerName,OwnerSurname,SecurityCode,ExpiryMonth,ExpiryYear")]
            Payment payment)
        {
            var userId = _userManager.GetUserId(User);

            if (!ModelState.IsValid)
            {
                return(View(payment));
            }

            var paymentId = _paymentsRepository.CreatePayment(userId, payment);

            return(RedirectToAction("Details", "Payments", new { id = paymentId }));
        }
Beispiel #3
0
        public async Task <PaymentResponse> CreatePayment(PaymentRequest paymentRequest)
        {
            if (paymentRequest == null)
            {
                return(null);
            }

            var payment = _mapper.Map <Payment>(paymentRequest);

            payment.Status = PaymentStatus.Captured;

            payment = await _paymentsRepo.CreatePayment(payment);

            var bankRequest = _mapper.Map <BankPaymentRequest>(paymentRequest);

            try
            {
                var bankResponse = await _bankRepo.ProcessCardPost(bankRequest);

                if (bankResponse != null)
                {
                    payment.Approved     = bankResponse.Approved;
                    payment.AuthCode     = bankResponse.AuthCode;
                    payment.Status       = bankResponse.Approved ? PaymentStatus.Authorized : PaymentStatus.Declined;
                    payment.ResponseCode = bankResponse.ResponseCode;
                }

                payment = await _paymentsRepo.UpdatePaymentStatus(payment.Id, payment.Approved, payment.AuthCode, payment.Status, payment.ResponseCode);
            }
            catch (HttpRequestException e)
            {
                _logger.LogError($"Payment Failed - {e.Message}");
                payment.Approved = false;
                payment.Status   = PaymentStatus.Failed;
                payment          = await _paymentsRepo.UpdatePaymentStatus(payment.Id, payment.Approved, payment.AuthCode, payment.Status, null);
            }

            var response = _mapper.Map <PaymentResponse>(payment);

            return(response);
        }
 public List <Payment> CreatePayment(int PaymentNumber, string Status)
 {
     return(_repository.CreatePayment(PaymentNumber, Status));
 }