Ejemplo n.º 1
0
        public void ShouldValidateEndDate([Values("1", "01", "8", "9")] string month, [Values("21", "21", "20", "20")] string year)
        {
            PaymentRequest request = GetValidPaymentRequest();

            request.ExpiryMonthDate = $"{month}/{year}";
            Assert.That(_validator.TryValidate(request, out string msg), Is.EqualTo(true));
            Assert.That(string.IsNullOrEmpty(msg));
        }
Ejemplo n.º 2
0
        public PaymentResponse ProcessPayment(PaymentRequest request)
        {
            try
            {
                _logger.LogInformation($"MerchantId:{request.MerchantId} MerchantPaymentRequestId:{request.MerchantPaymentRequestId} Validating request");

                if (!_registeredMerchants.ContainsKey(request.MerchantId))
                {
                    _logger.LogWarning($"MerchantId:{request.MerchantId} MerchantPaymentRequestId:{request.MerchantPaymentRequestId} Merchant Unregisterd");
                    return(new PaymentResponse {
                        status = false, Message = "Merchant Unregistered", MerchantId = request.MerchantId
                    });
                }

                if (!_paymentRequestValidator.TryValidate(request, out string msg))
                {
                    return(new PaymentResponse {
                        status = false, Message = msg, MerchantId = request.MerchantId
                    });
                }

                _logger.LogInformation($"MerchantId:{request.MerchantId} MerchantPaymentRequestId:{request.MerchantPaymentRequestId} Processing request");

                Guid paymentId = Guid.NewGuid();
                TransactionResponse txResponse = _bankClient.ProcessTransaction(new TransactionRequest
                {
                    Amount             = request.Amount,
                    CardNumber         = request.CardNumber,
                    Ccy                = request.Ccy,
                    CVV                = request.CVV,
                    ExpiryMonthDate    = request.ExpiryMonthDate,
                    PaymentGatewayTxId = paymentId,
                    MerchantName       = _registeredMerchants[request.MerchantId]
                }
                                                                                );

                _logger.LogInformation($"MerchantId:{request.MerchantId} MerchantPaymentRequestId:{request.MerchantPaymentRequestId} Storing payment response from bank");
                _processedPaymentCache[new ProcessedPaymentKey(request.MerchantId, paymentId)] = new ProcessedPaymentDetails
                {
                    Amount                   = request.Amount,
                    Cvv                      = request.CVV,
                    Ccy                      = request.Ccy,
                    ExpiryMonthDate          = request.ExpiryMonthDate,
                    MerchantId               = request.MerchantId,
                    Status                   = txResponse.Status,
                    CheckoutTransactionId    = paymentId,
                    MerchantPaymentRequestId = request.MerchantPaymentRequestId,
                    //Masking CardNumber here in case crash damp is access wherein complete card numbere may be accessible
                    CardNumber         = MaskPaymentCardNumber(request.CardNumber),
                    PaymentGatewayTxId = paymentId,
                    BankTransactionId  = txResponse.BankTransactionId,
                    Message            = txResponse.Message
                };


                _logger.LogInformation($"MerchantId:{request.MerchantId} MerchantPaymentRequestId:{request.MerchantPaymentRequestId} Processing complete");
                return(new PaymentResponse
                {
                    status = txResponse.Status,
                    MerchantId = request.MerchantId,
                    TransactionId = txResponse.BankTransactionId,
                    PaymentGatewayTxId = paymentId,
                    Message = txResponse.Message,
                    MerchantPaymentRequestId = request.MerchantPaymentRequestId
                });
            }
            catch (Exception e)
            {
                _logger.LogError($"MerchantId:{request.MerchantId} MerchantPaymentRequestId:{request.MerchantPaymentRequestId} Error processing request", e);
                throw;
            }
        }