private void CreateTestObject()
        {
            _paymentRequest = new PaymentRequest()
            {
                Amount          = 900,
                Currency        = "EUR",
                CardInformation = new CardInformation()
                {
                    CardNumber  = "1111222233334444",
                    ExpiryMonth = 12,
                    ExpiryYear  = 2021,
                    Cvv         = 123
                }
            };

            _paymentRequest2 = new PaymentRequest()
            {
                Amount          = 1500,
                Currency        = "EUR",
                CardInformation = new CardInformation()
                {
                    CardNumber  = "1111222233334444",
                    ExpiryMonth = 12,
                    ExpiryYear  = 2021,
                    Cvv         = 123
                }
            };

            _successfulPaymentResponse = new PaymentResponse()
            {
                PaymentId = new Guid("10013B70-6182-48E7-8222-1E14EBF86000"),
                Message   = "Successful",
                Status    = true
            };

            _unsuccessfulPaymentResponse = new PaymentResponse()
            {
                PaymentId = new Guid("10013B70-6182-48E7-8222-1E14EBF86111"),
                Message   = "Unsuccessful",
                Status    = false
            };

            _paymentResponseFromRepo = new PaymentEntity()
            {
                Amount   = 899,
                CardId   = 1,
                Code     = new Guid("10013B70-6182-48E7-8222-1E14EBF866CF"),
                Currency = "EUR",
                Message  = "Successful",
                Status   = true
            };

            _cardInformation = new CardInformationEntity()
            {
                CardNumber  = "1111222233334444",
                Cvv         = 123,
                ExpiryMonth = 12,
                ExpiryYear  = 2022
            };
        }
        /// <summary>
        /// Saves credit card information into postgres db.
        /// If same card number exists in db, does not save a new one.
        /// </summary>
        public void SaveCardInformation(CardInformationEntity cardInfo)
        {
            var existingCardInfo = GetDbConenctor(_dbConnection).Query <CardInformationEntity>().Where(p => p.CardNumber == cardInfo.CardNumber).FirstOrDefault();

            if (existingCardInfo != null)
            {
                cardInfo.Id = existingCardInfo.Id;
            }
            else
            {
                GetDbConenctor(_dbConnection).Save(cardInfo);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Creates CardInformationEntity instance and map properties by parameters.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="paymentResponse"></param>
        /// <param name="cardId"></param>
        /// <returns>Returns CardInformationEntity object</returns>
        private CardInformationEntity MapToCardInfoEntity(PaymentRequest request)
        {
            _logger.LogInformation("PaymentService -> MapToCardInfoEntity started.");
            var cardInfo = new CardInformationEntity()
            {
                CardNumber  = request.CardInformation.CardNumber,
                ExpiryMonth = request.CardInformation.ExpiryMonth,
                ExpiryYear  = request.CardInformation.ExpiryYear,
                Cvv         = request.CardInformation.Cvv,
            };

            _logger.LogInformation("PaymentService -> MapToCardInfoEntity ends.");
            return(cardInfo);
        }
Esempio n. 4
0
        /// <summary>
        /// Get payment detail by PaymentId (unique value for payment)
        /// </summary>
        /// <param name="paymentId">PaymentId (unique value for payment)</param>
        /// <returns>Returns payment information details</returns>
        public PaymentInformation GetPayment(Guid paymentId)
        {
            _logger.LogInformation("PaymentService -> GetPayment started.");
            var paymentEntity = _paymentRepo.GetPayment(paymentId);
            CardInformationEntity cardInfoEntity = null;

            if (paymentEntity != null)
            {
                cardInfoEntity = _paymentRepo.GetCardInformation(paymentEntity.CardId);
            }
            else
            {
                throw new PaymentNotFoundException();
            }
            var paymentInfo = MapToPaymentInformation(paymentEntity, cardInfoEntity);

            _logger.LogInformation("PaymentService -> GetPayment ends.");
            return(paymentInfo);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates PaymentInformation instance and map properties by parameters.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="paymentResponse"></param>
        /// <param name="cardId"></param>
        /// <returns>Returns PaymentInformation object</returns>
        private PaymentInformation MapToPaymentInformation(PaymentEntity paymentEntity, CardInformationEntity cardInfoEntity)
        {
            _logger.LogInformation("PaymentService -> MapToPaymentInformation started.");
            var paymentInformation = new PaymentInformation()
            {
                CardInfo = new CardInformation()
                {
                    CardNumber  = MaskCardNumber(cardInfoEntity.CardNumber),
                    Cvv         = cardInfoEntity.Cvv,
                    ExpiryMonth = cardInfoEntity.ExpiryMonth,
                    ExpiryYear  = cardInfoEntity.ExpiryYear
                },
                Amount    = paymentEntity.Amount,
                Currency  = paymentEntity.Currency,
                PaymentId = paymentEntity.Code,
                Status    = paymentEntity.Status,
                Message   = paymentEntity.Message
            };

            _logger.LogInformation("PaymentService -> MapToPaymentInformation ends.");
            return(paymentInformation);
        }