Ejemplo n.º 1
0
        public async Task <PaymentResponse> ProcessAsync(PaymentRequest request)
        {
            var validator = new PaymentValidation();
            var failures  = validator.Validate(request);

            if (!failures.IsValid)
            {
                _logger.LogWarning("Validation errors - PaymentProcessor : {@request} - Errors: {@ValidationErrors}", request, failures.Errors);

                throw new PaymentApiException(string.Join(",", failures.Errors));
            }

            var response = await _acquiringBankAdapter.SendRequestAsync(request);

            var command = _mapper.Map <CreatePaymentCommand>(request);

            command.TransactionId    = response.TransactionId;
            command.PaymentStatus    = response.PaymentStatus;
            command.ErrorDescription = response.ErrorDescription;

            await _commandHandler.Handle(command);

            return(new PaymentResponse()
            {
                Status = response.PaymentStatus,
                PaymentResultId = command.Id,
                ErrorDescription = response.ErrorDescription
            });
        }
Ejemplo n.º 2
0
        public IActionResult ConfirmPayment(PaymentModel Payment)
        {
            PaymentValidation paymentValidation = new PaymentValidation();
            ValidationResult  result            = paymentValidation.Validate(Payment);

            if (result.IsValid)
            {
                var cart = SessionHelper.GetObjectFromJson <List <ProductModel> >(HttpContext.Session, "cart");

                var ConfirmPayment = new ConfirmPaymentModel();

                ConfirmPayment.Product = cart;
                ConfirmPayment.Payment = Payment;

                if (ConfirmPayment != null)
                {
                    return(View(ConfirmPayment));
                }
            }
            else
            {
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                }
            }
            return(View(nameof(Checkout), Payment));
        }
Ejemplo n.º 3
0
        public override bool IsValid()
        {
            ValidationResult results = new PaymentValidation().Validate(this);

            if (!results.IsValid)
            {
                foreach (var failure in results.Errors)
                {
                    AddErro(failure.PropertyName, failure.ErrorMessage);
                }
            }
            return(results.IsValid);
        }
        /// <summary>
        /// This method represents Make card payment
        /// </summary>
        /// <param name="cardPaymentModel"></param>
        /// <returns></returns>
        public PaymentStatus MakeCardPayment(CardPaymentModel cardPaymentModel)
        {
            PaymentValidation.ValidateCardPayment(cardPaymentModel);
            var unEncryptedCardNumber = cardPaymentModel.CardNumber;
            var suffixCardNumber      = unEncryptedCardNumber.Substring(unEncryptedCardNumber.Length - 4, 4);
            var preFixCard            = unEncryptedCardNumber.Substring(0, unEncryptedCardNumber.Length - 4);
            var encryptedCardNumber   = AesOperation.EncryptString(this._appSettings.Key, suffixCardNumber);
            var encryptedCvvNumber    = AesOperation.EncryptString(this._appSettings.Key, cardPaymentModel.Cvvnumber);

            string errorMessage;

            var cardDetailsList = this.cardPaymentRepository.Query();
            var cardPayment     = (from cardDetail in cardDetailsList
                                   where cardDetail.CardNumber == (encryptedCardNumber + suffixCardNumber) && cardDetail.Cvvnumber == encryptedCvvNumber && cardDetail.ExpiryDate == cardPaymentModel.ExpiryDate
                                   select cardDetail).FirstOrDefault();

            return(CompleteCardPament(cardPaymentModel, cardPayment));
        }
Ejemplo n.º 5
0
 public override bool IsValid()
 {
     ValidationResult = new PaymentValidation().Validate(this);
     return(ValidationResult.IsValid);
 }
Ejemplo n.º 6
0
        public ValidationResult Validate()
        {
            var validationResult = new PaymentValidation().Validate(this);

            return(validationResult);
        }