示例#1
0
        /// <summary>
        /// All payment requests are processed and persisted. Bank Service mock respondes with the current  payment status
        /// </summary>
        /// <param name="paymentRequest">The requested payment as <see cref="PaymentRequest"/>.</param>
        /// <returns>The result of the payment processing as <see cref="PaymentResponse"/>.</returns>
        public async Task <PaymentResponse> ProcessPaymentAsync(
            PaymentRequest paymentRequest, CancellationToken cancellationToken)
        {
            PaymentAuthorizationResponse paymentAuthorizationResponse = null;
            var paymentAuthorizationRequest = new PaymentAuthorizationRequest(
                paymentRequest.CardNumber,
                paymentRequest.Expiry,
                paymentRequest.Amount,
                paymentRequest.Cvv,
                paymentRequest.Currency
                );

            paymentAuthorizationResponse = _bankService.AuthorizePayment(paymentAuthorizationRequest);

            var payment = new Core.Entities.Payment()
            {
                CardNumber    = MaskCardNumber(paymentRequest.CardNumber),
                Cvv           = paymentRequest.Cvv,
                Expiry        = paymentRequest.Expiry,
                Currency      = paymentRequest.Currency,
                Amount        = paymentRequest.Amount,
                SuccessStatus = paymentAuthorizationResponse.SuccessStatus
            };

            await _paymentRepository.AddAsync(payment, cancellationToken);

            return(new PaymentResponse(payment.Id, payment.SuccessStatus));
        }