Ejemplo n.º 1
0
 public PaymentController(IPaymentRepository paymentStore, IPaymentAuthoriser paymentAuthoriser, IClock clock, ILogger <PaymentController> logger)
 {
     _paymentStore      = paymentStore;
     _paymentAuthoriser = paymentAuthoriser;
     _clock             = clock;
     _logger            = logger;
 }
Ejemplo n.º 2
0
        public static IServiceCollection UsePaymentAuthoriser(this IServiceCollection services, IConfiguration configuration)
        {
            var acquirerConfig = configuration.GetSection(InMemoryAcquirerOptions.Acquirer).Get <InMemoryAcquirerOptions>();
            IPaymentAuthoriser paymentAuthoriser = acquirerConfig.AuthoriseBehaviour switch
            {
                AuthoriseBehaviour.Approve => new AlwaysApprovesPaymentAuthoriser(),
                AuthoriseBehaviour.Deny => new AlwaysDeniesPaymentAuthoriser(),
                AuthoriseBehaviour.Error => new AlwaysThrowsPaymentAuthoriser(),
                _ => throw new OptionsValidationException(InMemoryAcquirerOptions.Acquirer, typeof(InMemoryAcquirerOptions), new[] { $"Unknown InMemoryAcquirer behaviour option '{acquirerConfig.AuthoriseBehaviour}'" })
            };

            services.AddSingleton(paymentAuthoriser);

            return(services);
        }
    }