-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ACL-167] Add sub_merchants support to payouts (#320)
- Loading branch information
1 parent
9eb181b
commit 709dfe9
Showing
7 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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
17 changes: 17 additions & 0 deletions
17
src/main/java/com/truelayer/java/payouts/entities/submerchants/BusinessClient.java
This file contains 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,17 @@ | ||
package com.truelayer.java.payouts.entities.submerchants; | ||
|
||
import com.truelayer.java.entities.Address; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Builder | ||
@Getter | ||
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; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/truelayer/java/payouts/entities/submerchants/SubMerchants.java
This file contains 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,10 @@ | ||
package com.truelayer.java.payouts.entities.submerchants; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class SubMerchants { | ||
private UltimateCounterparty ultimateCounterparty; | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/truelayer/java/payouts/entities/submerchants/UltimateCounterparty.java
This file contains 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,46 @@ | ||
package com.truelayer.java.payouts.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")}) | ||
public abstract class UltimateCounterparty { | ||
|
||
@JsonIgnore | ||
public abstract Type getType(); | ||
|
||
@JsonIgnore | ||
public boolean isBusinessClient() { | ||
return this instanceof BusinessClient; | ||
} | ||
|
||
@JsonIgnore | ||
public BusinessClient asBusinessClient() { | ||
if (!isBusinessClient()) throw new TrueLayerException(buildErrorMessage()); | ||
return (BusinessClient) this; | ||
} | ||
|
||
public static BusinessClient.BusinessClientBuilder businessClient() { | ||
return new BusinessClient.BusinessClientBuilder(); | ||
} | ||
|
||
private String buildErrorMessage() { | ||
return String.format( | ||
"UltimateCounterparty is of type %s.", this.getClass().getSimpleName()); | ||
} | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum Type { | ||
BUSINESS_CLIENT("business_client"); | ||
|
||
@JsonValue | ||
private final String type; | ||
} | ||
} |
This file contains 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
27 changes: 27 additions & 0 deletions
27
...test/java/com/truelayer/java/payouts/entities/submerchants/UltimateCounterpartyTests.java
This file contains 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,27 @@ | ||
package com.truelayer.java.payouts.entities.submerchants; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class UltimateCounterpartyTests { | ||
|
||
@Test | ||
@DisplayName("It should yield true if instance is of type BusinessClient") | ||
public void shouldYieldTrueIfBusinessClient() { | ||
UltimateCounterparty sut = | ||
new BusinessClient.BusinessClientBuilder().tradingName("a-name").build(); | ||
|
||
assertTrue(sut.isBusinessClient()); | ||
} | ||
|
||
@Test | ||
@DisplayName("It should convert to an instance of class BusinessClient") | ||
public void shouldConvertToBusinessClient() { | ||
UltimateCounterparty sut = | ||
new BusinessClient.BusinessClientBuilder().tradingName("a-name").build(); | ||
|
||
assertDoesNotThrow(sut::asBusinessClient); | ||
} | ||
} |