Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/maven-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ jobs:
env:
CRD_KEY: ${{secrets.CRD_KEY}}
CRD_SECRET: ${{secrets.CRD_SECRET}}
CRD_PASSTHROUGH_KEY: ${{secrets.CRD_PASSTHROUGH_KEY}}
CRD_PASSTHROUGH_SECRET: ${{secrets.CRD_PASSTHROUGH_SECRET}}
run: mvn clean verify -Dgpg.skip=true
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Add this dependency to your project's POM:
<dependency>
<groupId>com.cardinity</groupId>
<artifactId>cardinity-sdk-java</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
</dependency>
```

Expand All @@ -28,7 +28,7 @@ Add this dependency to your project's POM:
Add this dependency to your project's build file:

```groovy
compile "com.cardinity:cardinity-sdk-java:1.10.0"
compile "com.cardinity:cardinity-sdk-java:1.11.0"
```

### Other
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.0
1.11.0
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.cardinity</groupId>
<artifactId>cardinity-sdk-java</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
<packaging>jar</packaging>
<name>cardinity-sdk-java</name>
<description>Cardinity payments API client for Java projects</description>
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/com/cardinity/model/Payment.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.cardinity.model;

import com.cardinity.exceptions.ValidationException;
import com.google.gson.annotations.SerializedName;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Currency;
import java.util.Date;
import java.util.UUID;

Expand Down Expand Up @@ -103,7 +106,15 @@ public BigDecimal getAmount() {
}

public void setAmount(BigDecimal amount) {
this.amount = amount.setScale(2, BigDecimal.ROUND_DOWN);
if (currency != null) {
try {
if (amount != null) {
this.amount = amount.setScale(Currency.getInstance(currency).getDefaultFractionDigits(), RoundingMode.DOWN);
return;
}
} catch (IllegalArgumentException ignored){}
}
this.amount = amount;
}

public String getCurrency() {
Expand All @@ -112,6 +123,13 @@ public String getCurrency() {

public void setCurrency(String currency) {
this.currency = currency;
if (currency != null && !currency.isEmpty()) {
try {
if (amount != null) {
this.amount = this.amount.setScale(Currency.getInstance(currency).getDefaultFractionDigits(), RoundingMode.DOWN);
}
} catch (IllegalArgumentException ignored){}
}
}

public Date getCreated() {
Expand Down
60 changes: 46 additions & 14 deletions src/test/java/com/cardinity/CardinityIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
public class CardinityIntegrationTest extends CardinityBaseTest {

private static CardinityClient client;
private static CardinityClient passthroughClient;

private static final String TEST_ORDER_ID = "cardinity-SDK-test";
private static final String TEST_PAYMENT_DESCRIPTION = "cardinity-SDK-payment";
Expand All @@ -32,6 +33,11 @@ public static void setUpClass() throws Exception {
final String consumerSecret = System.getenv("CRD_SECRET");
if (consumerKey == null || consumerSecret == null) throw new Exception("Authorization keys missing");
client = new CardinityClient(consumerKey, consumerSecret);

final String passthroughConsumerKey = System.getenv("CRD_PASSTHROUGH_KEY");
final String passthroughConsumerSecret = System.getenv("CRD_PASSTHROUGH_SECRET");
if (passthroughConsumerKey == null || passthroughConsumerSecret == null) throw new Exception("Authorization keys missing");
passthroughClient = new CardinityClient(passthroughConsumerKey, passthroughConsumerSecret);
}

private static Payment getBaseCCPayment() {
Expand All @@ -51,6 +57,13 @@ private static Payment getBaseCCPayment() {
return payment;
}

private static Payment getBaseCCPayment(String currency, BigDecimal amount) {
Payment payment = getBaseCCPayment();
payment.setAmount(amount);
payment.setCurrency(currency);
return payment;
}

private static Threeds2Data getThreeds2Data() {
Threeds2Data threeds2Data = new Threeds2Data();
threeds2Data.setNotificationUrl("http://notification.url");
Expand Down Expand Up @@ -97,13 +110,7 @@ private static Threeds2Data getThreeds2Data() {
@Test
public void testCreateApprovedPayment() {
Payment resultPayment = createApprovedPayment();
assertEquals(APPROVED, resultPayment.getStatus());
assertNotNull(resultPayment.getId());
assertThat(resultPayment.getPaymentInstrument(), instanceOf(Card.class));
assertFalse(resultPayment.getLive());
assertEquals(TEST_PAYMENT_DESCRIPTION, resultPayment.getDescription());
assertFalse(resultPayment.isThreedsV2());
assertFalse(resultPayment.isThreedsV1());
assertResultPayment(resultPayment);
}

@Test
Expand All @@ -130,13 +137,7 @@ public void testCreateApprovedPaymentWithDescriptorSuffix() {
Result<Payment> initialResult = client.createPayment(payment);
assertTrue(initialResult.isValid());
Payment resultPayment = initialResult.getItem();
assertEquals(APPROVED, resultPayment.getStatus());
assertNotNull(resultPayment.getId());
assertThat(resultPayment.getPaymentInstrument(), instanceOf(Card.class));
assertFalse(resultPayment.getLive());
assertEquals(TEST_PAYMENT_DESCRIPTION, resultPayment.getDescription());
assertFalse(resultPayment.isThreedsV2());
assertFalse(resultPayment.isThreedsV1());
assertResultPayment(resultPayment);
}

@Test
Expand Down Expand Up @@ -476,6 +477,18 @@ public void testGetAllChargebacksWithLimit() {
assertTrue(size <= limit);
}

@Test
public void testCreateApprovedPaymentNoDecimal() {
Payment resultPayment = createApprovedPassthroughPayment("JPY");
assertResultPayment(resultPayment);
}

@Test
public void testCreateApprovedPaymentMoreDecimal() {
Payment resultPayment = createApprovedPassthroughPayment("KWD");
assertResultPayment(resultPayment);
}

private Payment createApprovedPayment() {
Payment payment = getBaseCCPayment();
Result<Payment> initialResult = client.createPayment(payment);
Expand All @@ -485,6 +498,15 @@ private Payment createApprovedPayment() {
return resultPayment;
}

private Payment createApprovedPassthroughPayment(String currency) {
Payment payment = getBaseCCPayment(currency, BigDecimal.valueOf(10));
Result<Payment> initialResult = passthroughClient.createPayment(payment);
assertTrue(initialResult.isValid());
Payment resultPayment = initialResult.getItem();
assertEquals(APPROVED, resultPayment.getStatus());
return resultPayment;
}

private Payment createPendingPayment(Payment payment, boolean v2) {
Result<Payment> result = client.createPayment(payment);
assertTrue(result.isValid());
Expand All @@ -505,4 +527,14 @@ private Payment createPendingPayment(Payment payment, boolean v2) {
}
return resultPayment;
}

private void assertResultPayment(Payment resultPayment) {
assertEquals(APPROVED, resultPayment.getStatus());
assertNotNull(resultPayment.getId());
assertThat(resultPayment.getPaymentInstrument(), instanceOf(Card.class));
assertFalse(resultPayment.getLive());
assertEquals(TEST_PAYMENT_DESCRIPTION, resultPayment.getDescription());
assertFalse(resultPayment.isThreedsV2());
assertFalse(resultPayment.isThreedsV1());
}
}