コード例 #1
0
        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);
        }
コード例 #2
0
        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());
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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));
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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());
            }
        }
コード例 #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);
        }
コード例 #8
0
        public bool Post([FromBody] PaymentDetailsDto paymentDetails)
        {
            // Example invalid card number - 0000 0000 0000 0000
            if (paymentDetails.CardNumber == "0000000000000000")
            {
                return(false);
            }

            return(true);
        }
コード例 #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));
        }
コード例 #10
0
 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
     });
 }
コード例 #11
0
        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));
            }
        }
コード例 #12
0
        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);
        }
コード例 #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));
        }
コード例 #14
0
        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);
        }
コード例 #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);
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        //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." }));
            }
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #22
0
        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());
            }
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        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);
        }
コード例 #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();
        }
コード例 #26
0
 public PaymentProcessingService(PaymentDetailsDto productDto)
 {
     actions = ActionFactory.CreateActions(productDto);
 }
コード例 #27
0
 public PackingSlipForRoyalty(PaymentDetailsDto paymentDetailsDto)
 {
     this.paymentDetailsDto = paymentDetailsDto;
 }
コード例 #28
0
        public IActionResult ProcessSwedbankPayment([FromBody] PaymentDetailsDto value)
        {
            var isValidDto = PayloadValidator.ValidatePaymentDetailsDto(value);

            return(isValidDto ? StatusCode(200) : StatusCode(400));
        }
コード例 #29
0
 public EmailService(PaymentDetailsDto paymentDetailsDto)
 {
     this.paymentDetailsDto = paymentDetailsDto;
 }
コード例 #30
0
 public PackingSlipForShipping(PaymentDetailsDto paymentDetailsDto)
 {
     this.paymentDetailsDto = paymentDetailsDto;
 }