diff --git a/authorisation-adjustment-example/Controllers/AdminController.cs b/authorisation-adjustment-example/Controllers/AdminController.cs index 94b1dfbd..c096bb96 100644 --- a/authorisation-adjustment-example/Controllers/AdminController.cs +++ b/authorisation-adjustment-example/Controllers/AdminController.cs @@ -74,7 +74,7 @@ public IActionResult Result(string reference, string status, [FromQuery(Name = " } [HttpPost("admin/update-payment-amount")] - public async Task> UpdatePaymentAmount([FromBody] UpdatePaymentAmountRequest request, CancellationToken cancellationToken = default) + public async Task> UpdatePaymentAmount([FromBody] UpdatePaymentAmountRequest request, CancellationToken cancellationToken = default) { PaymentModel payment = _repository.FindLatestPaymentByReference(request.Reference); @@ -85,15 +85,15 @@ public async Task> UpdatePaymentAmount try { - var createPaymentAmountUpdateRequest = new CreatePaymentAmountUpdateRequest() + var paymentAmountUpdateRequest = new PaymentAmountUpdateRequest() { MerchantAccount = _merchantAccount, // Required Amount = new Amount() { Value = request.Amount, Currency = payment.Currency }, Reference = payment.Reference, - IndustryUsage = CreatePaymentAmountUpdateRequest.IndustryUsageEnum.DelayedCharge, + IndustryUsage = PaymentAmountUpdateRequest.IndustryUsageEnum.DelayedCharge, }; - var response = await _modificationsService.UpdateAuthorisedAmountAsync(payment.GetOriginalPspReference(), createPaymentAmountUpdateRequest, cancellationToken: cancellationToken); + var response = await _modificationsService.UpdateAuthorisedAmountAsync(payment.GetOriginalPspReference(), paymentAmountUpdateRequest, cancellationToken: cancellationToken); return Ok(response); } catch (HttpClientException e) @@ -104,7 +104,7 @@ public async Task> UpdatePaymentAmount } [HttpPost("admin/capture-payment")] - public async Task> CapturePayment([FromBody] CreateCapturePaymentRequest request, CancellationToken cancellationToken = default) + public async Task> CapturePayment([FromBody] CreateCapturePaymentRequest request, CancellationToken cancellationToken = default) { PaymentModel payment = _repository.FindLatestPaymentByReference(request.Reference); @@ -115,14 +115,14 @@ public async Task> CapturePayment([FromBody try { - var createPaymentCaptureRequest = new CreatePaymentCaptureRequest() + var paymentCaptureRequest = new PaymentCaptureRequest() { MerchantAccount = _merchantAccount, // Required. Amount = new Amount() { Value = payment.Amount, Currency = payment.Currency }, // Required. Reference = payment.Reference }; - var response = await _modificationsService.CaptureAuthorisedPaymentAsync(payment.GetOriginalPspReference(), createPaymentCaptureRequest, cancellationToken: cancellationToken); + var response = await _modificationsService.CaptureAuthorisedPaymentAsync(payment.GetOriginalPspReference(), paymentCaptureRequest, cancellationToken: cancellationToken); return Ok(response); // Note that the response will have a different PSPReference compared to the initial pre-authorisation. } catch (HttpClientException e) @@ -133,7 +133,7 @@ public async Task> CapturePayment([FromBody } [HttpPost("admin/reversal-payment")] - public async Task> ReversalPayment([FromBody] CreateReversalPaymentRequest request, CancellationToken cancellationToken = default) + public async Task> ReversalPayment([FromBody] CreateReversalPaymentRequest request, CancellationToken cancellationToken = default) { PaymentModel payment = _repository.FindLatestPaymentByReference(request.Reference); @@ -144,13 +144,13 @@ public async Task> ReversalPayment([FromBo try { - var createPaymentReversalRequest = new CreatePaymentReversalRequest() + var paymentReversalRequest = new PaymentReversalRequest() { MerchantAccount = _merchantAccount, // Required. Reference = payment.Reference }; - var response = await _modificationsService.RefundOrCancelPaymentAsync(payment.GetOriginalPspReference(), createPaymentReversalRequest, cancellationToken: cancellationToken); + var response = await _modificationsService.RefundOrCancelPaymentAsync(payment.GetOriginalPspReference(), paymentReversalRequest, cancellationToken: cancellationToken); return Ok(response); } catch (HttpClientException e) diff --git a/authorisation-adjustment-example/Controllers/ApiController.cs b/authorisation-adjustment-example/Controllers/ApiController.cs index ece151a8..c63f165f 100644 --- a/authorisation-adjustment-example/Controllers/ApiController.cs +++ b/authorisation-adjustment-example/Controllers/ApiController.cs @@ -55,7 +55,7 @@ public async Task> GetPaymentMethods(Cancel } [HttpPost("api/submitAdditionalDetails")] - public async Task> SubmitAdditionalDetails(DetailsRequest request, CancellationToken cancellationToken = default) + public async Task> SubmitAdditionalDetails(PaymentDetailsRequest request, CancellationToken cancellationToken = default) { try { @@ -73,7 +73,7 @@ public async Task> SubmitAdditionalDetails( [HttpGet("api/handleRedirect")] public async Task HandleRedirect(string payload = null, string redirectResult = null, CancellationToken cancellationToken = default) { - var detailsRequest = new DetailsRequest(); + var detailsRequest = new PaymentDetailsRequest(); if (!string.IsNullOrWhiteSpace(redirectResult)) { detailsRequest.Details = new PaymentCompletionDetails() { RedirectResult = redirectResult }; diff --git a/authorisation-adjustment-example/Startup.cs b/authorisation-adjustment-example/Startup.cs index ca608547..d2981b43 100644 --- a/authorisation-adjustment-example/Startup.cs +++ b/authorisation-adjustment-example/Startup.cs @@ -11,6 +11,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; +using System.Net.Http; +using System.Threading; +using System; namespace adyen_dotnet_authorisation_adjustment_example { @@ -51,22 +54,31 @@ public void ConfigureServices(IServiceCollection services) services.AddHttpContextAccessor() .AddTransient(); - // Register your dependencies. - services.AddSingleton(provider => + // Register Adyen.Client as singleton. + string httpClientName = "HttpClientName"; + + services.AddSingleton((IServiceProvider provider) => + { + AdyenOptions options = provider.GetRequiredService>().Value; + Config config = new Config() + { + // Get your `API Key` from AdyenOptions using the Options pattern. + XApiKey = options.ADYEN_API_KEY, + // Test environment. + Environment = Adyen.Model.Environment.Test, + }; + return new Client(config, provider.GetRequiredService(), httpClientName); + }); + + // Register named HttpClient. + services.AddHttpClient(httpClientName) + .ConfigurePrimaryHttpMessageHandler((IServiceProvider provider) => { - var options = provider.GetRequiredService>(); - return new Client( - new Config() - { - // Get your `API Key`, `HMAC Key` and `MerchantAccount` from AdyenOptions using the Options pattern. - XApiKey = options.Value.ADYEN_API_KEY, - HmacKey = options.Value.ADYEN_HMAC_KEY, - MerchantAccount = options.Value.ADYEN_MERCHANT_ACCOUNT, - - // Test environment. - Environment = Environment.Test, - }); - }).AddHttpClient(); // Add HttpClient. + return new SocketsHttpHandler() + { + PooledConnectionLifetime = TimeSpan.FromMinutes(1) + }; + }).SetHandlerLifetime(Timeout.InfiniteTimeSpan); services.AddSingleton(); // Used to be called "Checkout.cs" in Adyen .NET 9.x.x and below, see https://github.com/Adyen/adyen-dotnet-api-library/blob/9.2.1/Adyen/Service/Checkout.cs. services.AddSingleton(); diff --git a/authorisation-adjustment-example/adyen-dotnet-authorisation-adjustment-example.csproj b/authorisation-adjustment-example/adyen-dotnet-authorisation-adjustment-example.csproj index 992089b5..b523ac37 100644 --- a/authorisation-adjustment-example/adyen-dotnet-authorisation-adjustment-example.csproj +++ b/authorisation-adjustment-example/adyen-dotnet-authorisation-adjustment-example.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -6,7 +6,7 @@ - - + + diff --git a/checkout-example-advanced/Controllers/ApiController.cs b/checkout-example-advanced/Controllers/ApiController.cs index 30bf586a..b7f7340e 100644 --- a/checkout-example-advanced/Controllers/ApiController.cs +++ b/checkout-example-advanced/Controllers/ApiController.cs @@ -94,7 +94,7 @@ public async Task> InitiatePayment(PaymentRequest } [HttpPost("api/submitAdditionalDetails")] - public async Task> SubmitAdditionalDetails(DetailsRequest request, CancellationToken cancellationToken = default) + public async Task> SubmitAdditionalDetails(PaymentDetailsRequest request, CancellationToken cancellationToken = default) { try { @@ -112,7 +112,7 @@ public async Task> SubmitAdditionalDetails( [HttpGet("api/handleShopperRedirect")] public async Task HandleShoppperRedirect(string payload = null, string redirectResult = null, CancellationToken cancellationToken = default) { - var detailsRequest = new DetailsRequest(); + var detailsRequest = new PaymentDetailsRequest(); if (!string.IsNullOrWhiteSpace(redirectResult)) { detailsRequest.Details = new PaymentCompletionDetails() { RedirectResult = redirectResult }; diff --git a/checkout-example-advanced/Startup.cs b/checkout-example-advanced/Startup.cs index e46ad5aa..2889cafa 100644 --- a/checkout-example-advanced/Startup.cs +++ b/checkout-example-advanced/Startup.cs @@ -1,5 +1,4 @@ using Adyen; -using Adyen.Model; using Adyen.Service.Checkout; using Adyen.Util; using adyen_dotnet_checkout_example_advanced.Options; @@ -10,6 +9,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; +using System; +using System.Net.Http; +using System.Threading; namespace adyen_dotnet_checkout_example_advanced { @@ -51,21 +53,31 @@ public void ConfigureServices(IServiceCollection services) services.AddHttpContextAccessor() .AddTransient(); - // Register your dependencies. - services.AddSingleton(provider => + // Register Adyen.Client as singleton. + string httpClientName = "HttpClientName"; + + services.AddSingleton((IServiceProvider provider) => + { + AdyenOptions options = provider.GetRequiredService>().Value; + Config config = new Config() + { + // Get your `API Key` from AdyenOptions using the Options pattern. + XApiKey = options.ADYEN_API_KEY, + // Test environment. + Environment = Adyen.Model.Environment.Test, + }; + return new Client(config, provider.GetRequiredService(), httpClientName); + }); + + // Register named HttpClient. + services.AddHttpClient(httpClientName) + .ConfigurePrimaryHttpMessageHandler((IServiceProvider provider) => { - var options = provider.GetRequiredService>(); - return new Client( - new Config() - { - // Get your `API Key`, `HMAC Key` and `MerchantAccount` from AdyenOptions using the Options pattern. - XApiKey = options.Value.ADYEN_API_KEY, - HmacKey = options.Value.ADYEN_HMAC_KEY, - MerchantAccount = options.Value.ADYEN_MERCHANT_ACCOUNT, - // Test environment. - Environment = Environment.Test, - }); - }).AddHttpClient(); // Add HttpClient. + return new SocketsHttpHandler() + { + PooledConnectionLifetime = TimeSpan.FromMinutes(1) + }; + }).SetHandlerLifetime(Timeout.InfiniteTimeSpan); services.AddSingleton(); // Used to be called "Checkout.cs" in Adyen .NET 9.x.x and below, see https://github.com/Adyen/adyen-dotnet-api-library/blob/9.2.1/Adyen/Service/Checkout.cs. services.AddSingleton(); diff --git a/checkout-example-advanced/adyen-dotnet-checkout-example-advanced.csproj b/checkout-example-advanced/adyen-dotnet-checkout-example-advanced.csproj index d8f38616..6812345c 100644 --- a/checkout-example-advanced/adyen-dotnet-checkout-example-advanced.csproj +++ b/checkout-example-advanced/adyen-dotnet-checkout-example-advanced.csproj @@ -6,7 +6,7 @@ - - + + diff --git a/checkout-example/Startup.cs b/checkout-example/Startup.cs index a84dd988..eae488db 100644 --- a/checkout-example/Startup.cs +++ b/checkout-example/Startup.cs @@ -1,5 +1,4 @@ using Adyen; -using Adyen.Model; using Adyen.Service.Checkout; using Adyen.Util; using adyen_dotnet_checkout_example.Options; @@ -10,6 +9,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; +using System; +using System.Net.Http; +using System.Threading; namespace adyen_dotnet_checkout_example { @@ -32,15 +34,15 @@ public void ConfigureServices(IServiceCollection services) { // Public key used for client-side authentication: https://docs.adyen.com/development-resources/client-side-authentication. options.ADYEN_CLIENT_KEY = Configuration[nameof(AdyenOptions.ADYEN_CLIENT_KEY)]; - + // Your secret API Key: https://docs.adyen.com/development-resources/api-credentials#generate-your-api-key. options.ADYEN_API_KEY = Configuration[nameof(AdyenOptions.ADYEN_API_KEY)]; - + // Your Merchant Account name: https://docs.adyen.com/account/account-structure. options.ADYEN_MERCHANT_ACCOUNT = Configuration[nameof(AdyenOptions.ADYEN_MERCHANT_ACCOUNT)]; // HMAC Key used to validate your webhook signatures: https://docs.adyen.com/development-resources/webhooks/verify-hmac-signatures. - options.ADYEN_HMAC_KEY = Configuration[nameof(AdyenOptions.ADYEN_HMAC_KEY)]; + options.ADYEN_HMAC_KEY = Configuration[nameof(AdyenOptions.ADYEN_HMAC_KEY)]; } ); @@ -51,21 +53,31 @@ public void ConfigureServices(IServiceCollection services) services.AddHttpContextAccessor() .AddTransient(); - // Register your dependencies. - services.AddSingleton(provider => + // Register Adyen.Client as singleton. + string httpClientName = "HttpClientName"; + + services.AddSingleton((IServiceProvider provider) => + { + AdyenOptions options = provider.GetRequiredService>().Value; + Config config = new Config() + { + // Get your `API Key` from AdyenOptions using the Options pattern. + XApiKey = options.ADYEN_API_KEY, + // Test environment. + Environment = Adyen.Model.Environment.Test, + }; + return new Client(config, provider.GetRequiredService(), httpClientName); + }); + + // Register named HttpClient. + services.AddHttpClient(httpClientName) + .ConfigurePrimaryHttpMessageHandler((IServiceProvider provider) => { - var options = provider.GetRequiredService>(); - return new Client( - new Config() - { - // Get your `API Key`, `HMAC Key` and `MerchantAccount` from AdyenOptions using the Options pattern. - XApiKey = options.Value.ADYEN_API_KEY, - HmacKey = options.Value.ADYEN_HMAC_KEY, - MerchantAccount = options.Value.ADYEN_MERCHANT_ACCOUNT, - // Test environment. - Environment = Environment.Test, - }); - }).AddHttpClient(); // Add HttpClient. + return new SocketsHttpHandler() + { + PooledConnectionLifetime = TimeSpan.FromMinutes(1) + }; + }).SetHandlerLifetime(Timeout.InfiniteTimeSpan); services.AddSingleton(); // Used to be called "Checkout.cs" in Adyen .NET 9.x.x and below, see https://github.com/Adyen/adyen-dotnet-api-library/blob/9.2.1/Adyen/Service/Checkout.cs. services.AddSingleton(); diff --git a/checkout-example/adyen-dotnet-checkout-example.csproj b/checkout-example/adyen-dotnet-checkout-example.csproj index a5c0d07c..aa326c34 100644 --- a/checkout-example/adyen-dotnet-checkout-example.csproj +++ b/checkout-example/adyen-dotnet-checkout-example.csproj @@ -6,7 +6,7 @@ - - + + diff --git a/giftcard-example/Startup.cs b/giftcard-example/Startup.cs index a535ee98..34ace693 100644 --- a/giftcard-example/Startup.cs +++ b/giftcard-example/Startup.cs @@ -1,5 +1,4 @@ using Adyen; -using Adyen.Model; using Adyen.Service.Checkout; using Adyen.Util; using adyen_dotnet_giftcard_example.Options; @@ -10,6 +9,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; +using System; +using System.Net.Http; +using System.Threading; namespace adyen_dotnet_giftcard_example { @@ -50,21 +52,31 @@ public void ConfigureServices(IServiceCollection services) services.AddHttpContextAccessor() .AddTransient(); - // Register your dependencies. - services.AddSingleton(provider => + // Register Adyen.Client as singleton. + string httpClientName = "HttpClientName"; + + services.AddSingleton((IServiceProvider provider) => + { + AdyenOptions options = provider.GetRequiredService>().Value; + Config config = new Config() + { + // Get your `API Key` from AdyenOptions using the Options pattern. + XApiKey = options.ADYEN_API_KEY, + // Test environment. + Environment = Adyen.Model.Environment.Test, + }; + return new Client(config, provider.GetRequiredService(), httpClientName); + }); + + // Register named HttpClient. + services.AddHttpClient(httpClientName) + .ConfigurePrimaryHttpMessageHandler((IServiceProvider provider) => { - var options = provider.GetRequiredService>(); - return new Client( - new Config() - { - // Get your `API Key`, `HMAC Key` and `MerchantAccount` from AdyenOptions using the Options pattern. - XApiKey = options.Value.ADYEN_API_KEY, - HmacKey = options.Value.ADYEN_HMAC_KEY, - MerchantAccount = options.Value.ADYEN_MERCHANT_ACCOUNT, - // Test environment. - Environment = Environment.Test, - }); - }).AddHttpClient(); // Add HttpClient. + return new SocketsHttpHandler() + { + PooledConnectionLifetime = TimeSpan.FromMinutes(1) + }; + }).SetHandlerLifetime(Timeout.InfiniteTimeSpan); services.AddSingleton(); // Used to be called "Checkout.cs" in Adyen .NET 9.x.x and below, see https://github.com/Adyen/adyen-dotnet-api-library/blob/9.2.1/Adyen/Service/Checkout.cs. services.AddSingleton(); diff --git a/giftcard-example/adyen-dotnet-giftcard-example.csproj b/giftcard-example/adyen-dotnet-giftcard-example.csproj index a54f3f66..85d3cc10 100644 --- a/giftcard-example/adyen-dotnet-giftcard-example.csproj +++ b/giftcard-example/adyen-dotnet-giftcard-example.csproj @@ -6,7 +6,7 @@ - - + + diff --git a/paybylink-example/Services/LinksService.cs b/paybylink-example/Services/LinksService.cs index 4aa07255..3f551e24 100644 --- a/paybylink-example/Services/LinksService.cs +++ b/paybylink-example/Services/LinksService.cs @@ -38,7 +38,7 @@ public LinksService(IPaymentLinksService paymentLinksService, IPaymentLinkReposi public async Task CreatePaymentLinkAsync(string reference, long amount, bool isReusable, CancellationToken cancellationToken) { - var createPayByLinkRequest = new CreatePaymentLinkRequest( + var createPayByLinkRequest = new PaymentLinkRequest( merchantAccount: _merchantAccount, // Required. amount: new Amount("EUR", amount), // Required, value in minor units. reference: reference, // Required, use for example: new Guid(). @@ -55,8 +55,8 @@ public async Task CreatePaymentLinkAsync(string reference, id: response.Id, reference: response.Reference, response.Url, expiresAt: DateTime.Parse(response.ExpiresAt), - status: response.Status.ToString(), - isReusable: response.Reusable + status: response.Status.ToString(), + isReusable: response.Reusable.HasValue ? response.Reusable.Value : false ); _logger.LogInformation($"Response from API:\n{response}\n"); return response; @@ -75,8 +75,7 @@ public async Task> GetAndUpdatePa { try { - var response = - await _paymentLinksService.GetPaymentLinkAsync(kvp.Value.Id, cancellationToken: cancellationToken); + PaymentLinkResponse response = await _paymentLinksService.GetPaymentLinkAsync(kvp.Value.Id, cancellationToken: cancellationToken); // Update each individual link. _paymentLinkRepository.Upsert( @@ -84,7 +83,7 @@ public async Task> GetAndUpdatePa reference: response.Reference, response.Url, expiresAt: DateTime.Parse(response.ExpiresAt), status: response.Status.ToString(), - isReusable: response.Reusable + isReusable: response.Reusable.HasValue ? response.Reusable.Value : false ); } catch (Adyen.HttpClient.HttpClientException e) diff --git a/paybylink-example/Startup.cs b/paybylink-example/Startup.cs index 72276b60..33073537 100644 --- a/paybylink-example/Startup.cs +++ b/paybylink-example/Startup.cs @@ -1,5 +1,4 @@ using Adyen; -using Adyen.Model; using Adyen.Service.Checkout; using Adyen.Util; using adyen_dotnet_paybylink_example.Options; @@ -11,6 +10,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; +using System; +using System.Net.Http; +using System.Threading; namespace adyen_dotnet_paybylink_example { @@ -47,23 +49,33 @@ public void ConfigureServices(IServiceCollection services) services.AddControllers().AddNewtonsoftJson(); services.AddHttpContextAccessor() .AddTransient(); - - // Register your dependencies. - services.AddSingleton(provider => + + // Register Adyen.Client as singleton. + string httpClientName = "HttpClientName"; + + services.AddSingleton((IServiceProvider provider) => { - var options = provider.GetRequiredService>(); - return new Client( - new Config() - { - // Get your `API Key`, `HMAC Key` and `MerchantAccount` from AdyenOptions using the Options pattern. - XApiKey = options.Value.ADYEN_API_KEY, - HmacKey = options.Value.ADYEN_HMAC_KEY, - MerchantAccount = options.Value.ADYEN_MERCHANT_ACCOUNT, - // Test environment. - Environment = Environment.Test, - }); - }).AddHttpClient(); // Add HttpClient. - + AdyenOptions options = provider.GetRequiredService>().Value; + Config config = new Config() + { + // Get your `API Key` from AdyenOptions using the Options pattern. + XApiKey = options.ADYEN_API_KEY, + // Test environment. + Environment = Adyen.Model.Environment.Test, + }; + return new Client(config, provider.GetRequiredService(), httpClientName); + }); + + // Register named HttpClient. + services.AddHttpClient(httpClientName) + .ConfigurePrimaryHttpMessageHandler((IServiceProvider provider) => + { + return new SocketsHttpHandler() + { + PooledConnectionLifetime = TimeSpan.FromMinutes(1) + }; + }).SetHandlerLifetime(Timeout.InfiniteTimeSpan); + services.AddSingleton(); // Used to be part of "Checkout.cs" in Adyen .NET 9.x.x and below, see https://github.com/Adyen/adyen-dotnet-api-library/blob/9.2.1/Adyen/Service/Checkout.cs. services.AddSingleton(); diff --git a/paybylink-example/adyen-dotnet-paybylink-example.csproj b/paybylink-example/adyen-dotnet-paybylink-example.csproj index cfeb9587..68b1df30 100644 --- a/paybylink-example/adyen-dotnet-paybylink-example.csproj +++ b/paybylink-example/adyen-dotnet-paybylink-example.csproj @@ -6,7 +6,7 @@ - + diff --git a/subscription-example/Startup.cs b/subscription-example/Startup.cs index 98787c2a..5b4da445 100644 --- a/subscription-example/Startup.cs +++ b/subscription-example/Startup.cs @@ -1,5 +1,4 @@ using Adyen; -using Adyen.Model; using Adyen.Service.Checkout; using Adyen.Util; using adyen_dotnet_subscription_example.Options; @@ -11,6 +10,9 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; +using System; +using System.Net.Http; +using System.Threading; namespace adyen_dotnet_subscription_example { @@ -51,22 +53,31 @@ public void ConfigureServices(IServiceCollection services) services.AddHttpContextAccessor() .AddTransient(); - // Register your dependencies. - services.AddSingleton(provider => + // Register Adyen.Client as singleton. + string httpClientName = "HttpClientName"; + + services.AddSingleton((IServiceProvider provider) => + { + AdyenOptions options = provider.GetRequiredService>().Value; + Config config = new Config() + { + // Get your `API Key` from AdyenOptions using the Options pattern. + XApiKey = options.ADYEN_API_KEY, + // Test environment. + Environment = Adyen.Model.Environment.Test, + }; + return new Client(config, provider.GetRequiredService(), httpClientName); + }); + + // Register named HttpClient. + services.AddHttpClient(httpClientName) + .ConfigurePrimaryHttpMessageHandler((IServiceProvider provider) => { - var options = provider.GetRequiredService>(); - return new Client( - new Config() - { - // Get your `API Key`, `HMAC Key` and `MerchantAccount` from AdyenOptions using the Options pattern. - XApiKey = options.Value.ADYEN_API_KEY, - HmacKey = options.Value.ADYEN_HMAC_KEY, - MerchantAccount = options.Value.ADYEN_MERCHANT_ACCOUNT, - - // Test environment. - Environment = Environment.Test, - }); - }).AddHttpClient(); // Add HttpClient. + return new SocketsHttpHandler() + { + PooledConnectionLifetime = TimeSpan.FromMinutes(1) + }; + }).SetHandlerLifetime(Timeout.InfiniteTimeSpan); services.AddSingleton(); // Used to be called "Checkout.cs" in Adyen .NET 9.x.x and below, see https://github.com/Adyen/adyen-dotnet-api-library/blob/9.2.1/Adyen/Service/Checkout.cs. services.AddSingleton(); // Used to be called "Recurring.cs" in Adyen .NET 9.x.x and below, see https://github.com/Adyen/adyen-dotnet-api-library/blob/9.2.1/Adyen/Service/Recurring.cs. diff --git a/subscription-example/adyen-dotnet-subscription-example.csproj b/subscription-example/adyen-dotnet-subscription-example.csproj index 489c3b78..206632d6 100644 --- a/subscription-example/adyen-dotnet-subscription-example.csproj +++ b/subscription-example/adyen-dotnet-subscription-example.csproj @@ -6,7 +6,7 @@ - - + +