-
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.
feat(ACL-162): supports for verified payins (#310)
- Loading branch information
Showing
8 changed files
with
225 additions
and
2 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
45 changes: 45 additions & 0 deletions
45
src/main/java/com/truelayer/java/payments/entities/verification/AutomatedVerification.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,45 @@ | ||
package com.truelayer.java.payments.entities.verification; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.Value; | ||
|
||
@Getter | ||
@Value | ||
@EqualsAndHashCode(callSuper = false) | ||
public class AutomatedVerification extends Verification { | ||
Verification.Type type = Type.AUTOMATED; | ||
|
||
boolean remitterName; | ||
|
||
boolean remitterDateOfBirth; | ||
|
||
@JsonIgnore | ||
public static AutomatedVerificationBuilder builder() { | ||
return new AutomatedVerificationBuilder(); | ||
} | ||
|
||
/** | ||
* Custom builder for the AutomatedVerification class that prevents setting remitter flags to false | ||
*/ | ||
public static class AutomatedVerificationBuilder { | ||
private boolean remitterName; | ||
|
||
private boolean remitterDateOfBirth; | ||
|
||
public AutomatedVerification.AutomatedVerificationBuilder withRemitterName() { | ||
this.remitterName = true; | ||
return this; | ||
} | ||
|
||
public AutomatedVerification.AutomatedVerificationBuilder withRemitterDateOfBirth() { | ||
this.remitterDateOfBirth = true; | ||
return this; | ||
} | ||
|
||
public AutomatedVerification build() { | ||
return new AutomatedVerification(remitterName, remitterDateOfBirth); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/com/truelayer/java/payments/entities/verification/Verification.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,44 @@ | ||
package com.truelayer.java.payments.entities.verification; | ||
|
||
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 = AutomatedVerification.class) | ||
@JsonSubTypes({@JsonSubTypes.Type(value = AutomatedVerification.class, name = "automated")}) | ||
@ToString | ||
@EqualsAndHashCode | ||
@Getter | ||
public abstract class Verification { | ||
@JsonIgnore | ||
public abstract Verification.Type getType(); | ||
|
||
@JsonIgnore | ||
public boolean isAutomated() { | ||
return this instanceof AutomatedVerification; | ||
} | ||
|
||
@JsonIgnore | ||
public AutomatedVerification asAutomated() { | ||
if (!isAutomated()) { | ||
throw new TrueLayerException( | ||
String.format("Verification is of type %s.", this.getClass().getSimpleName())); | ||
} | ||
return (AutomatedVerification) this; | ||
} | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum Type { | ||
AUTOMATED("automated"); | ||
|
||
@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
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
29 changes: 29 additions & 0 deletions
29
src/test/java/com/truelayer/java/payments/entities/verification/VerificationTests.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,29 @@ | ||
package com.truelayer.java.payments.entities.verification; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class VerificationTests { | ||
@Test | ||
@DisplayName("It should yield true if instance is of type AutomatedVerification") | ||
public void shouldYieldTrueIfAutomatedVerification() { | ||
Verification sut = | ||
AutomatedVerification.builder().withRemitterDateOfBirth().build(); | ||
|
||
assertTrue(sut.isAutomated()); | ||
} | ||
|
||
@Test | ||
@DisplayName("It should convert to an instance of class AutomatedVerification") | ||
public void shouldConvertToAutomatedVerification() { | ||
Verification sut = AutomatedVerification.builder() | ||
.withRemitterName() | ||
.withRemitterDateOfBirth() | ||
.build(); | ||
|
||
assertDoesNotThrow(sut::asAutomated); | ||
} | ||
} |
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