|
34 | 34 | import com.truelayer.java.payments.entities.providerselection.ProviderSelection; |
35 | 35 | import com.truelayer.java.payments.entities.providerselection.UserSelectedProviderSelection; |
36 | 36 | import com.truelayer.java.payments.entities.schemeselection.preselected.SchemeSelection; |
| 37 | +import com.truelayer.java.payments.entities.submerchants.BusinessClient; |
| 38 | +import com.truelayer.java.payments.entities.submerchants.BusinessDivision; |
| 39 | +import com.truelayer.java.payments.entities.submerchants.SubMerchants; |
| 40 | +import com.truelayer.java.payments.entities.submerchants.UltimateCounterparty; |
37 | 41 | import com.truelayer.java.payments.entities.verification.AutomatedVerification; |
38 | 42 | import com.truelayer.java.payments.entities.verification.Verification; |
39 | 43 | import com.truelayer.java.versioninfo.LibraryInfoLoader; |
@@ -861,4 +865,109 @@ private static Stream<Arguments> provideAutomatedVerifications() { |
861 | 865 | .withRemitterDateOfBirth() |
862 | 866 | .build())); |
863 | 867 | } |
| 868 | + |
| 869 | + private static Stream<Arguments> provideSubMerchantsScenarios() { |
| 870 | + return Stream.of( |
| 871 | + Arguments.of( |
| 872 | + "BusinessClient", |
| 873 | + BusinessClient.builder() |
| 874 | + .tradingName("Test Trading Ltd") |
| 875 | + .commercialName("Test Commercial Name") |
| 876 | + .url("https://example.com") |
| 877 | + .mcc("5999") |
| 878 | + .registrationNumber("12345678") |
| 879 | + .address(Address.builder() |
| 880 | + .addressLine1("123 Test Street") |
| 881 | + .city("London") |
| 882 | + .state("Greater London") |
| 883 | + .zip("EC1R 4RB") |
| 884 | + .countryCode("GB") |
| 885 | + .build()) |
| 886 | + .build()), |
| 887 | + Arguments.of( |
| 888 | + "BusinessDivision", |
| 889 | + BusinessDivision.builder() |
| 890 | + .id("division-123") |
| 891 | + .name("Test Division") |
| 892 | + .build())); |
| 893 | + } |
| 894 | + |
| 895 | + @ParameterizedTest |
| 896 | + @MethodSource("provideSubMerchantsScenarios") |
| 897 | + @DisplayName("It should create and get a payment with sub-merchants information") |
| 898 | + @SneakyThrows |
| 899 | + public void shouldCreateAPaymentWithSubMerchants( |
| 900 | + String counterpartyType, UltimateCounterparty ultimateCounterparty) { |
| 901 | + // create payment with sub-merchants |
| 902 | + SubMerchants subMerchants = SubMerchants.builder() |
| 903 | + .ultimateCounterparty(ultimateCounterparty) |
| 904 | + .build(); |
| 905 | + |
| 906 | + CreatePaymentRequest paymentRequest = buildPaymentRequestWithSubMerchants( |
| 907 | + buildPreselectedProviderSelection(), CurrencyCode.GBP, subMerchants); |
| 908 | + |
| 909 | + ApiResponse<CreatePaymentResponse> createPaymentResponse = |
| 910 | + tlClient.payments().createPayment(paymentRequest).get(); |
| 911 | + |
| 912 | + assertNotError(createPaymentResponse); |
| 913 | + assertTrue(createPaymentResponse.getData().isAuthorizationRequired()); |
| 914 | + |
| 915 | + // get it by id and verify sub-merchants are preserved |
| 916 | + ApiResponse<PaymentDetail> getPaymentByIdResponse = tlClient.payments() |
| 917 | + .getPayment(createPaymentResponse.getData().getId()) |
| 918 | + .get(); |
| 919 | + |
| 920 | + assertNotError(getPaymentByIdResponse); |
| 921 | + |
| 922 | + // Verify the sub-merchants information is returned correctly |
| 923 | + PaymentDetail paymentDetail = getPaymentByIdResponse.getData(); |
| 924 | + assertNotNull(paymentDetail.getSubMerchants(), "Sub-merchants should not be null"); |
| 925 | + assertEquals( |
| 926 | + subMerchants.getUltimateCounterparty().getType(), |
| 927 | + paymentDetail.getSubMerchants().getUltimateCounterparty().getType(), |
| 928 | + "Ultimate counterparty type should match"); |
| 929 | + |
| 930 | + // Verify type-specific fields |
| 931 | + if (ultimateCounterparty instanceof BusinessClient) { |
| 932 | + BusinessClient original = (BusinessClient) ultimateCounterparty; |
| 933 | + BusinessClient returned = |
| 934 | + (BusinessClient) paymentDetail.getSubMerchants().getUltimateCounterparty(); |
| 935 | + assertEquals(original.getTradingName(), returned.getTradingName(), "Trading name should match"); |
| 936 | + assertEquals(original.getCommercialName(), returned.getCommercialName(), "Commercial name should match"); |
| 937 | + assertEquals(original.getMcc(), returned.getMcc(), "MCC should match"); |
| 938 | + } else if (ultimateCounterparty instanceof BusinessDivision) { |
| 939 | + BusinessDivision original = (BusinessDivision) ultimateCounterparty; |
| 940 | + BusinessDivision returned = |
| 941 | + (BusinessDivision) paymentDetail.getSubMerchants().getUltimateCounterparty(); |
| 942 | + assertEquals(original.getId(), returned.getId(), "Division ID should match"); |
| 943 | + assertEquals(original.getName(), returned.getName(), "Division name should match"); |
| 944 | + } |
| 945 | + } |
| 946 | + |
| 947 | + @SneakyThrows |
| 948 | + private CreatePaymentRequest buildPaymentRequestWithSubMerchants( |
| 949 | + ProviderSelection providerSelection, CurrencyCode currencyCode, SubMerchants subMerchants) { |
| 950 | + return CreatePaymentRequest.builder() |
| 951 | + .amountInMinor(ThreadLocalRandom.current().nextInt(50, 500)) |
| 952 | + .currency(currencyCode) |
| 953 | + .paymentMethod(PaymentMethod.bankTransfer() |
| 954 | + .providerSelection(providerSelection) |
| 955 | + .beneficiary(buildBeneficiary(currencyCode)) |
| 956 | + .build()) |
| 957 | + .user(User.builder() |
| 958 | + .name("John Smith") |
| 959 | + .email("john.smith@example.com") |
| 960 | + .dateOfBirth(LocalDate.now()) |
| 961 | + .address(Address.builder() |
| 962 | + .addressLine1("123 Main Street") |
| 963 | + .city("London") |
| 964 | + .state("Greater London") |
| 965 | + .zip("EC1R 4RB") |
| 966 | + .countryCode("GB") |
| 967 | + .build()) |
| 968 | + .build()) |
| 969 | + .metadata(Collections.singletonMap("a_custom_key", "a-custom-value")) |
| 970 | + .subMerchants(subMerchants) |
| 971 | + .build(); |
| 972 | + } |
864 | 973 | } |
0 commit comments