-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ACL-242] Add CreditableAt in GetPaymentResult #237
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
|
||
namespace TrueLayer.AcceptanceTests.Helpers; | ||
|
||
public static class Waiter | ||
{ | ||
public static Task<T> WaitAsync<T>( | ||
Func<Task<T>> action, | ||
Predicate<T> predicate, | ||
TimeSpan? pause = null, | ||
TimeSpan? timeout = null) | ||
=> WaitAsync(action, x => Task.FromResult(predicate(x)), pause, timeout); | ||
|
||
public static async Task<T> WaitAsync<T>( | ||
Func<Task<T>> action, | ||
Func<T, Task<bool>> predicate, | ||
TimeSpan? pause = null, | ||
TimeSpan? timeout = null) | ||
{ | ||
var stopwatch = Stopwatch.StartNew(); | ||
|
||
T result; | ||
|
||
do | ||
{ | ||
result = await action(); | ||
await Task.Delay(pause.GetValueOrDefault(TimeSpan.FromSeconds(1))); | ||
} while (!await predicate(result) && stopwatch.Elapsed < timeout.GetValueOrDefault(TimeSpan.FromSeconds(20))); | ||
|
||
return result; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace TrueLayer.AcceptanceTests.MockBank; | ||
|
||
public enum MockBankAction | ||
{ | ||
Cancel, | ||
RejectAuthorisation, | ||
Execute, | ||
RejectExecution, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Net.Mime; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
|
||
namespace TrueLayer.AcceptanceTests.MockBank; | ||
|
||
public class MockBankClient | ||
{ | ||
private readonly HttpClient _httpClient; | ||
|
||
public MockBankClient(HttpClient httpClient) | ||
{ | ||
_httpClient = httpClient; | ||
} | ||
|
||
public async Task<Uri> AuthorisePaymentAsync( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, I was planning to do a refactor later, we can optimise several part of the tests. |
||
Uri authUri, | ||
MockBankAction action, | ||
int settlementDelayInSeconds = 0) | ||
{ | ||
var mockPaymentId = authUri.Segments.Last(); | ||
var token = authUri.Fragment[7..]; | ||
|
||
var requestBody = $@"{{ ""action"": ""{action}"", ""settlement_delay_in_seconds"": {settlementDelayInSeconds} }}"; | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Post, $"api/single-immediate-payments/{mockPaymentId}/action") | ||
{ | ||
Headers = { { "Authorization", $"Bearer {token}" } }, | ||
Content = new StringContent(requestBody, Encoding.UTF8, MediaTypeNames.Application.Json), | ||
}; | ||
var response = await _httpClient.SendAsync(request); | ||
var responseBody = await response.Content.ReadAsStringAsync(); | ||
response.StatusCode.Should().Be(HttpStatusCode.Accepted, "submit mock payment response should be 202"); | ||
return new Uri(responseBody); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Net.Http; | ||
using System.Net.Http.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
|
||
namespace TrueLayer.AcceptanceTests; | ||
|
||
public class PayApiClient | ||
{ | ||
private readonly HttpClient _httpClient; | ||
|
||
public PayApiClient(HttpClient httpClient) | ||
{ | ||
_httpClient = httpClient; | ||
} | ||
|
||
public async Task<HttpResponseMessage> GetJwksAsync() | ||
{ | ||
var request = new HttpRequestMessage(HttpMethod.Get, "/.well-known/jwks.json"); | ||
var response = await _httpClient.SendAsync(request); | ||
return response; | ||
} | ||
|
||
public async Task<HttpResponseMessage> SubmitProviderReturnParametersAsync(string query, string fragment) | ||
{ | ||
var requestBody = new SubmitProviderReturnParametersRequest { Query = query, Fragment = fragment }; | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Post, "/spa/submit-provider-return-parameters") | ||
{ | ||
Content = JsonContent.Create(requestBody) | ||
}; | ||
var response = await _httpClient.SendAsync(request); | ||
return response; | ||
} | ||
} | ||
|
||
public class SubmitProviderReturnParametersRequest | ||
{ | ||
[JsonPropertyName("query")] public string? Query { get; set; } | ||
[JsonPropertyName("fragment")] public string? Fragment { get; set; } | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct? It does not seems so based on our public docs? I can't see the field on the
authorized
payment details on the API refThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it's quite new, probably the docs are not updated, I'm checking with Risk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's confirmed, we need to update docs