Ejemplo n.º 1
0
 public ValidateScan(ICheckBalance checkBalance, ICheckTerminal checkTerminal, IProcessPayment processPayment, INewCardScanned newCardScanned)
 {
     _checkTerminal  = checkTerminal;
     _checkBalance   = checkBalance;
     _processPayment = processPayment;
     _newCardScanned = newCardScanned;
 }
Ejemplo n.º 2
0
        private IProcessPayment GetPaymentProcess(int productType)
        {
            // based on product type, generate process class.
            switch (productType)
            {
            case 0:
                _processPayment = new PhysicalProductPaymentProcess();
                return(_processPayment);

            case 1:
                _processPayment = new BookPaymentProcess();
                return(_processPayment);

            case 2:
                _processPayment = new MemberPaymentProcess();
                return(_processPayment);

            case 3:
                _processPayment = new UpgradeMembershipPaymentProcess();
                return(_processPayment);

            case 4:
                _processPayment = new VideoTrainingPaymentProcess();
                return(_processPayment);

            default:
                return(null);
            }
        }
        public async Task <IActionResult> ProceedPaymentRequest([FromBody] PaymentRequest paymentRequest,
                                                                [FromServices] IGenerateGuid gatewayPaymentIdGenerator,
                                                                [FromServices] IKnowAllPaymentRequests paymentRequestsRepository,
                                                                [FromServices] IProcessPayment paymentProcessor)
        {
            var gatewayPaymentId = gatewayPaymentIdGenerator.Generate();

            var commandResult = await _commandHandler.Handle(paymentRequest.AsCommand(gatewayPaymentId));

            switch (commandResult)
            {
            case SuccessCommandResult <Payment> success:
                var paymentDto = success.Entity.AsDto();

                return(AcceptedAtRoute(nameof(PaymentReadController.GetPaymentInfo),
                                       routeValues: new { gateWayPaymentId = paymentDto.GatewayPaymentId },
                                       value: paymentDto));

            case InvalidCommandResult invalid:
                return(ActionResultHelper.ToActionResult(invalid));

            case FailureCommandResult failure:
                return(ActionResultHelper.ToActionResult(failure));


            default:
                throw new NotSupportedException();
            }
        }
Ejemplo n.º 4
0
        public void TestPhysicalPaymentProcess()
        {
            PhysicalPaymentProcess = new PhysicalProductPaymentProcess();
            Assert.AreNotEqual(null, PhysicalPaymentProcess);

            string result = PhysicalPaymentProcess.PaymentProcess(order, paymentAmount);

            Assert.AreEqual("success", result);
        }
Ejemplo n.º 5
0
        public void TestBookPaymentProcess()
        {
            bookPaymentProcess = new BookPaymentProcess();
            Assert.AreNotEqual(null, bookPaymentProcess);

            string result = bookPaymentProcess.PaymentProcess(order, paymentAmount);

            Assert.AreEqual("success", result);
        }
Ejemplo n.º 6
0
        public void NewMemberShipPaymentTest()
        {
            memberPaymentProcess = new MemberPaymentProcess();
            Assert.AreNotEqual(null, memberPaymentProcess);

            string result = memberPaymentProcess.PaymentProcess(order, paymentAmount);

            Assert.IsNotEmpty(result);
            Assert.AreEqual("success", result);
        }
Ejemplo n.º 7
0
 public PaymentRequestCommandHandler(IEventSourcedRepository <Payment> repository,
                                     IKnowAllPaymentRequests paymentRequestsMemory,
                                     IProcessPayment paymentProcessor,
                                     IMapMerchantToBankAdapter bankAdapterMapper,
                                     IKnowSendRequestToBankSynchrony synchronyMaster, ILogger <PaymentRequestCommandHandler> logger)
 {
     _repository            = repository;
     _paymentRequestsMemory = paymentRequestsMemory;
     _paymentProcessor      = paymentProcessor;
     _bankAdapterMapper     = bankAdapterMapper;
     _synchronyMaster       = synchronyMaster;
     _logger = logger;
 }
Ejemplo n.º 8
0
        public RabbitMQPaymentConsumer(IRabbitMQPaymentMessageSender rabbitMQPaymentMessageSender,
                                       IProcessPayment processPayment)
        {
            _processPayment = processPayment;
            _rabbitMQPaymentMessageSender = rabbitMQPaymentMessageSender;
            var factory = new ConnectionFactory
            {
                HostName = "localhost",
                UserName = "******",
                Password = "******"
            };

            _connection = factory.CreateConnection();
            _channel    = _connection.CreateModel();
            _channel.QueueDeclare(queue: "orderpaymentprocesstopic", false, false, false, arguments: null);
        }
Ejemplo n.º 9
0
        public AzureServiceBusConsumer(IProcessPayment processPayment, IConfiguration configuration, IMessageBus messageBus)
        {
            _processPayment = processPayment;
            _configuration  = configuration;
            _messageBus     = messageBus;

            serviceBusConnectionString    = _configuration.GetValue <string>("ServiceBusConnectionString");
            subscriptionPayment           = _configuration.GetValue <string>("OrderPaymentProcessSubscription");
            orderupdatepaymentresulttopic = _configuration.GetValue <string>("OrderUpdatePaymentResultTopic");
            orderPaymentProcessTopic      = _configuration.GetValue <string>("OrderPaymentProcessTopics");


            var client = new ServiceBusClient(serviceBusConnectionString);

            orderPaymentProcessor = client.CreateProcessor(orderPaymentProcessTopic, subscriptionPayment);
        }
Ejemplo n.º 10
0
        public string DoProcess(int type, string cname, string pname, double amount)
        {
            Order order = new Order();

            order.CreateDependencies(type, cname, pname);
            ProductType productType = order.ProductObj.Type;
            int         value       = (int)productType;

            // get payment prcess object.
            _processPayment = GetPaymentProcess(value);
            if (_processPayment != null)
            {
                // execute the process
                _processPayment.PaymentProcess(order, amount);
                return("processed");
            }
            else
            {
                return("Payment Not processed. Please select right product type");
            }
        }
Ejemplo n.º 11
0
 public PaymentProcessor(IProcessPayment directdebit, IProcessPayment standingOrder)
 {
     this.directdebit   = directdebit;
     this.standingOrder = standingOrder;
 }
Ejemplo n.º 12
0
 public Handler(IProcessPayment processor)
 {
     _processor = processor;
 }
Ejemplo n.º 13
0
 public void TakePayment(IProcessPayment paymentType, double amount)
 {
     paymentType.Process(amount);
 }
Ejemplo n.º 14
0
        public CreateFakeDatabaseContext()
        {
            string databaseName = Guid.NewGuid().ToString();

            _context = TestContextCreater.Create(databaseName);

            _context.Employees.Add(new Employee()
            {
                CardUid = "04346C824D5380",
                Balance = 10,
                Email   = "*****@*****.**"
            });

            _context.Employees.Add(new Employee()
            {
                CardUid = "99999999999999",
                Balance = 0,
                Email   = "*****@*****.**"
            });

            var terminals = new Faker <Terminal>()
                            .RuleFor(x => x.TerminalId, x => Guid.NewGuid().ToString())
                            .Generate(10);

            _context.Terminals.Add(new Terminal()
            {
                TerminalId = "04346C824D538012",
                ProductId  = 1
            });

            _context.Terminals.AddRange(terminals);

            var products = new Faker <Product>()
                           .RuleFor(x => x.ProductId, x => x.IndexFaker + 1)
                           .RuleFor(x => x.Productname, x => x.Commerce.ProductName())
                           .RuleFor(x => x.ProductDescription, x => x.Lorem.Sentence())
                           .RuleFor(x => x.ProductPrice, x => Convert.ToDecimal((x.Commerce.Price(0.5m, 2m))))
                           .RuleFor(x => x.Terminal, x => x.PickRandom(terminals))
                           .Generate(10);

            _context.Products.AddRange(products);

            var loggerFactory = new LoggerFactory();

            var getBalance = new GetBalance(_context);

            _checkBalance = new CheckBalance(getBalance, loggerFactory);

            var getProduct = new GetProduct(_context);

            _checkTerminal = new CheckTerminal(getProduct, loggerFactory);

            var writeTransaction = new WriteTransaction(_context, loggerFactory);

            _processPayment = new ProcessPayment(writeTransaction);

            var writeNewcard = new WriteNewCard(_context, loggerFactory);

            _newCardScanned = new NewCardScanned(writeNewcard, getProduct);

            _context.SaveChanges();
        }
Ejemplo n.º 15
0
 public PaymentController(IProcessPayment processPayment)
 {
     _processPayment = processPayment;
 }
Ejemplo n.º 16
0
 public PaymentController(IProcessPayment iPaymentHistoryRepository)
 {
     _iPaymentHistoryRepository = iPaymentHistoryRepository;
 }