From a9d005ec2f7d55632bc90c7878551380382a45bd Mon Sep 17 00:00:00 2001 From: Pontus Eliason Date: Mon, 22 Apr 2024 14:51:09 +0200 Subject: [PATCH 1/5] added support for overriding request creation --- src/Client/TrustlyApiClient.cs | 11 +++++-- tests/Client.UnitTests/RequestTests.cs | 40 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/Client/TrustlyApiClient.cs b/src/Client/TrustlyApiClient.cs index e1e2990..8868fd9 100644 --- a/src/Client/TrustlyApiClient.cs +++ b/src/Client/TrustlyApiClient.cs @@ -26,6 +26,8 @@ public class TrustlyApiClient : IDisposable private readonly JsonRpcSigner _signer; private readonly JsonRpcValidator _validator = new JsonRpcValidator(); + public Func RequestCreator { get; set; } + public event EventHandler> OnAccount; public event EventHandler> OnCancel; public event EventHandler> OnCredit; @@ -329,6 +331,11 @@ NotificationFailResponseDelegate onFailed return eventHandler.GetInvocationList().Length; } + protected virtual WebRequest CreateWebRequest(string url) + { + return WebRequest.Create(url); + } + /// /// Sends an HTTP POST to Trustly server. /// @@ -337,7 +344,7 @@ NotificationFailResponseDelegate onFailed protected string NewHttpPost(string request) { var requestBytes = Encoding.UTF8.GetBytes(request); - var httpWebRequest = (HttpWebRequest)WebRequest.Create(this.Settings.URL); + var httpWebRequest = (this.RequestCreator ?? this.CreateWebRequest)(this.Settings.URL); httpWebRequest.ContentType = "application/json"; httpWebRequest.ContentLength = requestBytes.Length; @@ -353,7 +360,7 @@ protected string NewHttpPost(string request) } } - var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); + var httpResponse = httpWebRequest.GetResponse(); var responseStream = httpResponse.GetResponseStream(); if (responseStream == null) diff --git a/tests/Client.UnitTests/RequestTests.cs b/tests/Client.UnitTests/RequestTests.cs index a1bfa4e..4003143 100644 --- a/tests/Client.UnitTests/RequestTests.cs +++ b/tests/Client.UnitTests/RequestTests.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Trustly.Api.Domain.Base; using Newtonsoft.Json; +using System.Net; namespace Trustly.Api.Client.Tests { @@ -268,6 +269,45 @@ public void TestDeposit() Assert.IsFalse(string.IsNullOrEmpty(response.URL)); } + [Test] + public void TestDepositWithCustomProxyClient() + { + var callCount = 0; + var proxyClient = new TrustlyApiClient(TrustlyApiClientSettings.ForDefaultTest()) + { + RequestCreator = url => + { + callCount++; + var request = WebRequest.Create(url); + request.Proxy = new WebProxy(); + + return request; + } + }; + + var response = proxyClient.Deposit(new Trustly.Api.Domain.Requests.DepositRequestData + { + NotificationURL = "https://fake.test.notification.trustly.com", + MessageID = Guid.NewGuid().ToString(), + EndUserID = "pontus.eliason@trustly.com", + Attributes = new Trustly.Api.Domain.Requests.DepositRequestDataAttributes + { + Amount = "100.00", + Firstname = "John", + Lastname = "Doe", + Email = "pontus.eliason@trustly.com", + Currency = "EUR", + Country = "SE", + Locale = "sv_SE", + ShopperStatement = "Trustly Test Deposit" + } + }); + + Assert.NotNull(response); + Assert.IsFalse(string.IsNullOrEmpty(response.URL)); + Assert.AreEqual(1, callCount); + } + [Test] public void TestGetWithdrawals() { From 1c7fda5ae0a8176add373c7d22588fcc67435a5c Mon Sep 17 00:00:00 2001 From: Pontus Eliason Date: Mon, 22 Apr 2024 15:04:01 +0200 Subject: [PATCH 2/5] upgraded nunit --- tests/Client.UnitTests/Client.UnitTests.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Client.UnitTests/Client.UnitTests.csproj b/tests/Client.UnitTests/Client.UnitTests.csproj index 3ec02bc..4e5bc3a 100644 --- a/tests/Client.UnitTests/Client.UnitTests.csproj +++ b/tests/Client.UnitTests/Client.UnitTests.csproj @@ -8,8 +8,8 @@ - - + + From 6ef89c7773c1a2dee80ac3efc531f4921f63053f Mon Sep 17 00:00:00 2001 From: Pontus Eliason Date: Mon, 22 Apr 2024 15:09:03 +0200 Subject: [PATCH 3/5] GA net version --- .github/workflows/dotnet.yml | 6 +----- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index c2fcb22..b23060e 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -11,16 +11,12 @@ jobs: runs-on: windows-latest - #strategy: - # matrix: - # dotnet: [ '4.5.x', '5.0.x' ] - steps: - uses: actions/checkout@v2 - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 5.0.x + dotnet-version: 8.0.x - name: Restore dependencies run: dotnet restore - name: Build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 67cab18..e242e08 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,7 +22,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: 5.0.x + dotnet-version: 8.0.x - name: Restore dependencies run: dotnet restore - name: Build From 74a07442200f0ff89bee446a765bca28bdca178c Mon Sep 17 00:00:00 2001 From: Pontus Eliason Date: Mon, 22 Apr 2024 15:35:48 +0200 Subject: [PATCH 4/5] v4 --- .github/workflows/dotnet.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index b23060e..8eda2a7 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -14,7 +14,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Setup .NET - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: 8.0.x - name: Restore dependencies diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e242e08..497350f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,7 +20,7 @@ jobs: id: get_version uses: battila7/get-version-action@v2 - name: Setup .NET - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: 8.0.x - name: Restore dependencies From ed02fa793f409f9384ec0025c14c25bf38ca1e4e Mon Sep 17 00:00:00 2001 From: Pontus Eliason Date: Mon, 22 Apr 2024 15:54:06 +0200 Subject: [PATCH 5/5] net 4.7.2 for test runner --- tests/Client.UnitTests/Client.UnitTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Client.UnitTests/Client.UnitTests.csproj b/tests/Client.UnitTests/Client.UnitTests.csproj index 4e5bc3a..612909b 100644 --- a/tests/Client.UnitTests/Client.UnitTests.csproj +++ b/tests/Client.UnitTests/Client.UnitTests.csproj @@ -1,7 +1,7 @@ - net461 + net472 false Trustly.Api.Client.UnitTests