Beispiel #1
0
        /// <summary>
        /// setup default api implementation with container
        /// </summary>
        /// <param name="services">services description</param>
        /// <param name="settings">settings for cash api</param>
        public static void SetupContainer(IServiceCollection services, CashSettings settings)
        {
            services.AddSingleton(settings);
            //services.TryAdd(ServiceDescriptor.Singleton(typeof(ILogger<>), typeof(Logger<>)));

            services.AddTransient <IHttpHandler, HttpHandler>();
            services.AddTransient <ICashHttpClient, CashHttpClient>();
            services.AddTransient <ICashApi, CashApi>();
        }
Beispiel #2
0
 /// <summary>
 /// get default implementation of CashApi
 /// </summary>
 /// <param name="settings">settings for cash api</param>
 /// <param name="httpLog"></param>
 /// <param name="cashHttpLog"></param>
 /// <returns>api interface</returns>
 public static ICashApi GetDefault(CashSettings settings, ILogger <IHttpHandler> httpLog, ILogger <ICashHttpClient> cashHttpLog)
 {
     return(new CashApi(
                new CashHttpClient(
                    new HttpHandler(settings, httpLog),
                    cashHttpLog
                    ),
                settings
                ));
 }
Beispiel #3
0
 /// <summary>
 /// get default implementation of CashApi
 /// </summary>
 /// <param name="settings">settings for cash api</param>
 /// <param name="loggerFactory">logger factory</param>
 /// <returns>api interface</returns>
 public static ICashApi GetDefault(CashSettings settings, ILoggerFactory loggerFactory)
 {
     return(new CashApi(
                new CashHttpClient(
                    new HttpHandler(settings, loggerFactory.CreateLogger <IHttpHandler>()),
                    loggerFactory.CreateLogger <ICashHttpClient>()
                    ),
                settings
                ));
 }
Beispiel #4
0
        public HttpHandler(CashSettings settings, ILogger <IHttpHandler> logger)
        {
            _client = new HttpClient {
                BaseAddress = new Uri(settings.Endpoint)
            };
            _logger = logger;

            var credentials = Encoding.ASCII.GetBytes($"{settings.PublicId}:{settings.ApiSecret}");

            _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(credentials));
        }
Beispiel #5
0
 public static void AddCloudPaymentCash(this IServiceCollection services, CashSettings settings)
 {
     CashApi.SetupContainer(services, settings);
 }
Beispiel #6
0
 public CashApi(ICashHttpClient cashHttpClient, CashSettings settings)
 {
     _cashHttpClient = cashHttpClient;
     _settings       = settings;
 }