Skip to content

Commit

Permalink
feat(ACL-162): supports for verified payins (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
dili91 authored Sep 10, 2024
1 parent 600f252 commit 85036c8
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Main properties
group=com.truelayer
archivesBaseName=truelayer-java
version=13.1.2
version=13.2.0

# Artifacts properties
sonatype_repository_url=https://s01.oss.sonatype.org/service/local/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.truelayer.java.payments.entities.beneficiary;

import com.truelayer.java.payments.entities.verification.Verification;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand All @@ -15,4 +16,6 @@ public class MerchantAccount extends Beneficiary {
private String accountHolderName;

private String reference;

private Verification verification;
}
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);
}
}
}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import com.truelayer.java.payments.entities.providerselection.ProviderSelection;
import com.truelayer.java.payments.entities.providerselection.UserSelectedProviderSelection;
import com.truelayer.java.payments.entities.schemeselection.SchemeSelection;
import com.truelayer.java.payments.entities.verification.AutomatedVerification;
import com.truelayer.java.payments.entities.verification.Verification;
import com.truelayer.java.versioninfo.LibraryInfoLoader;
import java.net.URI;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -118,6 +120,47 @@ public void itShouldCreateAPaymentWithSignupPlusIntention() {
assertNotError(createPaymentResponse);
}

@ParameterizedTest
@DisplayName("It should create a payment with automated verification")
@MethodSource("provideAutomatedVerifications")
@SneakyThrows
public void itShouldCreateAPaymentWithAutomatedVerification(Verification verification) {
CurrencyCode currency = CurrencyCode.GBP;
MerchantAccount account = getMerchantAccount(currency);
CreatePaymentRequest.CreatePaymentRequestBuilder builder = CreatePaymentRequest.builder()
.amountInMinor(100)
.currency(currency)
.paymentMethod(PaymentMethod.bankTransfer()
.providerSelection(ProviderSelection.preselected()
.providerId(PROVIDER_ID)
.build())
.beneficiary(Beneficiary.merchantAccount()
.merchantAccountId(account.getId())
.reference(UUID.randomUUID().toString())
.verification(verification)
.build())
.build())
.user(User.builder()
.name("Andrea Di Lisio")
.email("andrea@truelayer.com")
.dateOfBirth(LocalDate.now())
.address(Address.builder()
.addressLine1("1 Hardwick Street")
.city("London")
.state("Greater London")
.zip("EC1R 4RB")
.countryCode("GB")
.build())
.build());

ApiResponse<CreatePaymentResponse> createPaymentResponse = tlClient.payments()
.createPayment(buildPaymentRequestWithProviderSelection(
buildPreselectedProviderSelection(), CurrencyCode.GBP, null, null))
.get();

assertNotError(createPaymentResponse);
}

@Test
@DisplayName("It should create and get by id a payment with preselected provider")
@SneakyThrows
Expand Down Expand Up @@ -736,4 +779,12 @@ private static AuthorizationFlowResponse startAuthorizationFlowWithRetry(String
}
return mapper.readValue(responseBody, AuthorizationFlowResponse.class);
}

private static Stream<Arguments> provideAutomatedVerifications() {
return Stream.of(
Arguments.of(AutomatedVerification.builder().withRemitterName().build()),
Arguments.of(AutomatedVerification.builder()
.withRemitterDateOfBirth()
.build()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
import com.truelayer.java.http.entities.Headers;
import com.truelayer.java.http.entities.ProblemDetails;
import com.truelayer.java.payments.entities.*;
import com.truelayer.java.payments.entities.beneficiary.MerchantAccount;
import com.truelayer.java.payments.entities.paymentdetail.PaymentDetail;
import com.truelayer.java.payments.entities.paymentdetail.Status;
import com.truelayer.java.payments.entities.paymentmethod.PaymentMethod;
import com.truelayer.java.payments.entities.paymentrefund.PaymentRefund;
import com.truelayer.java.payments.entities.providerselection.ProviderSelection;
import com.truelayer.java.payments.entities.providerselection.UserSelectedProviderSelection;
import com.truelayer.java.payments.entities.schemeselection.SchemeSelection;
import com.truelayer.java.payments.entities.verification.AutomatedVerification;
import java.util.Collections;
import java.util.UUID;
import java.util.stream.Stream;
import lombok.SneakyThrows;
import org.junit.jupiter.api.*;
Expand Down Expand Up @@ -99,6 +102,41 @@ public void shouldCreateAPaymentWithAdditionalProductIntention() {
.withRequestBody(matchingJsonPath("$.related_products", equalToJson("{\"signup_plus\": {}}"))));
}

@DisplayName("It should create a payment with automated verification")
@MethodSource("provideAutomatedVerifications")
@ParameterizedTest()
@SneakyThrows
public void shouldCreateAPaymentWithAutomatedVerification(AutomatedVerification verification) {
RequestStub.New()
.method("post")
.path(urlPathEqualTo("/connect/token"))
.status(200)
.bodyFile("auth/200.access_token.json")
.build();

CreatePaymentRequest paymentRequest = CreatePaymentRequest.builder()
.paymentMethod(PaymentMethod.bankTransfer()
.beneficiary(MerchantAccount.merchantAccount()
.verification(verification)
.merchantAccountId(UUID.randomUUID().toString())
.build())
.build())
.amountInMinor(100)
.relatedProducts(RelatedProducts.builder()
.signupPlus(Collections.emptyMap())
.build())
.build();

tlClient.payments().createPayment(paymentRequest).get();

verifyGeneratedToken(Collections.singletonList(PAYMENTS));
verify(postRequestedFor(urlPathEqualTo("/payments"))
.withRequestBody(matchingJsonPath(
"$.payment_method.beneficiary.verification",
equalToJson("{\"type\": \"automated\", \"remitter_name\": " + verification.isRemitterName()
+ ", \"remitter_date_of_birth\": " + verification.isRemitterDateOfBirth() + "}"))));
}

@DisplayName("It should create payment with")
@ParameterizedTest(name = "scheme_selection={0} and expected allow_remitter_fee={1}")
@MethodSource("provideSchemeSelectionTestParameters")
Expand Down Expand Up @@ -516,4 +554,12 @@ private static Stream<Arguments> provideSchemeSelectionTestParameters() {
.build(),
false));
}

private static Stream<Arguments> provideAutomatedVerifications() {
return Stream.of(
Arguments.of(AutomatedVerification.builder().withRemitterName().build()),
Arguments.of(AutomatedVerification.builder()
.withRemitterDateOfBirth()
.build()));
}
}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@
"type":"merchant_account",
"merchant_account_id":"e83c4c20-b2ad-4b73-8a32-***",
"account_holder_name":"john smith",
"reference": "a-reference"
"reference": "a-reference",
"verification": {
"type": "automated",
"remitter_date_of_birth": true,
"remitter_name": false
}
}
},
"created_at":"2022-01-17T17:13:18.214924Z",
Expand Down

0 comments on commit 85036c8

Please sign in to comment.