Skip to content

Commit

Permalink
[ACL-161] Add risk_assessment field to create payment request (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
tl-luca-baggi authored Sep 11, 2024
1 parent 85036c8 commit 36cf23f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 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.2.0
version=13.3.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
Expand Up @@ -29,4 +29,9 @@ public class CreatePaymentRequest {
* Optional field. Not available when creating recurring payments.
*/
private RelatedProducts relatedProducts;

/**
* Optional field for configuring risk assessment and the payment_creditable webhook
*/
private RiskAssessment riskAssessment;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.truelayer.java.payments.entities;

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

@Builder
@EqualsAndHashCode
@ToString
@Getter
public class RiskAssessment {

private String segment;
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public void itShouldCreateAPaymentWithSignupPlusIntention() {
RelatedProducts.builder()
.signupPlus(Collections.emptyMap())
.build(),
null,
null))
.get();

Expand Down Expand Up @@ -155,7 +156,23 @@ public void itShouldCreateAPaymentWithAutomatedVerification(Verification verific

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

assertNotError(createPaymentResponse);
}

@Test
@DisplayName("It should create a payment with risk assessment")
@SneakyThrows
public void itShouldCreateAPaymentWithRiskAssessment() {
ApiResponse<CreatePaymentResponse> createPaymentResponse = tlClient.payments()
.createPayment(buildPaymentRequestWithProviderSelection(
buildPreselectedProviderSelection(),
CurrencyCode.GBP,
null,
RiskAssessment.builder().segment("a-custom-segment").build(),
null))
.get();

assertNotError(createPaymentResponse);
Expand Down Expand Up @@ -605,18 +622,19 @@ private Beneficiary buildBeneficiary(CurrencyCode currencyCode) {

private CreatePaymentRequest buildPaymentRequestWithProviderSelection(
ProviderSelection providerSelection, CurrencyCode currencyCode) {
return buildPaymentRequestWithProviderSelection(providerSelection, currencyCode, null, null);
return buildPaymentRequestWithProviderSelection(providerSelection, currencyCode, null, null, null);
}

private CreatePaymentRequest buildPaymentRequestWithProviderSelectionWithRetry(
ProviderSelection providerSelection, CurrencyCode currencyCode) {
return buildPaymentRequestWithProviderSelection(providerSelection, currencyCode, null, new Retry());
return buildPaymentRequestWithProviderSelection(providerSelection, currencyCode, null, null, new Retry());
}

private CreatePaymentRequest buildPaymentRequestWithProviderSelection(
ProviderSelection providerSelection,
CurrencyCode currencyCode,
RelatedProducts relatedProducts,
RiskAssessment riskAssessment,
Retry retry) {
CreatePaymentRequest.CreatePaymentRequestBuilder builder = CreatePaymentRequest.builder()
.amountInMinor(RandomUtils.nextInt(50, 500))
Expand Down Expand Up @@ -644,6 +662,10 @@ private CreatePaymentRequest buildPaymentRequestWithProviderSelection(
builder.relatedProducts(relatedProducts);
}

if (riskAssessment != null) {
builder.riskAssessment(riskAssessment);
}

return builder.build();
}

Expand Down

0 comments on commit 36cf23f

Please sign in to comment.