public CreditCardController(IUnityContainer container, ICheapPaymentGateway cheapPayment, IExpensivePaymentGateway expensivePayment, IPremiumPaymentGateway premiumPayment)
 {
     this.container               = container;
     this.cheapPaymentGateway     = cheapPayment;
     this.expensivePaymentGateway = expensivePayment;
     this.premiumPaymentGateway   = premiumPayment;
 }
Ejemplo n.º 2
0
 public PaymentService(ICheapPaymentGateway cheapPaymentGateway, IExpensivePaymentGateway expensivePaymentGateway, IPremiumPaymentGateway premiumPaymentGateway, IUnitOfWork unitOfWork)
 {
     _cheapPaymentGateway     = cheapPaymentGateway;
     _expensivePaymentGateway = expensivePaymentGateway;
     _premiumPaymentGateway   = premiumPaymentGateway;
     _unitOfWork = unitOfWork;
 }
 public ProcessPayment(ProcessPaymentsContext context, ICheapPaymentGateway iCheapPaymentGeteway, IExpensivePaymentGateway iExpensivePaymentGateway, IPremiumPaymentGateway iPremiumPaymentGeteway)
 {
     _context = context;
     _iCheapPaymentGeteway     = iCheapPaymentGeteway;
     _iExpensivePaymentGateway = iExpensivePaymentGateway;
     _iPremiumPaymentGeteway   = iPremiumPaymentGeteway;
 }
Ejemplo n.º 4
0
 public PaymentService(IUnitOfWork unitOfWork)
 {
     this.unitOfWork = unitOfWork;
     this.expensivePaymentGateway = new ExpensivePaymentGateway();
     this.cheapPaymentGateway     = new CheapPaymentGateway();
     this.premiumPaymentGateway   = new PremiumPaymentGateway();
 }
        public PaymentGatewayTest()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseSqlServer("Data Source=(local)\\SQLEXPRESS;Initial Catalog=PaymentGateway;Integrated Security=True;").Options;

            _context = new ApplicationDbContext(options);
            _context.Database.EnsureDeleted();
            _context.Database.EnsureCreated();

            if (_mapper == null)
            {
                var mappingConfig = new MapperConfiguration(mc =>
                {
                    mc.AddProfile(new AutoMapperProfile());
                });
                IMapper mapper = mappingConfig.CreateMapper();
                _mapper = mapper;
            }

            _cheapPaymentGateway     = new CheapPaymentGateway();
            _expensivePaymentGateway = new ExpensivePaymentGateway(_cheapPaymentGateway);
            _premiumPaymentGateway   = new PremiumPaymentGateway();
            _paymentRepo             = new PaymentRepository(_context);
            _paymentStateRepo        = new PaymentStateRepository(_context);
            _paymentGateway          = new PaymentGateway(_cheapPaymentGateway, _expensivePaymentGateway, _premiumPaymentGateway, _paymentRepo, _paymentStateRepo, _mapper);
        }
Ejemplo n.º 6
0
 public PaymentController(ICheapPaymentGateway cheapPaymentGateway,
                          IExpensivePaymentGateway expensivePaymentGateway,
                          IPremiumPaymentGateway premiumPaymentGateway)
 {
     _cheapPaymentGateway     = cheapPaymentGateway;
     _expensivePaymentGateway = expensivePaymentGateway;
     _premiumPaymentGateway   = premiumPaymentGateway;
 }
Ejemplo n.º 7
0
 public PaymentService(ICheapPaymentGateway cheapPaymentGateway,
                       IExpensivePaymentGateway expensivePaymentGateway,
                       IPremiumPaymentGateway premiumPaymentGateway)
 {
     _cheapPaymentGateway     = cheapPaymentGateway;
     _expensivePaymentGateway = expensivePaymentGateway;
     _premiumPaymentGateway   = premiumPaymentGateway;
 }
Ejemplo n.º 8
0
 public PaymentDetailService(IPaymentLogRepository paymentLogRepository, IPaymentDetailRepository detailRepository, IExpensivePaymentGateway expensivePaymentGateway, ICheapPaymentGateway cheapPaymentGateway, IPremiumPaymentGateway premiumPaymentGateway)
 {
     this.paymentLogRepository    = paymentLogRepository;
     this.detailRepository        = detailRepository;
     this.expensivePaymentGateway = expensivePaymentGateway;
     this.cheapPaymentGateway     = cheapPaymentGateway;
     this.premiumPaymentGateway   = premiumPaymentGateway;
 }
Ejemplo n.º 9
0
 //dependency injection of interfaces into the PaymentProcessor constructor
 public PaymentProcessor(ICheapPaymentGateway cheapPaymentGateway, IExpensivePaymentGateway expensivePaymentGateway,
                         IPremiumPaymentGateway premiumPaymentGateway, IStatusRepository statusRepository)
 {
     _cheapPaymentGateway     = cheapPaymentGateway;
     _expensivePaymentGateway = expensivePaymentGateway;
     _premiumPaymentGateway   = premiumPaymentGateway;
     _statusRepo = statusRepository;
 }
Ejemplo n.º 10
0
 public PaymentHandler(IRepository <PayDetails> payRepository, IRepository <PaymentStatus> payStatusRepository
                       , ICheapPaymentGateway cheapPaymentGateway, IExpensivePaymentGateway expensivePaymentGateway, IPremiumPaymentGateway premiumPaymentGateway)
 {
     _payRepository           = payRepository;
     _payStatusRepository     = payStatusRepository;
     _cheapPaymentGateway     = cheapPaymentGateway;
     _expensivePaymentGateway = expensivePaymentGateway;
     _premiumPaymentGateway   = premiumPaymentGateway;
 }
 public PaymentController(IPaymentEngine paymentEngine, IMapper mapper, ICheapPaymentGateway cheapPaymentGateway,
                          IExpensivePaymentGateway expensivePaymentGateway, IPremiumPaymentGateway premiumPaymentGateway)
 {
     _paymentEngine         = paymentEngine ?? throw new ArgumentNullException(nameof(paymentEngine));
     _mapper                = mapper ?? throw new ArgumentNullException(nameof(mapper));
     _cheapPaymentGateway   = cheapPaymentGateway ?? throw new ArgumentNullException(nameof(cheapPaymentGateway));
     _expensePaymentGateway = expensivePaymentGateway ?? throw new ArgumentNullException(nameof(expensivePaymentGateway));
     _premiumPaymentGateway = premiumPaymentGateway ?? throw new ArgumentNullException(nameof(premiumPaymentGateway));
 }
Ejemplo n.º 12
0
 public UnitOfWork(IPaymentDbContext iPaymentDbContext,
                   IPaymentRepository iPaymentRepository, ICheapPaymentGateway cheapPaymentGateways, IExpensivePaymentGateway expensivePaymentGateways, IPremiumPaymentGateway premiumPaymentGateways)
 {
     _context                 = iPaymentDbContext;
     Payments                 = iPaymentRepository;
     CheapPaymentGateways     = cheapPaymentGateways;
     ExpensivePaymentGateways = expensivePaymentGateways;
     PremiumPaymentGateways   = premiumPaymentGateways;
 }
Ejemplo n.º 13
0
 public PaymentGateway(ICheapPaymentGateway cheapPaymentGateway, IExpensivePaymentGateway expensivePaymentGateway, IPremiumPaymentGateway premiumPaymentGateway, IPaymentRepository paymentRepo, IPaymentStateRepository paymentStateRepo, IMapper mapper)
 {
     _cheapPaymentGateway     = cheapPaymentGateway;
     _expensivePaymentGateway = expensivePaymentGateway;
     _premiumPaymentGateway   = premiumPaymentGateway;
     _paymentRepo             = paymentRepo;
     _paymentStateRepo        = paymentStateRepo;
     _mapper = mapper;
 }
Ejemplo n.º 14
0
 public PaymentController(ILogger <PaymentController> logger, IServiceProvider provider, IMapper mapper)
 {
     _logger                = logger;
     _mapper                = mapper;
     _cheapPayment          = provider.GetRequiredService <ICheapPaymentGateway>();
     _expensivePayment      = provider.GetRequiredService <IExpensivePaymentGateway>();
     _premiumPayment        = provider.GetRequiredService <IPremiumPaymentGateway>();
     _transactionRepository = provider.GetRequiredService <ITransactionRepository>();
 }
Ejemplo n.º 15
0
 public void TestInitialize()
 {
     unityContainer          = new UnityContainer();
     premiumPaymentGateway   = MockRepository.GenerateStub <IPremiumPaymentGateway>();
     cheapPaymentGateway     = MockRepository.GenerateStub <ICheapPaymentGateway>();
     expensivePaymentGateway = MockRepository.GenerateStub <IExpensivePaymentGateway>();
     controller               = new CreditCardController(unityContainer, cheapPaymentGateway, expensivePaymentGateway, premiumPaymentGateway);
     controller.Request       = new HttpRequestMessage();
     controller.Configuration = new HttpConfiguration();
 }
Ejemplo n.º 16
0
 public ProcessPayment(IPaymentService paymentService, IPaymentStatusService paymentStatusService, ILogWriter logWriter, IMapper mapper, ICheapPaymentGateway cheapPaymentGateway, IExpensivePaymentGateway expensivePaymentGateway, IPremiumPaymentGateway premiumPaymentGateway, IConfiguration config)
 {
     _paymentService       = paymentService;
     _paymentStatusService = paymentStatusService;
     _logWriter            = logWriter;
     _mapper           = mapper;
     _cheapPayment     = cheapPaymentGateway;
     _expensivePayment = expensivePaymentGateway;
     _premium          = premiumPaymentGateway;
     _config           = config;
 }
Ejemplo n.º 17
0
        public BankingSystem(ICheapPaymentGateway cheapGateway,
                             IExpensivePaymentGateway expensiveGateway,
                             IPremiumPaymentGateway premiumGateway
                             )
        {
            _cheapGateway     = cheapGateway;
            _expensiveGateway = expensiveGateway;
            _premiumGateway   = premiumGateway;

            _cheapGateway.SetNext(_expensiveGateway);
            _expensiveGateway.SetNext(_premiumGateway);
        }
Ejemplo n.º 18
0
 public Handler(
     ICurrentUserService currentUserService,
     IDataContext dataContext,
     ICheapPaymentGateway cheapPaymentGateway,
     IExpensivePaymentGateway expensivePaymentGateway,
     IPremiumPaymentGateway premiumPaymentGateway)
 {
     _currentUserService      = currentUserService;
     _dataContext             = dataContext;
     _cheapPaymentGateway     = cheapPaymentGateway;
     _expensivePaymentGateway = expensivePaymentGateway;
     _premiumPaymentGateway   = premiumPaymentGateway;
 }
Ejemplo n.º 19
0
        public PaymentBusinessTest()
        {
            _logger     = Substitute.For <ILoggerManager>();
            _unitOfWork = Substitute.For <IUnitOfWork>();
            _mapper     = Substitute.For <IMapper>();

            _cheapPaymentGateway     = Substitute.For <ICheapPaymentGateway>();
            _expensivePaymentGateway = Substitute.For <IExpensivePaymentGateway>();
            _premiumPaymentGateway   = Substitute.For <IPremiumPaymentGateway>();

            _serviceAccessor = Substitute.For <Register.ServiceResolver>();
            _serviceAccessor.Invoke(Constants.CHEAP).Returns(_cheapPaymentGateway);
            _serviceAccessor.Invoke(Constants.EXPENSIVE).Returns(_expensivePaymentGateway);
            _serviceAccessor.Invoke(Constants.PREMIUM).Returns(_premiumPaymentGateway);

            _mapper.Map <PaymentEntities.Entities.Payment>(Arg.Any <PaymentRequestModel>()).Returns(GetPayment());

            _paymentBusiness = new PaymentBusiness.Payment.PaymentBusiness(_logger, _unitOfWork, _mapper, _serviceAccessor);
        }
Ejemplo n.º 20
0
        public PaymentResponse ProcessPayment(Payment payment)
        {
            PaymentResponse response = null;

            IPaymentGateway gateway;

            if (payment.Amount < 20)
            {
                gateway  = new ICheapPaymentGateway();
                response = gateway.ProcessPayment(payment);
            }
            else if (payment.Amount > 20 && payment.Amount <= 500)
            {
                gateway  = new IExpensivePaymentGateway();
                response = gateway.ProcessPayment(payment);
                if (!response.Success)
                {
                    gateway  = new ICheapPaymentGateway();
                    response = gateway.ProcessPayment(payment);
                }
            }
            else
            {
                gateway = new IPremiumPaymentGateway();
                var retries = 3;
                while (retries > 0)
                {
                    response = gateway.ProcessPayment(payment);
                    if (response.Success)
                    {
                        return(response);
                    }

                    retries--;
                }
                response.ErrorMessage += " Retried: 3 times.";
            }
            return(response);
        }
Ejemplo n.º 21
0
 public PremiumPaymentGatewayCommand(double amount, IPremiumPaymentGateway premiumPaymentGateway)
 {
     _amount  = amount;
     _gateway = premiumPaymentGateway;
 }
Ejemplo n.º 22
0
 public PaymentProcessor()
 {
     _cheapPaymentGateWay     = new CheapPaymentGateway();
     _expensicePaymentGateWay = new  ExpensicePaymentGateWay();
     _premiumPaymentGateway   = new  PremiumPaymentGateway();
 }
Ejemplo n.º 23
0
 public Invoker(ICheapPaymentGateway cheapPaymentGateway, IExpensivePaymentGateway expensivePaymentGateway, IPremiumPaymentGateway premiumPaymentGateway)
 {
     _expensiveGateWay = expensivePaymentGateway;
     _cheapGateway     = cheapPaymentGateway;
     _premiumGateway   = premiumPaymentGateway;
 }
 public PremiumPaymentGatewayProvider(IPremiumPaymentGateway premiumPaymentGateway)
 {
     _premiumPaymentGateway = premiumPaymentGateway;
 }