Skip to content

Commit 32e3068

Browse files
committed
integration test
1 parent 5d87394 commit 32e3068

File tree

2 files changed

+116
-4
lines changed

2 files changed

+116
-4
lines changed

src/main/java/com/truelayer/java/payments/entities/StartAuthorizationFlowRequest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,13 @@ public StartAuthorizationFlowRequest build() {
100100
@ToString
101101
@EqualsAndHashCode
102102
@AllArgsConstructor
103+
@Getter
103104
public static class ProviderSelection {
104105
private Icon icon;
105106

106107
public ProviderSelection() {}
107108

109+
@Getter
108110
@NoArgsConstructor
109111
@AllArgsConstructor
110112
@EqualsAndHashCode
@@ -140,6 +142,7 @@ public static class Redirect {
140142
@Builder
141143
@ToString
142144
@EqualsAndHashCode
145+
@Getter
143146
public static class Consent {
144147
private final ActionType actionType;
145148
private final Requirements requirements;
@@ -157,14 +160,20 @@ public enum ActionType {
157160
@ToString
158161
@EqualsAndHashCode
159162
@Builder
163+
@Getter
160164
public static class Requirements {
161165
private final Map<String, String> pis;
162166

167+
private final AisRequirements ais;
168+
163169
@Builder
164170
@ToString
165171
@EqualsAndHashCode
172+
@Getter
166173
public static class AisRequirements {
167174

175+
private final List<Scope> scopes;
176+
168177
@RequiredArgsConstructor
169178
@Getter
170179
public enum Scope {

src/test/java/com/truelayer/java/integration/PaymentsIntegrationTests.java

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import com.truelayer.java.http.entities.Headers;
2020
import com.truelayer.java.http.entities.ProblemDetails;
2121
import com.truelayer.java.payments.entities.*;
22+
import com.truelayer.java.payments.entities.StartAuthorizationFlowRequest.ProviderSelection.Icon;
23+
import com.truelayer.java.payments.entities.StartAuthorizationFlowRequest.ProviderSelection.Icon.IconType;
2224
import com.truelayer.java.payments.entities.beneficiary.MerchantAccount;
2325
import com.truelayer.java.payments.entities.paymentdetail.PaymentDetail;
2426
import com.truelayer.java.payments.entities.paymentdetail.Status;
@@ -28,8 +30,8 @@
2830
import com.truelayer.java.payments.entities.providerselection.UserSelectedProviderSelection;
2931
import com.truelayer.java.payments.entities.schemeselection.userselected.SchemeSelection;
3032
import com.truelayer.java.payments.entities.verification.AutomatedVerification;
31-
import java.util.Collections;
32-
import java.util.UUID;
33+
import java.net.URI;
34+
import java.util.*;
3335
import java.util.stream.Stream;
3436
import lombok.SneakyThrows;
3537
import org.junit.jupiter.api.*;
@@ -323,8 +325,7 @@ public void shouldThrowARequestInvalidError() {
323325
.authorizationFlow(StartAuthorizationFlowRequest.builder()
324326
.schemeSelection(Collections.singletonMap("foo", "bar"))
325327
.providerSelection(StartAuthorizationFlowRequest.ProviderSelection.builder()
326-
.icon(new StartAuthorizationFlowRequest.ProviderSelection.Icon(
327-
StartAuthorizationFlowRequest.ProviderSelection.Icon.IconType.DEFAULT))
328+
.icon(new Icon(IconType.DEFAULT))
328329
.build())
329330
.build())
330331
.build();
@@ -594,4 +595,106 @@ private static Stream<Arguments> provideAutomatedVerifications() {
594595
.withRemitterDateOfBirth()
595596
.build()));
596597
}
598+
599+
@Deprecated
600+
@Test
601+
@DisplayName("It should create a payment with authorization_flow with deprecated provider selection")
602+
@SneakyThrows
603+
public void shouldCreatePaymentWithAuthorizationFlowDeprecated() {
604+
RequestStub.New()
605+
.method("post")
606+
.path(urlPathEqualTo("/connect/token"))
607+
.status(200)
608+
.bodyFile("auth/200.access_token.json")
609+
.build();
610+
RequestStub.New()
611+
.method("post")
612+
.path(urlPathEqualTo("/payments"))
613+
.withAuthorization()
614+
.withSignature()
615+
.withIdempotencyKey()
616+
.status(201)
617+
.bodyFile("payments/201.create_payment.AUTHORIZATION_REQUIRED.json")
618+
.build();
619+
620+
CreatePaymentRequest paymentRequest = CreatePaymentRequest.builder()
621+
.amountInMinor(100)
622+
.currency(CurrencyCode.GBP)
623+
.paymentMethod(PaymentMethod.bankTransfer().build())
624+
.authorizationFlow(StartAuthorizationFlowRequest.builder()
625+
.withProviderSelection()
626+
.build())
627+
.build();
628+
629+
tlClient.payments().createPayment(paymentRequest).get();
630+
631+
verifyGeneratedToken(Collections.singletonList(PAYMENTS));
632+
verify(postRequestedFor(urlPathEqualTo("/payments"))
633+
.withRequestBody(matchingJsonPath("$.amount_in_minor", equalTo("100")))
634+
.withRequestBody(matchingJsonPath("$.currency", equalTo("GBP")))
635+
.withRequestBody(matchingJsonPath("$.payment_method.type", equalTo("bank_transfer")))
636+
.withRequestBody(matchingJsonPath("$.authorization_flow.provider_selection", equalToJson("{}"))));
637+
}
638+
639+
@Deprecated
640+
@Test
641+
@DisplayName("It should create a payment with authorization_flow")
642+
@SneakyThrows
643+
public void shouldCreatePaymentWithAuthorizationFlow() {
644+
RequestStub.New()
645+
.method("post")
646+
.path(urlPathEqualTo("/connect/token"))
647+
.status(200)
648+
.bodyFile("auth/200.access_token.json")
649+
.build();
650+
RequestStub.New()
651+
.method("post")
652+
.path(urlPathEqualTo("/payments"))
653+
.withAuthorization()
654+
.withSignature()
655+
.withIdempotencyKey()
656+
.status(201)
657+
.bodyFile("payments/201.create_payment.AUTHORIZATION_REQUIRED.json")
658+
.build();
659+
660+
CreatePaymentRequest paymentRequest = CreatePaymentRequest.builder()
661+
.amountInMinor(100)
662+
.currency(CurrencyCode.GBP)
663+
.paymentMethod(PaymentMethod.bankTransfer().build())
664+
.authorizationFlow(StartAuthorizationFlowRequest.builder()
665+
.redirect(StartAuthorizationFlowRequest.Redirect.builder()
666+
.returnUri(URI.create("https://example.com/return"))
667+
.directReturnUri(URI.create("http://example.com/direct-return"))
668+
.build())
669+
.schemeSelection(Collections.singletonMap("foo", "bar"))
670+
.providerSelection(StartAuthorizationFlowRequest.ProviderSelection.builder()
671+
.icon(new Icon(IconType.EXTENDED))
672+
.build())
673+
.form(StartAuthorizationFlowRequest.Form.builder().build())
674+
.consent(StartAuthorizationFlowRequest.Consent.builder()
675+
.actionType(StartAuthorizationFlowRequest.Consent.ActionType.ADJACENT)
676+
.requirements(StartAuthorizationFlowRequest.Consent.Requirements.builder()
677+
.pis(Collections.singletonMap("req1", "foo"))
678+
.ais(
679+
StartAuthorizationFlowRequest.Consent.Requirements.AisRequirements
680+
.builder()
681+
// scopes
682+
.build())
683+
.build())
684+
.build())
685+
.build())
686+
.build();
687+
688+
tlClient.payments().createPayment(paymentRequest).get();
689+
690+
verifyGeneratedToken(Collections.singletonList(PAYMENTS));
691+
verify(postRequestedFor(urlPathEqualTo("/payments"))
692+
.withRequestBody(matchingJsonPath("$.amount_in_minor", equalTo("100")))
693+
.withRequestBody(matchingJsonPath("$.currency", equalTo("GBP")))
694+
.withRequestBody(matchingJsonPath("$.payment_method.type", equalTo("bank_transfer")))
695+
.withRequestBody(matchingJsonPath(
696+
"$.authorization_flow.redirect.return_uri", equalTo("https://example.com/return")))
697+
.withRequestBody(
698+
matchingJsonPath("$.authorization_flow.provider_selection.icon.type", equalTo("extended"))));
699+
}
597700
}

0 commit comments

Comments
 (0)