Skip to content

Commit

Permalink
add search payments providers endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tl-luca-baggi committed Dec 4, 2024
1 parent d93c669 commit 860df2d
Show file tree
Hide file tree
Showing 26 changed files with 421 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Main properties
group=com.truelayer
archivesBaseName=truelayer-java
version=16.1.0
version=16.2.0

# Artifacts properties
sonatype_repository_url=https://s01.oss.sonatype.org/service/local/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.truelayer.java.entities.RequestScopes;
import com.truelayer.java.http.entities.ApiResponse;
import com.truelayer.java.paymentsproviders.entities.PaymentsProvider;
import com.truelayer.java.paymentsproviders.entities.SearchPaymentProvidersRequest;
import com.truelayer.java.paymentsproviders.entities.SearchPaymentProvidersResponse;
import java.util.concurrent.CompletableFuture;
import retrofit2.http.GET;
import retrofit2.http.Path;
import retrofit2.http.Tag;
import retrofit2.http.*;

/**
* Interface that models /payments-providers/* endpoints
Expand All @@ -16,4 +16,8 @@ public interface IPaymentsProvidersApi {
@GET("/payments-providers/{id}")
CompletableFuture<ApiResponse<PaymentsProvider>> getProvider(
@Tag RequestScopes scopes, @Path("id") String providerId);

@POST("/payments-providers/search")
CompletableFuture<ApiResponse<SearchPaymentProvidersResponse>> searchPaymentProviders(
@Tag RequestScopes scopes, @Body SearchPaymentProvidersRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.truelayer.java.http.entities.ApiResponse;
import com.truelayer.java.paymentsproviders.entities.PaymentsProvider;
import com.truelayer.java.paymentsproviders.entities.SearchPaymentProvidersRequest;
import com.truelayer.java.paymentsproviders.entities.SearchPaymentProvidersResponse;
import java.util.concurrent.CompletableFuture;

/**
Expand All @@ -19,4 +21,14 @@ public interface IPaymentsProvidersHandler {
* @see <a href="https://docs.truelayer.com/reference/get-payment-provider"><i>Get Payment Provider</i> API reference</a>
*/
CompletableFuture<ApiResponse<PaymentsProvider>> getProvider(String providerId);

/**
* Returns a list of payments providers.
*
* @param request the request with filters to search providers
* @return the response of the <i>Search Payments Providers</i> operation
* @see <a href="https://docs.truelayer.com/reference/search-payment-providers"><i>Search Payment Providers</i> API reference</a>
*/
CompletableFuture<ApiResponse<SearchPaymentProvidersResponse>> searchProviders(
SearchPaymentProvidersRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.truelayer.java.entities.RequestScopes;
import com.truelayer.java.http.entities.ApiResponse;
import com.truelayer.java.paymentsproviders.entities.PaymentsProvider;
import com.truelayer.java.paymentsproviders.entities.SearchPaymentProvidersRequest;
import com.truelayer.java.paymentsproviders.entities.SearchPaymentProvidersResponse;
import java.util.concurrent.CompletableFuture;
import lombok.Builder;

Expand All @@ -29,4 +31,10 @@ public RequestScopes getRequestScopes() {
public CompletableFuture<ApiResponse<PaymentsProvider>> getProvider(String providerId) {
return paymentsProvidersApi.getProvider(getRequestScopes(), providerId);
}

@Override
public CompletableFuture<ApiResponse<SearchPaymentProvidersResponse>> searchProviders(
SearchPaymentProvidersRequest request) {
return paymentsProvidersApi.searchPaymentProviders(getRequestScopes(), request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.truelayer.java.paymentsproviders.entities;

import java.util.List;
import lombok.*;

@Builder
@Getter
@ToString
@EqualsAndHashCode
public class AisConsent {
private List<Scope> scopes;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.truelayer.java.paymentsproviders.entities;

import lombok.*;

@Builder
@Getter
@ToString
@EqualsAndHashCode
public class AuthorizationFlow {
private Configuration configuration;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import com.truelayer.java.entities.ProviderAvailability;
import com.truelayer.java.payments.entities.ReleaseChannel;
import java.util.List;
import lombok.Value;
import lombok.*;

@Value
@Builder
@Getter
@ToString
@EqualsAndHashCode
public class BankTransferCapabilities {
ReleaseChannel releaseChannel;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.truelayer.java.paymentsproviders.entities;

import lombok.Value;
import lombok.*;

@Value
@Builder
@Getter
@ToString
@EqualsAndHashCode
public class Capabilities {
PaymentsCapabilities payments;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.truelayer.java.paymentsproviders.entities;

import lombok.*;

@Builder
@Getter
@ToString
@EqualsAndHashCode
public class Configuration {
private ProviderSelection providerSelection;

private Redirect redirect;

private Form form;

private Consent consent;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.truelayer.java.paymentsproviders.entities;

import lombok.*;

@Builder
@Getter
@ToString
@EqualsAndHashCode
public class Consent {
private Requirements requirements;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.truelayer.java.paymentsproviders.entities;

import java.util.List;
import lombok.*;

@Builder
@Getter
@ToString
@EqualsAndHashCode
public class Form {
private List<InputType> inputTypes;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.truelayer.java.paymentsproviders.entities;

import lombok.*;

@Builder
@Getter
@ToString
@EqualsAndHashCode
public class Icon {
private IconType type;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.truelayer.java.paymentsproviders.entities;

import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Getter
public enum IconType {
DEFAULT("default"),
EXTENDED("extended"),
EXTENDED_SMALL("extended_small"),
EXTENDED_MEDIUM("extended_medium"),
EXTENDED_LARGE("extended_large");

@JsonValue
private final String iconType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.truelayer.java.paymentsproviders.entities;

import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Getter
public enum InputType {
TEXT("text"),
TEXT_WITH_IMAGE("text_with_image"),
SELECT("select");

@JsonValue
private final String inputType;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.truelayer.java.paymentsproviders.entities;

import lombok.Value;
import lombok.*;

@Value
@Builder
@Getter
@ToString
@EqualsAndHashCode
public class MandatesCapabilities {
VrpSweepingCapabilities vrpSweeping;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.truelayer.java.paymentsproviders.entities;

import lombok.Value;
import lombok.*;

@Value
@Builder
@Getter
@ToString
@EqualsAndHashCode
public class PaymentsCapabilities {
BankTransferCapabilities bankTransfer;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.truelayer.java.paymentsproviders.entities;

import lombok.*;

@Builder
@Getter
@ToString
@EqualsAndHashCode
public class PisConsent {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.truelayer.java.paymentsproviders.entities;

import lombok.*;

@Builder
@Getter
@ToString
@EqualsAndHashCode
public class ProviderSelection {
private Icon icon;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.truelayer.java.paymentsproviders.entities;

import lombok.*;

@Builder
@Getter
@ToString
@EqualsAndHashCode
public class Redirect {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.truelayer.java.paymentsproviders.entities;

import lombok.*;

@Builder
@Getter
@ToString
@EqualsAndHashCode
public class Requirements {
private PisConsent pis;

private AisConsent ais;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.truelayer.java.paymentsproviders.entities;

import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Getter
public enum Scope {
ACCOUNTS("accounts"),
BALANCE("balance");

@JsonValue
private final String scope;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.truelayer.java.paymentsproviders.entities;

import com.truelayer.java.entities.CurrencyCode;
import com.truelayer.java.payments.entities.CountryCode;
import com.truelayer.java.payments.entities.CustomerSegment;
import com.truelayer.java.payments.entities.ReleaseChannel;
import java.util.List;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

@Builder
@Getter
@ToString
@EqualsAndHashCode
public class SearchPaymentProvidersRequest {
private List<CountryCode> countries;

private List<CurrencyCode> currencies;

private ReleaseChannel releaseChannel;

private List<CustomerSegment> customerSegments;

private Capabilities capabilities;

private AuthorizationFlow authorizationFlow;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.truelayer.java.paymentsproviders.entities;

import java.util.List;
import lombok.Value;

@Value
public class SearchPaymentProvidersResponse {
List<PaymentsProvider> items;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
import static com.truelayer.java.TestUtils.assertNotError;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.truelayer.java.entities.CurrencyCode;
import com.truelayer.java.http.entities.ApiResponse;
import com.truelayer.java.paymentsproviders.entities.PaymentsProvider;
import com.truelayer.java.payments.entities.CountryCode;
import com.truelayer.java.payments.entities.CustomerSegment;
import com.truelayer.java.payments.entities.ReleaseChannel;
import com.truelayer.java.paymentsproviders.entities.*;
import java.util.List;
import lombok.SneakyThrows;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
Expand All @@ -25,4 +30,31 @@ public void shouldGetAPaymentsProviderById() {
assertNotError(getPaymentsProviderResponse);
assertEquals(getPaymentsProviderResponse.getData().getId(), PROVIDER_ID);
}

@Test
@DisplayName("It should search for payments providers")
@SneakyThrows
public void shouldSearchPaymentsProviders() {
SearchPaymentProvidersRequest request = SearchPaymentProvidersRequest.builder()
.countries(List.of(CountryCode.GB))
.currencies(List.of(CurrencyCode.GBP))
.releaseChannel(ReleaseChannel.PRIVATE_BETA)
.capabilities(Capabilities.builder()
.payments(PaymentsCapabilities.builder()
.bankTransfer(BankTransferCapabilities.builder().build())
.build())
.build())
.customerSegments(List.of(CustomerSegment.RETAIL))
.authorizationFlow(AuthorizationFlow.builder()
.configuration(Configuration.builder()
.redirect(Redirect.builder().build())
.build())
.build())
.build();

ApiResponse<SearchPaymentProvidersResponse> searchPaymentsProvidersResponse =
tlClient.paymentsProviders().searchProviders(request).get();

assertNotError(searchPaymentsProvidersResponse);
}
}
Loading

0 comments on commit 860df2d

Please sign in to comment.