public void GeneratePackingSlipForRoyaltyAndCommissionPayment_Test()
        {
            PaymentDetailsDto paymentDetailsDto = new PaymentDetailsDto();

            paymentDetailsDto.ProductType = ProductEnum.PhysicalProduct;
            paymentDetailsDto.ProductDto  = new ProductDto
            {
                Price     = 1200,
                ProductId = 1
            };
            paymentDetailsDto.AgentDto = new AgentDto
            {
                AgentId   = 200,
                AgentName = "John Miller"
            };

            IAction packingSlip       = new PackingSlipForRoyalty(paymentDetailsDto);
            string  packingSlipResult = packingSlip.DoProcess();

            Assert.IsNotNull(packingSlipResult);

            IAction commissionPayment       = new CommissionPayment(paymentDetailsDto);
            string  commissionPaymentResult = commissionPayment.DoProcess();

            Assert.IsNotNull(commissionPaymentResult);
        }
        public void ActionsForMembershipUpgrade_Test()
        {
            PaymentDetailsDto paymentDetailsDto = new PaymentDetailsDto();

            paymentDetailsDto.ProductType   = ProductEnum.UpgradeMembership;
            paymentDetailsDto.MembershipDto = new MembershipDto
            {
                MembershipId   = 10001,
                MembershipName = "Prime Membership"
            };
            paymentDetailsDto.CustomerDto = new CustomerDto
            {
                CustomerEmail = "*****@*****.**",
                CustomerId    = 120,
                CustomerName  = "Vithal Deshpande"
            };

            var actions = ActionFactory.CreateActions(paymentDetailsDto);

            Assert.IsTrue(actions.Count == 2); // membership upgrade and sending email

            foreach (var action in actions)
            {
                Assert.IsNotNull(action.DoProcess());
            }
        }
        public void UpgradeMembershipAndSendEmail_Test()
        {
            PaymentDetailsDto paymentDetailsDto = new PaymentDetailsDto();

            paymentDetailsDto.ProductType   = ProductEnum.UpgradeMembership;
            paymentDetailsDto.MembershipDto = new MembershipDto
            {
                MembershipId   = 10001,
                MembershipName = "Prime Membership"
            };
            paymentDetailsDto.CustomerDto = new CustomerDto
            {
                CustomerEmail = "*****@*****.**",
                CustomerId    = 120,
                CustomerName  = "Vithal Deshpande"
            };
            IAction upgradeMemberShip = new MemberShipUpgradation(paymentDetailsDto);
            string  result            = upgradeMemberShip.DoProcess();

            Assert.IsNotNull(result);

            IAction emailService       = new EmailService(paymentDetailsDto);
            string  emailServiceResult = emailService.DoProcess();

            Assert.IsNotNull(emailServiceResult);
        }
        public async Task <int> ProcessPayment(PaymentDetailsDto paymentDetails)
        {
            var isCardValid = await IsValidCard(paymentDetails.CardNumber);

            if (!isCardValid)
            {
                LogEvent(new LogDto {
                    LogType = LogTypeEnum.ValidationFailure, Message = "Invalid card number"
                });
                throw new ArgumentException("Card number is invalid");
            }

            LogEvent(new LogDto {
                LogType = LogTypeEnum.ValidationSuccess, Message = "Valid card number"
            });

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                var postBody     = new StringContent(JsonConvert.SerializeObject(paymentDetails), System.Text.Encoding.UTF8, "application/json");
                var postResponse = await client.PostAsync("https://localhost:44399/api/Payment/", postBody);

                var responseStr = await postResponse.Content.ReadAsStringAsync();

                return(int.Parse(responseStr));
            }
        }
        public static List <IAction> CreateActions(PaymentDetailsDto productDto)
        {
            List <IAction> Actions = new List <IAction>();

            switch (productDto.ProductType)
            {
            case ProductEnum.ActivateMembership:
                Actions.Add(new MemberShipActivation(productDto));
                Actions.Add(new EmailService(productDto));
                break;

            case ProductEnum.UpgradeMembership:
                Actions.Add(new MemberShipUpgradation(productDto));
                Actions.Add(new EmailService(productDto));
                break;

            case ProductEnum.Book:
                Actions.Add(new PackingSlipForRoyalty(productDto));
                Actions.Add(new CommissionPayment(productDto));
                break;

            case ProductEnum.PhysicalProduct:
                Actions.Add(new PackingSlipForShipping(productDto));
                Actions.Add(new CommissionPayment(productDto));
                break;

            case ProductEnum.Video:
                Actions.Add(new Video(productDto));
                break;
            }

            return(Actions);
        }
        public void ActionsForBook_Test()
        {
            PaymentDetailsDto paymentDetailsDto = new PaymentDetailsDto();

            paymentDetailsDto.ProductType = ProductEnum.Book;
            paymentDetailsDto.ProductDto  = new ProductDto
            {
                Price     = 1000,
                ProductId = 1
            };

            var actions = ActionFactory.CreateActions(paymentDetailsDto);

            Assert.IsTrue(actions.Count == 2); // one of packing slip for shipping and agent payment generation

            paymentDetailsDto.AgentDto = new AgentDto
            {
                AgentId   = 200,
                AgentName = "John Miller"
            };
            foreach (var action in actions)
            {
                Assert.IsNotNull(action.DoProcess());
            }
        }
Example #7
0
        public void ValidatePaymentDetailsDto_ShouldReturnCorrectBool(int orderNumber, double amount, bool expected)
        {
            var paymentDetails = new PaymentDetailsDto {
                OrderNumber = orderNumber, PayableAmount = amount
            };

            var actual = PayloadValidator.ValidatePaymentDetailsDto(paymentDetails);

            Assert.Equal(expected, actual);
        }
        public bool Post([FromBody] PaymentDetailsDto paymentDetails)
        {
            // Example invalid card number - 0000 0000 0000 0000
            if (paymentDetails.CardNumber == "0000000000000000")
            {
                return(false);
            }

            return(true);
        }
Example #9
0
        public async Task <ActionResult <int> > PostPayment(string apiKey, [FromBody] PaymentDetailsDto paymentDetails)
        {
            if (!_service.IsValidApiKey(apiKey))
            {
                return(BadRequest("Invalid API key"));
            }

            var paymentId = await _service.ProcessPayment(paymentDetails);

            return(Ok(paymentId));
        }
 private Models.Database.Payment CreateNewPayment(PaymentDetailsDto paymentDetails)
 {
     return(new Models.Database.Payment
     {
         Amount = paymentDetails.Amount,
         Currency = paymentDetails.Currency,
         Cvv = paymentDetails.Cvv,
         ExpiryDate = paymentDetails.ExpiryDate,
         MaskedCardNumber = paymentDetails.CardNumber.Substring(paymentDetails.CardNumber.Length - 4),
         PaymentStatus = PaymentStatusEnum.Pending
     });
 }
        public async Task <ActionResult <int> > ProcessPayment([FromBody] PaymentDetailsDto paymentDetails)
        {
            try
            {
                var newPaymentId = await _service.ProcessPaymentAsync(paymentDetails);

                return(Ok(newPaymentId));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        public async Task <PaymentDetailsDto> GetPaymentDetails(string paymentIdentifier, Merchant currentUser)
        {
            PaymentDetails payment = await repository.GetPaymentDetails(paymentIdentifier, currentUser);

            if (payment == null)
            {
                return(null);
            }

            PaymentDetailsDto paymentDto = paymentMapper.MapToPaymentDetailsDto(payment);

            return(paymentDto);
        }
Example #13
0
        public static PaymentProcessingService GetPaymentProcessingServiceForVideo()
        {
            PaymentDetailsDto paymentDetailsDto = new PaymentDetailsDto();

            paymentDetailsDto.ProductType = ProductEnum.Video;
            paymentDetailsDto.ProductDto  = new ProductDto
            {
                Price     = 2345,
                ProductId = 55
            };


            return(new PaymentProcessingService(paymentDetailsDto));
        }
        public void VideoPayment_Test()
        {
            PaymentDetailsDto paymentDetailsDto = new PaymentDetailsDto();

            paymentDetailsDto.ProductType          = ProductEnum.Video;
            paymentDetailsDto.ProductDto           = new ProductDto();
            paymentDetailsDto.ProductDto.ProductId = 101;
            paymentDetailsDto.ProductDto.Price     = 200;

            IAction videoPayment = new Video(paymentDetailsDto);
            string  result       = videoPayment.DoProcess();

            Assert.IsNotNull(result);
        }
Example #15
0
        public static bool ValidatePaymentDetailsDto(PaymentDetailsDto payload)
        {
            var isValid = true;
            var errors  = new List <string>();

            ValidateInteger(payload.OrderNumber, "Order Number", errors);
            ValidatePayableAmount(payload.PayableAmount, errors);

            if (errors.Count() > 0)
            {
                isValid = false;
            }
            return(isValid);
        }
        public void GeneratePackingSlipForRoyalty_Test()
        {
            PaymentDetailsDto paymentDetailsDto = new PaymentDetailsDto();

            paymentDetailsDto.ProductType = ProductEnum.Book;
            paymentDetailsDto.ProductDto  = new ProductDto
            {
                Price     = 1200,
                ProductId = 1
            };

            IAction packingSlip = new PackingSlipForRoyalty(paymentDetailsDto);
            string  result      = packingSlip.DoProcess();

            Assert.IsNotNull(result);
        }
        public void SendEmail_Test()
        {
            PaymentDetailsDto paymentDetailsDto = new PaymentDetailsDto();

            paymentDetailsDto.CustomerDto = new CustomerDto
            {
                CustomerEmail = "*****@*****.**",
                CustomerId    = 120,
                CustomerName  = "Vithal Deshpande"
            };

            IAction emailService       = new EmailService(paymentDetailsDto);
            string  emailServiceResult = emailService.DoProcess();

            Assert.IsNotNull(emailService);
        }
        public void UpgradeMembership_Test()
        {
            PaymentDetailsDto paymentDetailsDto = new PaymentDetailsDto();

            paymentDetailsDto.ProductType   = ProductEnum.UpgradeMembership;
            paymentDetailsDto.MembershipDto = new MembershipDto
            {
                MembershipId   = 10001,
                MembershipName = "Prime Membership"
            };

            IAction upgradeMemberShip = new MemberShipUpgradation(paymentDetailsDto);
            string  result            = upgradeMemberShip.DoProcess();

            Assert.IsNotNull(result);
        }
        //GET: /api/Payments/Get/{paymentIdentifier}
        public async Task <ActionResult <PaymentDetailsDto> > Get([FromRoute] string paymentIdentifier)
        {
            ClaimsPrincipal currentUser     = this.User;
            var             currentUserName = currentUser.FindFirst("login").Value;
            var             user            = await _userManager.FindByNameAsync(currentUserName);

            PaymentDetailsDto paymentDetailsDto = await paymentService.GetPaymentDetails(paymentIdentifier, user);

            if (paymentDetailsDto != null)
            {
                return(Ok(paymentDetailsDto));
            }
            else
            {
                return(NotFound(new { message = "Payment with given identifier was not found." }));
            }
        }
Example #20
0
        public static PaymentProcessingService GetPaymentProcessingServiceForBook()
        {
            PaymentDetailsDto paymentDetailsDto = new PaymentDetailsDto();

            paymentDetailsDto.ProductType = ProductEnum.Book;
            paymentDetailsDto.ProductDto  = new ProductDto
            {
                Price     = 1200,
                ProductId = 1
            };
            paymentDetailsDto.AgentDto = new AgentDto
            {
                AgentId   = 200,
                AgentName = "John Miller"
            };

            return(new PaymentProcessingService(paymentDetailsDto));
        }
Example #21
0
        public static PaymentProcessingService GetPaymentProcessingServiceForMembershipUpgradation()
        {
            PaymentDetailsDto paymentDetailsDto = new PaymentDetailsDto();

            paymentDetailsDto.ProductType   = ProductEnum.UpgradeMembership;
            paymentDetailsDto.MembershipDto = new MembershipDto
            {
                MembershipId   = 10001,
                MembershipName = "Prime Membership"
            };
            paymentDetailsDto.CustomerDto = new CustomerDto
            {
                CustomerEmail = "*****@*****.**",
                CustomerId    = 120,
                CustomerName  = "Vithal Deshpande"
            };

            return(new PaymentProcessingService(paymentDetailsDto));
        }
        public void ActionsForVideoPayment_Test()
        {
            PaymentDetailsDto paymentDetailsDto = new PaymentDetailsDto();

            paymentDetailsDto.ProductType          = ProductEnum.Video;
            paymentDetailsDto.ProductDto           = new ProductDto();
            paymentDetailsDto.ProductDto.ProductId = 101;
            paymentDetailsDto.ProductDto.Price     = 200;

            var actions = ActionFactory.CreateActions(paymentDetailsDto);

            Assert.IsTrue(actions.Count == 1); // sending free video


            foreach (var action in actions)
            {
                Assert.IsNotNull(action.DoProcess());
            }
        }
        public async Task <int> ProcessPaymentAsync(PaymentDetailsDto paymentDetails)
        {
            // Save payment details
            var newPaymentDetails = CreateNewPayment(paymentDetails);

            _repository.AddPayment(newPaymentDetails);

            // Send request to bank
            var client = new HttpClient();

            client.DefaultRequestHeaders.Accept.Clear();
            var postBody     = new StringContent(JsonConvert.SerializeObject(paymentDetails), System.Text.Encoding.UTF8, "application/json");
            var postResponse = await client.PostAsync("https://localhost:44378/api/MockBank/", postBody);

            // Update details with response
            UpdatePaymentStatus(newPaymentDetails.PaymentId, postResponse.IsSuccessStatusCode);

            // Return payment ID
            return(newPaymentDetails.PaymentId);
        }
        public void GenerateCommissionPaymentToAgent_Test()
        {
            PaymentDetailsDto paymentDetailsDto = new PaymentDetailsDto();

            paymentDetailsDto.ProductType = ProductEnum.PhysicalProduct;
            paymentDetailsDto.ProductDto  = new ProductDto
            {
                Price     = 1200,
                ProductId = 1
            };
            paymentDetailsDto.AgentDto = new AgentDto
            {
                AgentId   = 200,
                AgentName = "John Miller"
            };

            IAction commissionPayment = new CommissionPayment(paymentDetailsDto);
            string  result            = commissionPayment.DoProcess();

            Assert.IsNotNull(result);
        }
Example #25
0
        public void PaymentProcessIntegrationTest()
        {
            PaymentDetailsDto paymentDetailsDto = new PaymentDetailsDto();

            paymentDetailsDto.ProductType = ProductEnum.PhysicalProduct;
            paymentDetailsDto.ProductDto  = new ProductDto
            {
                Price     = 1200,
                ProductId = 1
            };

            paymentDetailsDto.AgentDto = new AgentDto
            {
                AgentId   = 200,
                AgentName = "John Miller"
            };

            PaymentProcessingService paymentProcessingService = new PaymentProcessingService(paymentDetailsDto);

            paymentProcessingService.ProcessPayment();
        }
 public PaymentProcessingService(PaymentDetailsDto productDto)
 {
     actions = ActionFactory.CreateActions(productDto);
 }
 public PackingSlipForRoyalty(PaymentDetailsDto paymentDetailsDto)
 {
     this.paymentDetailsDto = paymentDetailsDto;
 }
        public IActionResult ProcessSwedbankPayment([FromBody] PaymentDetailsDto value)
        {
            var isValidDto = PayloadValidator.ValidatePaymentDetailsDto(value);

            return(isValidDto ? StatusCode(200) : StatusCode(400));
        }
Example #29
0
 public EmailService(PaymentDetailsDto paymentDetailsDto)
 {
     this.paymentDetailsDto = paymentDetailsDto;
 }
 public PackingSlipForShipping(PaymentDetailsDto paymentDetailsDto)
 {
     this.paymentDetailsDto = paymentDetailsDto;
 }