-
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-180] Add preselected scheme selection to preselected provider (#312
) Co-authored-by: Andrea Di Lisio <[email protected]>
- Loading branch information
1 parent
36cf23f
commit a51d5b8
Showing
16 changed files
with
437 additions
and
63 deletions.
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
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
2 changes: 1 addition & 1 deletion
2
...selection/InstantOnlySchemeSelection.java → ...eselected/InstantOnlySchemeSelection.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
2 changes: 1 addition & 1 deletion
2
...tion/InstantPreferredSchemeSelection.java → ...cted/InstantPreferredSchemeSelection.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
17 changes: 17 additions & 0 deletions
17
...elayer/java/payments/entities/schemeselection/preselected/PreselectedSchemeSelection.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.payments.entities.schemeselection.preselected; | ||
|
||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
@Getter | ||
@Builder | ||
@EqualsAndHashCode(callSuper = false) | ||
@ToString | ||
public class PreselectedSchemeSelection extends SchemeSelection { | ||
|
||
private final Type type = Type.PRESELECTED; | ||
|
||
private String schemeId; | ||
} |
92 changes: 92 additions & 0 deletions
92
...ava/com/truelayer/java/payments/entities/schemeselection/preselected/SchemeSelection.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,92 @@ | ||
package com.truelayer.java.payments.entities.schemeselection.preselected; | ||
|
||
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.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.ToString; | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = InstantOnlySchemeSelection.class) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = InstantOnlySchemeSelection.class, name = "instant_only"), | ||
@JsonSubTypes.Type(value = InstantPreferredSchemeSelection.class, name = "instant_preferred"), | ||
@JsonSubTypes.Type(value = PreselectedSchemeSelection.class, name = "preselected"), | ||
}) | ||
@Getter | ||
@ToString | ||
@EqualsAndHashCode | ||
public abstract class SchemeSelection { | ||
|
||
@JsonIgnore | ||
public abstract Type getType(); | ||
|
||
public static InstantOnlySchemeSelection.InstantOnlySchemeSelectionBuilder instantOnly() { | ||
return InstantOnlySchemeSelection.builder(); | ||
} | ||
|
||
public static InstantPreferredSchemeSelection.InstantPreferredSchemeSelectionBuilder instantPreferred() { | ||
return InstantPreferredSchemeSelection.builder(); | ||
} | ||
|
||
public static PreselectedSchemeSelection.PreselectedSchemeSelectionBuilder preselected() { | ||
return PreselectedSchemeSelection.builder(); | ||
} | ||
|
||
@JsonIgnore | ||
public boolean isInstantOnly() { | ||
return this instanceof InstantOnlySchemeSelection; | ||
} | ||
|
||
@JsonIgnore | ||
public boolean isInstantPreferred() { | ||
return this instanceof InstantPreferredSchemeSelection; | ||
} | ||
|
||
@JsonIgnore | ||
public boolean isPreselected() { | ||
return this instanceof PreselectedSchemeSelection; | ||
} | ||
|
||
@JsonIgnore | ||
public InstantOnlySchemeSelection asInstantOnly() { | ||
if (!isInstantOnly()) { | ||
throw new TrueLayerException(buildErrorMessage()); | ||
} | ||
return (InstantOnlySchemeSelection) this; | ||
} | ||
|
||
@JsonIgnore | ||
public InstantPreferredSchemeSelection asInstantPreferred() { | ||
if (!isInstantPreferred()) { | ||
throw new TrueLayerException(buildErrorMessage()); | ||
} | ||
return (InstantPreferredSchemeSelection) this; | ||
} | ||
|
||
@JsonIgnore | ||
public PreselectedSchemeSelection asPreselected() { | ||
if (!isPreselected()) { | ||
throw new TrueLayerException(buildErrorMessage()); | ||
} | ||
return (PreselectedSchemeSelection) this; | ||
} | ||
|
||
private String buildErrorMessage() { | ||
return String.format("Scheme selection is of type %s.", this.getClass().getSimpleName()); | ||
} | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public enum Type { | ||
INSTANT_ONLY("instant_only"), | ||
INSTANT_PREFERRED("instant_preferred"), | ||
PRESELECTED("preselected"); | ||
|
||
@JsonValue | ||
private final String type; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...layer/java/payments/entities/schemeselection/userselected/InstantOnlySchemeSelection.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,20 @@ | ||
package com.truelayer.java.payments.entities.schemeselection.userselected; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import lombok.experimental.Accessors; | ||
|
||
@Getter | ||
@Builder | ||
@EqualsAndHashCode(callSuper = false) | ||
@ToString | ||
public class InstantOnlySchemeSelection extends SchemeSelection { | ||
private final Type type = Type.INSTANT_ONLY; | ||
|
||
@Accessors(fluent = true) | ||
@JsonProperty // Jackson's @JsonProperty is required for serialization to work as expected | ||
private boolean allowRemitterFee; | ||
} |
20 changes: 20 additions & 0 deletions
20
.../java/payments/entities/schemeselection/userselected/InstantPreferredSchemeSelection.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,20 @@ | ||
package com.truelayer.java.payments.entities.schemeselection.userselected; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import lombok.experimental.Accessors; | ||
|
||
@Getter | ||
@Builder | ||
@EqualsAndHashCode(callSuper = false) | ||
@ToString | ||
public class InstantPreferredSchemeSelection extends SchemeSelection { | ||
private final Type type = Type.INSTANT_PREFERRED; | ||
|
||
@Accessors(fluent = true) | ||
@JsonProperty // Jackson's @JsonProperty is required for serialization to work as expected | ||
private boolean allowRemitterFee; | ||
} |
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
Oops, something went wrong.