|
19 | 19 | import com.truelayer.java.http.entities.Headers; |
20 | 20 | import com.truelayer.java.http.entities.ProblemDetails; |
21 | 21 | 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; |
22 | 24 | import com.truelayer.java.payments.entities.beneficiary.MerchantAccount; |
23 | 25 | import com.truelayer.java.payments.entities.paymentdetail.PaymentDetail; |
24 | 26 | import com.truelayer.java.payments.entities.paymentdetail.Status; |
|
28 | 30 | import com.truelayer.java.payments.entities.providerselection.UserSelectedProviderSelection; |
29 | 31 | import com.truelayer.java.payments.entities.schemeselection.userselected.SchemeSelection; |
30 | 32 | 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.*; |
33 | 35 | import java.util.stream.Stream; |
34 | 36 | import lombok.SneakyThrows; |
35 | 37 | import org.junit.jupiter.api.*; |
@@ -323,8 +325,7 @@ public void shouldThrowARequestInvalidError() { |
323 | 325 | .authorizationFlow(StartAuthorizationFlowRequest.builder() |
324 | 326 | .schemeSelection(Collections.singletonMap("foo", "bar")) |
325 | 327 | .providerSelection(StartAuthorizationFlowRequest.ProviderSelection.builder() |
326 | | - .icon(new StartAuthorizationFlowRequest.ProviderSelection.Icon( |
327 | | - StartAuthorizationFlowRequest.ProviderSelection.Icon.IconType.DEFAULT)) |
| 328 | + .icon(new Icon(IconType.DEFAULT)) |
328 | 329 | .build()) |
329 | 330 | .build()) |
330 | 331 | .build(); |
@@ -594,4 +595,106 @@ private static Stream<Arguments> provideAutomatedVerifications() { |
594 | 595 | .withRemitterDateOfBirth() |
595 | 596 | .build())); |
596 | 597 | } |
| 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 | + } |
597 | 700 | } |
0 commit comments