-
Notifications
You must be signed in to change notification settings - Fork 10
[ACL-290] Add sub_merchants support to Payments module #360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
10fb6fb
[ACL-290] Add sub_merchants support to Payments module
federico1525 fc9a509
Merge branch 'main' into feature/acl-290-payments-submerchants
dili91 294331d
Add files to support developing with Claude Code [skip ci]
dili91 d3edcc5
Address PR feedback: add Javadoc and bump version
federico1525 a992662
Remove .claude folder from git tracking
federico1525 b25cf4e
Merge latest changes from main
federico1525 e4ab152
Add acceptance test for sub-merchants functionality
federico1525 b4ce564
Apply code formatting with spotless
federico1525 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,8 @@ build | |
| .idea | ||
|
|
||
| #OSX | ||
| .DS_Store | ||
| .DS_Store | ||
|
|
||
| #Claude Code | ||
| .claude/ | ||
| CLAUDE.local.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/com/truelayer/java/payments/entities/submerchants/BusinessClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.truelayer.java.payments.entities.submerchants; | ||
|
|
||
| import com.truelayer.java.entities.Address; | ||
| import lombok.Builder; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.ToString; | ||
|
|
||
| @Builder | ||
| @Getter | ||
| @ToString | ||
| @EqualsAndHashCode(callSuper = false) | ||
| public class BusinessClient extends UltimateCounterparty { | ||
| private final Type type = Type.BUSINESS_CLIENT; | ||
| private String tradingName; | ||
| private String commercialName; | ||
| private String url; | ||
| private String mcc; | ||
| private String registrationNumber; | ||
| private Address address; | ||
| } |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/truelayer/java/payments/entities/submerchants/BusinessDivision.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.truelayer.java.payments.entities.submerchants; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.ToString; | ||
|
|
||
| @Builder | ||
| @Getter | ||
| @ToString | ||
| @EqualsAndHashCode(callSuper = false) | ||
| public class BusinessDivision extends UltimateCounterparty { | ||
| private final Type type = Type.BUSINESS_DIVISION; | ||
| private String id; | ||
| private String name; | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/truelayer/java/payments/entities/submerchants/SubMerchants.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.truelayer.java.payments.entities.submerchants; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.Getter; | ||
| import lombok.ToString; | ||
|
|
||
| @Builder | ||
| @Getter | ||
| @ToString | ||
| @EqualsAndHashCode | ||
| public class SubMerchants { | ||
| private UltimateCounterparty ultimateCounterparty; | ||
| } |
65 changes: 65 additions & 0 deletions
65
src/main/java/com/truelayer/java/payments/entities/submerchants/UltimateCounterparty.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package com.truelayer.java.payments.entities.submerchants; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
| import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
| import com.fasterxml.jackson.annotation.JsonValue; | ||
| import com.truelayer.java.TrueLayerException; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = BusinessClient.class) | ||
| @JsonSubTypes({ | ||
| @JsonSubTypes.Type(value = BusinessClient.class, name = "business_client"), | ||
| @JsonSubTypes.Type(value = BusinessDivision.class, name = "business_division") | ||
| }) | ||
| public abstract class UltimateCounterparty { | ||
|
|
||
| @JsonIgnore | ||
| public abstract Type getType(); | ||
|
|
||
| @JsonIgnore | ||
| public boolean isBusinessClient() { | ||
| return this instanceof BusinessClient; | ||
| } | ||
|
|
||
| @JsonIgnore | ||
| public boolean isBusinessDivision() { | ||
| return this instanceof BusinessDivision; | ||
| } | ||
|
|
||
| @JsonIgnore | ||
| public BusinessClient asBusinessClient() { | ||
| if (!isBusinessClient()) throw new TrueLayerException(buildErrorMessage()); | ||
| return (BusinessClient) this; | ||
| } | ||
|
|
||
| @JsonIgnore | ||
| public BusinessDivision asBusinessDivision() { | ||
| if (!isBusinessDivision()) throw new TrueLayerException(buildErrorMessage()); | ||
| return (BusinessDivision) this; | ||
| } | ||
|
|
||
| public static BusinessClient.BusinessClientBuilder businessClient() { | ||
| return new BusinessClient.BusinessClientBuilder(); | ||
| } | ||
|
|
||
| public static BusinessDivision.BusinessDivisionBuilder businessDivision() { | ||
| return new BusinessDivision.BusinessDivisionBuilder(); | ||
| } | ||
|
|
||
| private String buildErrorMessage() { | ||
| return String.format( | ||
| "UltimateCounterparty is of type %s.", this.getClass().getSimpleName()); | ||
| } | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum Type { | ||
| BUSINESS_CLIENT("business_client"), | ||
| BUSINESS_DIVISION("business_division"); | ||
|
|
||
| @JsonValue | ||
| private final String type; | ||
| } | ||
| } |
103 changes: 103 additions & 0 deletions
103
src/test/java/com/truelayer/java/integration/PaymentSubMerchantsIntegrationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| package com.truelayer.java.integration; | ||
|
|
||
| import static com.github.tomakehurst.wiremock.client.WireMock.*; | ||
| import static com.truelayer.java.Constants.Scopes.PAYMENTS; | ||
| import static com.truelayer.java.TestUtils.assertNotError; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import com.truelayer.java.TestUtils.RequestStub; | ||
| import com.truelayer.java.http.entities.ApiResponse; | ||
| import com.truelayer.java.payments.entities.paymentdetail.ExecutedPaymentDetail; | ||
| import com.truelayer.java.payments.entities.paymentdetail.PaymentDetail; | ||
| import com.truelayer.java.payments.entities.submerchants.BusinessClient; | ||
| import com.truelayer.java.payments.entities.submerchants.UltimateCounterparty; | ||
| import java.util.Collections; | ||
| import lombok.SneakyThrows; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class PaymentSubMerchantsIntegrationTest extends IntegrationTests { | ||
|
|
||
| @Test | ||
| @DisplayName("It should deserialize payment response with sub_merchants") | ||
| @SneakyThrows | ||
| void shouldDeserializePaymentWithSubMerchants() { | ||
| String paymentId = "payment-id"; | ||
|
|
||
| RequestStub.New() | ||
| .method("post") | ||
| .path(urlPathEqualTo("/connect/token")) | ||
| .status(200) | ||
| .bodyFile("auth/200.access_token.json") | ||
| .build(); | ||
|
|
||
| RequestStub.New() | ||
| .method("get") | ||
| .path(urlPathEqualTo(String.format("/payments/%s", paymentId))) | ||
| .status(200) | ||
| .bodyFile("payments/200.get_payment_by_id.with_submerchants.json") | ||
| .build(); | ||
|
|
||
| ApiResponse<PaymentDetail> response = | ||
| tlClient.payments().getPayment(paymentId).get(); | ||
|
|
||
| verifyGeneratedToken(Collections.singletonList(PAYMENTS)); | ||
| assertNotError(response); | ||
|
|
||
| PaymentDetail result = response.getData(); | ||
| assertNotNull(result); | ||
| assertTrue(result.isExecuted()); | ||
|
|
||
| ExecutedPaymentDetail executedPayment = result.asExecuted(); | ||
| assertNotNull(executedPayment.getSubMerchants()); | ||
| assertNotNull(executedPayment.getSubMerchants().getUltimateCounterparty()); | ||
|
|
||
| UltimateCounterparty ultimateCounterparty = | ||
| executedPayment.getSubMerchants().getUltimateCounterparty(); | ||
| assertTrue(ultimateCounterparty.isBusinessClient()); | ||
|
|
||
| BusinessClient businessClient = ultimateCounterparty.asBusinessClient(); | ||
| assertEquals("Example Trading Ltd", businessClient.getTradingName()); | ||
| assertEquals("Example Commercial Name", businessClient.getCommercialName()); | ||
| assertEquals("https://example.com", businessClient.getUrl()); | ||
| assertEquals("1234", businessClient.getMcc()); | ||
| assertEquals("12345678", businessClient.getRegistrationNumber()); | ||
| assertNotNull(businessClient.getAddress()); | ||
| assertEquals("London", businessClient.getAddress().getCity()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("It should handle payment response without sub_merchants (backward compatibility)") | ||
| @SneakyThrows | ||
| void shouldHandlePaymentWithoutSubMerchants() { | ||
| String paymentId = "payment-id"; | ||
|
|
||
| RequestStub.New() | ||
| .method("post") | ||
| .path(urlPathEqualTo("/connect/token")) | ||
| .status(200) | ||
| .bodyFile("auth/200.access_token.json") | ||
| .build(); | ||
|
|
||
| RequestStub.New() | ||
| .method("get") | ||
| .path(urlPathEqualTo(String.format("/payments/%s", paymentId))) | ||
| .status(200) | ||
| .bodyFile("payments/200.get_payment_by_id.bank_transfer.executed.json") | ||
| .build(); | ||
|
|
||
| ApiResponse<PaymentDetail> response = | ||
| tlClient.payments().getPayment(paymentId).get(); | ||
|
|
||
| verifyGeneratedToken(Collections.singletonList(PAYMENTS)); | ||
| assertNotError(response); | ||
|
|
||
| PaymentDetail result = response.getData(); | ||
| assertNotNull(result); | ||
| assertTrue(result.isExecuted()); | ||
|
|
||
| ExecutedPaymentDetail executedPayment = result.asExecuted(); | ||
| // subMerchants should be null for backward compatibility | ||
| assertNull(executedPayment.getSubMerchants()); | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
src/test/java/com/truelayer/java/payments/entities/CreatePaymentRequestSubMerchantsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package com.truelayer.java.payments.entities; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
|
||
| import com.truelayer.java.entities.CurrencyCode; | ||
| import com.truelayer.java.entities.User; | ||
| import com.truelayer.java.payments.entities.paymentmethod.BankTransfer; | ||
| import com.truelayer.java.payments.entities.submerchants.BusinessClient; | ||
| import com.truelayer.java.payments.entities.submerchants.SubMerchants; | ||
| import com.truelayer.java.payments.entities.submerchants.UltimateCounterparty; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class CreatePaymentRequestSubMerchantsTest { | ||
|
|
||
| @Test | ||
| void canCreatePaymentRequestWithSubMerchants() { | ||
| BusinessClient businessClient = UltimateCounterparty.businessClient() | ||
| .tradingName("Test Trading Name") | ||
| .build(); | ||
|
|
||
| SubMerchants subMerchants = | ||
| SubMerchants.builder().ultimateCounterparty(businessClient).build(); | ||
|
|
||
| CreatePaymentRequest request = CreatePaymentRequest.builder() | ||
| .amountInMinor(1000) | ||
| .currency(CurrencyCode.GBP) | ||
| .paymentMethod(BankTransfer.builder().build()) | ||
| .user(User.builder().id("user-123").build()) | ||
| .subMerchants(subMerchants) | ||
| .build(); | ||
|
|
||
| assertNotNull(request); | ||
| assertNotNull(request.getSubMerchants()); | ||
| assertEquals( | ||
| UltimateCounterparty.Type.BUSINESS_CLIENT, | ||
| request.getSubMerchants().getUltimateCounterparty().getType()); | ||
| } | ||
| } |
61 changes: 61 additions & 0 deletions
61
src/test/java/com/truelayer/java/payments/entities/submerchants/SubMerchantsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package com.truelayer.java.payments.entities.submerchants; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
|
||
| import com.truelayer.java.entities.Address; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class SubMerchantsTest { | ||
|
|
||
| @Test | ||
| void canCreateBusinessClient() { | ||
| Address address = Address.builder() | ||
| .addressLine1("123 Test Street") | ||
| .city("London") | ||
| .countryCode("GB") | ||
| .build(); | ||
|
|
||
| BusinessClient businessClient = UltimateCounterparty.businessClient() | ||
| .tradingName("Test Trading Name") | ||
| .commercialName("Test Commercial Name") | ||
| .url("https://example.com") | ||
| .mcc("1234") | ||
| .registrationNumber("REG123") | ||
| .address(address) | ||
| .build(); | ||
|
|
||
| assertNotNull(businessClient); | ||
| assertEquals(UltimateCounterparty.Type.BUSINESS_CLIENT, businessClient.getType()); | ||
| assertEquals("Test Trading Name", businessClient.getTradingName()); | ||
| } | ||
|
|
||
| @Test | ||
| void canCreateBusinessDivision() { | ||
| BusinessDivision businessDivision = UltimateCounterparty.businessDivision() | ||
| .id("division-123") | ||
| .name("Test Division") | ||
| .build(); | ||
|
|
||
| assertNotNull(businessDivision); | ||
| assertEquals(UltimateCounterparty.Type.BUSINESS_DIVISION, businessDivision.getType()); | ||
| assertEquals("division-123", businessDivision.getId()); | ||
| assertEquals("Test Division", businessDivision.getName()); | ||
| } | ||
|
|
||
| @Test | ||
| void canCreateSubMerchantsWithBusinessClient() { | ||
| BusinessClient businessClient = UltimateCounterparty.businessClient() | ||
| .tradingName("Test Trading Name") | ||
| .build(); | ||
|
|
||
| SubMerchants subMerchants = | ||
| SubMerchants.builder().ultimateCounterparty(businessClient).build(); | ||
|
|
||
| assertNotNull(subMerchants); | ||
| assertNotNull(subMerchants.getUltimateCounterparty()); | ||
| assertEquals( | ||
| UltimateCounterparty.Type.BUSINESS_CLIENT, | ||
| subMerchants.getUltimateCounterparty().getType()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.