Skip to content

Commit f833962

Browse files
authored
[CC-896] Add tra exemption type (Transaction Risk Analysis). (#157)
1 parent 5515368 commit f833962

3 files changed

Lines changed: 97 additions & 55 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Click To Pay payment method is added to Java SDK.
1313
### Added
1414

1515
* Added `ClickToPay` payment method.
16+
* Add exemption type for transaction risk analysis: `com.unzer.payment.models.CardTransactionData.ExemptionType.TRA`
1617

1718
## [5.2.0](https://github.com/unzerdev/java-sdk/compare/5.1.0..5.2.0)
1819

src/main/java/com/unzer/payment/models/CardTransactionData.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,15 @@ public enum Liability {
7676
}
7777

7878
public enum ExemptionType {
79+
/**
80+
* Low Value Payment
81+
*/
7982
@SerializedName("lvp")
80-
LVP
83+
LVP,
84+
/**
85+
* Transaction Risk Analysis
86+
*/
87+
@SerializedName("tra")
88+
TRA
8189
}
8290
}

src/test/java/com/unzer/payment/integration/paymenttypes/CardTest.java

Lines changed: 87 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@
88
import com.unzer.payment.models.CardTransactionData;
99
import com.unzer.payment.paymenttypes.Card;
1010
import org.junit.jupiter.api.Disabled;
11+
import org.junit.jupiter.api.DynamicTest;
1112
import org.junit.jupiter.api.Test;
13+
import org.junit.jupiter.api.TestFactory;
1214

1315
import java.math.BigDecimal;
16+
import java.util.Collection;
1417
import java.util.Currency;
18+
import java.util.stream.Collectors;
19+
import java.util.stream.Stream;
1520

1621
import static com.unzer.payment.business.Keys.ALT_LEGACY_PRIVATE_KEY;
1722
import static com.unzer.payment.util.Types.unsafeUrl;
1823
import static org.junit.jupiter.api.Assertions.*;
24+
import static org.junit.jupiter.api.DynamicTest.dynamicTest;
1925

2026

2127
public class CardTest extends AbstractPaymentTest {
@@ -195,7 +201,7 @@ public void testCardMailInvalidValue() {
195201
card.setCvc("123");
196202
card.setEmail(INVALID_MAIL_STRING);
197203
try {
198-
card = getUnzer().createPaymentType(card);
204+
getUnzer().createPaymentType(card);
199205
} catch (PaymentException e) {
200206
assertNotNull(e.getPaymentErrorList());
201207
assertTrue(e.getPaymentErrorList().size() > 0);
@@ -447,64 +453,91 @@ public void testAdditionalTransactionData_Liability() {
447453
assertEquals(liability, fetchAuthorization.getAdditionalTransactionData().getCard().getLiability());
448454
}
449455

450-
@Test
451-
public void testCardLowValueExemptionsForAuth() {
452-
Unzer unzer = getUnzer();
453-
454-
Card card = unzer.createPaymentType(
455-
new Card(NO_3DS_VISA_CARD_NUMBER, "01/30")
456-
.setCvc("123")
457-
.set3ds(false)
458-
);
456+
@TestFactory
457+
public Collection<DynamicTest> testExemptionTypesForAuth() {
458+
class TestCase {
459+
final CardTransactionData.ExemptionType exemptionType;
459460

460-
Authorization authorization = (Authorization) new Authorization()
461-
.setTypeId(card.getId())
462-
.setReturnUrl(unsafeUrl("https://unzer.com"))
463-
.setAmount(BigDecimal.TEN)
464-
.setCurrency(Currency.getInstance("EUR"))
465-
.setOrderId("ord-Hi686u4Q4Y")
466-
.setAdditionalTransactionData(
467-
new AdditionalTransactionData()
468-
.setCard(
469-
new CardTransactionData()
470-
.setRecurrenceType(RecurrenceType.UNSCHEDULED)
471-
.setExemptionType(CardTransactionData.ExemptionType.LVP)
472-
)
473-
);
474-
authorization = unzer.authorize(authorization);
461+
public TestCase(CardTransactionData.ExemptionType exemptionType) {
462+
this.exemptionType = exemptionType;
463+
}
464+
}
475465

476-
Authorization fetchAuthorization = unzer.fetchAuthorization(authorization.getPaymentId());
477-
assertEquals(CardTransactionData.ExemptionType.LVP, fetchAuthorization.getAdditionalTransactionData().getCard().getExemptionType());
466+
return Stream.of(
467+
new TestCase(CardTransactionData.ExemptionType.LVP),
468+
new TestCase(CardTransactionData.ExemptionType.TRA)
469+
).map(tc -> dynamicTest("exemptionType " + tc.exemptionType, () -> {
470+
Unzer unzer = getUnzer();
471+
472+
Card card = unzer.createPaymentType(
473+
new Card(NO_3DS_VISA_CARD_NUMBER, "01/30")
474+
.setCvc("123")
475+
.set3ds(false)
476+
);
477+
478+
Authorization authorization = (Authorization) new Authorization()
479+
.setTypeId(card.getId())
480+
.setReturnUrl(unsafeUrl("https://unzer.com"))
481+
.setAmount(BigDecimal.TEN)
482+
.setCurrency(Currency.getInstance("EUR"))
483+
.setOrderId("ord-Hi686u4Q4Y")
484+
.setAdditionalTransactionData(
485+
new AdditionalTransactionData()
486+
.setCard(
487+
new CardTransactionData()
488+
.setRecurrenceType(RecurrenceType.UNSCHEDULED)
489+
.setExemptionType(tc.exemptionType)
490+
)
491+
);
492+
authorization = unzer.authorize(authorization);
493+
494+
Authorization fetchAuthorization = unzer.fetchAuthorization(authorization.getPaymentId());
495+
assertEquals(tc.exemptionType, fetchAuthorization.getAdditionalTransactionData().getCard().getExemptionType());
496+
})
497+
).collect(Collectors.toList());
478498
}
479499

480-
@Test
481-
public void testCardLowValueExemptionsForCharge() {
482-
Unzer unzer = getUnzer();
483-
484-
Card card = unzer.createPaymentType(
485-
new Card(NO_3DS_VISA_CARD_NUMBER, "01/30")
486-
.setCvc("123")
487-
.set3ds(false)
488-
);
500+
@TestFactory
501+
public Collection<DynamicTest> testCardExemptionTypesForCharge() {
502+
class TestCase {
503+
final CardTransactionData.ExemptionType exemptionType;
489504

490-
Charge charge = (Charge) new Charge()
491-
.setTypeId(card.getId())
492-
.setReturnUrl(unsafeUrl("https://unzer.com"))
493-
.setAmount(BigDecimal.TEN)
494-
.setCurrency(Currency.getInstance("EUR"))
495-
.setOrderId("ord-Hi686u4Q4Y")
496-
.setAdditionalTransactionData(
497-
new AdditionalTransactionData()
498-
.setCard(
499-
new CardTransactionData()
500-
.setRecurrenceType(RecurrenceType.UNSCHEDULED)
501-
.setExemptionType(CardTransactionData.ExemptionType.LVP)
502-
)
503-
);
504-
unzer.charge(charge);
505+
public TestCase(CardTransactionData.ExemptionType exemptionType) {
506+
this.exemptionType = exemptionType;
507+
}
508+
}
505509

506-
Charge fetchCharge = unzer.fetchCharge(charge.getPaymentId(), "s-chg-1");
507-
assertEquals(CardTransactionData.ExemptionType.LVP, fetchCharge.getAdditionalTransactionData().getCard().getExemptionType());
510+
return Stream.of(
511+
new TestCase(CardTransactionData.ExemptionType.LVP),
512+
new TestCase(CardTransactionData.ExemptionType.TRA)
513+
).map(tc -> dynamicTest("exemptionType " + tc.exemptionType, () -> {
514+
Unzer unzer = getUnzer();
515+
516+
Card card = unzer.createPaymentType(
517+
new Card(NO_3DS_VISA_CARD_NUMBER, "01/30")
518+
.setCvc("123")
519+
.set3ds(false)
520+
);
521+
522+
Charge charge = (Charge) new Charge()
523+
.setTypeId(card.getId())
524+
.setReturnUrl(unsafeUrl("https://unzer.com"))
525+
.setAmount(BigDecimal.TEN)
526+
.setCurrency(Currency.getInstance("EUR"))
527+
.setOrderId("ord-Hi686u4Q4Y")
528+
.setAdditionalTransactionData(
529+
new AdditionalTransactionData()
530+
.setCard(
531+
new CardTransactionData()
532+
.setRecurrenceType(RecurrenceType.UNSCHEDULED)
533+
.setExemptionType(tc.exemptionType)
534+
)
535+
);
536+
unzer.charge(charge);
537+
538+
Charge fetchCharge = unzer.fetchCharge(charge.getPaymentId(), "s-chg-1");
539+
assertEquals(tc.exemptionType, fetchCharge.getAdditionalTransactionData().getCard().getExemptionType());
540+
})
541+
).collect(Collectors.toList());
508542
}
509-
510543
}

0 commit comments

Comments
 (0)