|
33 | 33 | import com.truelayer.java.payments.entities.schemeselection.userselected.SchemeSelection; |
34 | 34 | import com.truelayer.java.payments.entities.submerchants.SubMerchants; |
35 | 35 | import com.truelayer.java.payments.entities.submerchants.UltimateCounterparty; |
| 36 | +import com.truelayer.java.payments.entities.userconsent.AuthorizationFlowCapturedConsent; |
| 37 | +import com.truelayer.java.payments.entities.userconsent.PrecapturedConsent; |
36 | 38 | import com.truelayer.java.payments.entities.verification.AutomatedVerification; |
37 | 39 | import java.net.URI; |
| 40 | +import java.time.ZonedDateTime; |
| 41 | +import java.time.format.DateTimeFormatter; |
38 | 42 | import java.util.*; |
39 | 43 | import java.util.stream.Stream; |
40 | 44 | import lombok.SneakyThrows; |
@@ -660,6 +664,8 @@ public void shouldCreatePaymentWithAuthorizationFlow() { |
660 | 664 | .bodyFile("payments/201.create_payment.AUTHORIZATION_REQUIRED.json") |
661 | 665 | .build(); |
662 | 666 |
|
| 667 | + ZonedDateTime consentCapturedAt = ZonedDateTime.now(); |
| 668 | + |
663 | 669 | CreatePaymentRequest paymentRequest = CreatePaymentRequest.builder() |
664 | 670 | .amountInMinor(100) |
665 | 671 | .currency(CurrencyCode.GBP) |
@@ -696,6 +702,9 @@ public void shouldCreatePaymentWithAuthorizationFlow() { |
696 | 702 | .build()) |
697 | 703 | .build()) |
698 | 704 | .riskAssessment(RiskAssessment.builder().segment("Flights").build()) |
| 705 | + .userConsent(PrecapturedConsent.builder() |
| 706 | + .capturedAt(consentCapturedAt) |
| 707 | + .build()) |
699 | 708 | .build(); |
700 | 709 |
|
701 | 710 | tlClient.payments().createPayment(paymentRequest).get(); |
@@ -729,6 +738,61 @@ public void shouldCreatePaymentWithAuthorizationFlow() { |
729 | 738 | .withRequestBody(matchingJsonPath("$.sub_merchants.ultimate_counterparty.id", equalTo("an-id"))) |
730 | 739 | .withRequestBody( |
731 | 740 | matchingJsonPath("$.sub_merchants.ultimate_counterparty.name", equalTo("business-name"))) |
732 | | - .withRequestBody(matchingJsonPath("$.risk_assessment.segment", equalTo("Flights")))); |
| 741 | + .withRequestBody(matchingJsonPath("$.risk_assessment.segment", equalTo("Flights"))) |
| 742 | + .withRequestBody(matchingJsonPath("$.user_consent.type", equalTo("precaptured"))) |
| 743 | + .withRequestBody(matchingJsonPath( |
| 744 | + "$.user_consent.captured_at", |
| 745 | + equalTo(consentCapturedAt |
| 746 | + .truncatedTo(java.time.temporal.ChronoUnit.SECONDS) |
| 747 | + .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME))))); |
| 748 | + } |
| 749 | + |
| 750 | + @Test |
| 751 | + @DisplayName("It should create a payment with hosted_page_parameters") |
| 752 | + @SneakyThrows |
| 753 | + public void shouldCreatePaymentWithHostedPageParameters() { |
| 754 | + RequestStub.New() |
| 755 | + .method("post") |
| 756 | + .path(urlPathEqualTo("/connect/token")) |
| 757 | + .status(200) |
| 758 | + .bodyFile("auth/200.access_token.json") |
| 759 | + .build(); |
| 760 | + RequestStub.New() |
| 761 | + .method("post") |
| 762 | + .path(urlPathEqualTo("/payments")) |
| 763 | + .withAuthorization() |
| 764 | + .withSignature() |
| 765 | + .withIdempotencyKey() |
| 766 | + .status(201) |
| 767 | + .bodyFile("payments/201.create_payment.AUTHORIZATION_REQUIRED.json") |
| 768 | + .build(); |
| 769 | + |
| 770 | + ZonedDateTime consentCapturedAt = ZonedDateTime.now(); |
| 771 | + |
| 772 | + CreatePaymentRequest paymentRequest = CreatePaymentRequest.builder() |
| 773 | + .amountInMinor(100) |
| 774 | + .currency(CurrencyCode.GBP) |
| 775 | + .paymentMethod(PaymentMethod.bankTransfer().build()) |
| 776 | + .hostedPage(HostedPageParameters.builder() |
| 777 | + .returnUri(URI.create("https://example.com/callback")) |
| 778 | + .countryCode(CountryCode.GB) |
| 779 | + .languageCode("en") |
| 780 | + .maxWaitForResults(300) |
| 781 | + .build()) |
| 782 | + .userConsent(AuthorizationFlowCapturedConsent.builder().build()) |
| 783 | + .build(); |
| 784 | + |
| 785 | + tlClient.payments().createPayment(paymentRequest).get(); |
| 786 | + |
| 787 | + verifyGeneratedToken(Collections.singletonList(PAYMENTS)); |
| 788 | + verify(postRequestedFor(urlPathEqualTo("/payments")) |
| 789 | + .withRequestBody(matchingJsonPath("$.amount_in_minor", equalTo("100"))) |
| 790 | + .withRequestBody(matchingJsonPath("$.currency", equalTo("GBP"))) |
| 791 | + .withRequestBody(matchingJsonPath("$.payment_method.type", equalTo("bank_transfer"))) |
| 792 | + .withRequestBody(matchingJsonPath("$.hosted_page.return_uri", equalTo("https://example.com/callback"))) |
| 793 | + .withRequestBody(matchingJsonPath("$.hosted_page.country_code", equalTo("GB"))) |
| 794 | + .withRequestBody(matchingJsonPath("$.hosted_page.language_code", equalTo("en"))) |
| 795 | + .withRequestBody(matchingJsonPath("$.hosted_page.max_wait_for_results", equalTo("300"))) |
| 796 | + .withRequestBody(matchingJsonPath("$.user_consent.type", equalTo("authorization_flow_captured")))); |
733 | 797 | } |
734 | 798 | } |
0 commit comments