Skip to content

Commit

Permalink
[EWT-563] Implement payments-providers/search (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
tl-mauro-franchi authored Jun 18, 2024
2 parents d1186a3 + 0e7ec21 commit 30f0295
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/TrueLayer/PaymentsProviders/IPaymentsProvidersApi.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using TrueLayer.PaymentsProviders.Model;

Expand All @@ -14,5 +15,12 @@ public interface IPaymentsProvidersApi
/// <param name="id">The provider identifier</param>
/// <returns>An API response that includes the payments provider details if successful, otherwise problem details</returns>
Task<ApiResponse<PaymentsProvider>> GetPaymentsProvider(string id);

/// <summary>
/// Search for payments providers matching the given criteria
/// </summary>
/// <param name="searchPaymentsProvidersRequest">The provider search request</param>
/// <returns>An API response that includes all the providers that match the criteria specified on the request</returns>
Task<ApiResponse<SearchPaymentsProvidersResponse>> SearchPaymentsProviders(SearchPaymentsProvidersRequest searchPaymentsProvidersRequest);
}
}
15 changes: 15 additions & 0 deletions src/TrueLayer/PaymentsProviders/Model/AuthorizationFlow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;
using TrueLayer.Models;

namespace TrueLayer.PaymentsProviders.Model;

public record AuthorizationFlow(AuthorizationFlowConfiguration Configuration);

public record AuthorizationFlowConfiguration(Dictionary<string, string>? Redirect = null, Form? Form = null,
Consent? Consent = null);

public record Form(List<string> InputTypes);

public record Consent(ConsentRequirements Requirements);

public record ConsentRequirements(Dictionary<string, string> Pis, Dictionary<string, string>? Ais = null);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using TrueLayer.Models;

namespace TrueLayer.PaymentsProviders.Model;

public record SearchPaymentsProvidersRequest(AuthorizationFlow AuthorizationFlow,
List<string>? Countries = null,
List<string>? Currencies = null,
List<string>? ReleaseChannels = null,
List<string>? CustomerSegments = null,
Capabilities? Capabilities = null);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using System.Collections.Generic;

namespace TrueLayer.PaymentsProviders.Model;

public record SearchPaymentsProvidersResponse(List<PaymentsProvider> Items);
19 changes: 19 additions & 0 deletions src/TrueLayer/PaymentsProviders/PaymentsProvidersApi.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using TrueLayer.Auth;
using TrueLayer.Common;
Expand Down Expand Up @@ -47,5 +48,23 @@ public async Task<ApiResponse<PaymentsProvider>> GetPaymentsProvider(string id)
accessToken: authResponse.Data!.AccessToken
);
}

public async Task<ApiResponse<SearchPaymentsProvidersResponse>> SearchPaymentsProviders(SearchPaymentsProvidersRequest searchPaymentsProvidersRequest)
{
searchPaymentsProvidersRequest.NotNull(nameof(searchPaymentsProvidersRequest));

ApiResponse<GetAuthTokenResponse> authResponse = await _auth.GetAuthToken(new GetAuthTokenRequest("payments"));

if (!authResponse.IsSuccessful)
{
return new(authResponse.StatusCode, authResponse.TraceId);
}

return await _apiClient.PostAsync<SearchPaymentsProvidersResponse>(
_baseUri.Append("/search"),
request: searchPaymentsProvidersRequest,
accessToken: authResponse.Data!.AccessToken
);
}
}
}
29 changes: 28 additions & 1 deletion test/TrueLayer.AcceptanceTests/PaymentsProvidersTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using OneOf;
using Shouldly;
using TrueLayer.Models;
using TrueLayer.Payments.Model;
using TrueLayer.PaymentsProviders.Model;
using Xunit;
using AuthorizationFlow = TrueLayer.PaymentsProviders.Model.AuthorizationFlow;
using Provider = TrueLayer.Payments.Model.Provider;

namespace TrueLayer.AcceptanceTests
{
using ProviderUnion = OneOf<Provider.UserSelected, Provider.Preselected>;
using AccountIdentifierUnion = OneOf<AccountIdentifier.SortCodeAccountNumber, AccountIdentifier.Iban>;
using ProviderUnion = OneOf<Provider.UserSelected, Provider.Preselected>;

public class PaymentProvidersTests : IClassFixture<ApiTestFixture>
{
Expand Down Expand Up @@ -54,5 +59,27 @@ public async Task Can_get_payments_provider_with_mandates_capabilities()
response.Data.Capabilities.Mandates?.VrpSweeping.ShouldNotBeNull();
response.Data.Capabilities.Mandates?.VrpSweeping?.ReleaseChannel.ShouldNotBeNullOrWhiteSpace();
}

[Fact]
public async Task Can_search_payments_providers()
{
var searchRequest = new SearchPaymentsProvidersRequest(
new AuthorizationFlow(new AuthorizationFlowConfiguration())
);

var response = await _fixture.Client.PaymentsProviders.SearchPaymentsProviders(searchRequest);

response.IsSuccessful.ShouldBeTrue();
response.Data.ShouldNotBeNull();
response.Data.Items.ShouldNotBeNull().ShouldNotBeEmpty();
response.Data.Items.ForEach(pp =>
{
pp.Id.ShouldNotBeEmpty();
pp.DisplayName.ShouldNotBeNullOrWhiteSpace();
pp.CountryCode.ShouldNotBeNullOrWhiteSpace();
pp.Capabilities.Mandates?.VrpSweeping.ShouldNotBeNull();
pp.Capabilities.Mandates?.VrpSweeping?.ReleaseChannel.ShouldNotBeNullOrWhiteSpace();
});
}
}
}

0 comments on commit 30f0295

Please sign in to comment.