diff --git a/.github/workflows/maven-verify.yml b/.github/workflows/maven-verify.yml
index b12d531..2a188fc 100644
--- a/.github/workflows/maven-verify.yml
+++ b/.github/workflows/maven-verify.yml
@@ -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
\ No newline at end of file
diff --git a/README.md b/README.md
index 15c9fc1..52de596 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ Add this dependency to your project's POM:
com.cardinity
cardinity-sdk-java
- 1.10.0
+ 1.11.0
```
@@ -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
diff --git a/VERSION b/VERSION
index ed21137..169f19b 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.10.0
\ No newline at end of file
+1.11.0
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 0e2f2f5..a9699c3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.cardinity
cardinity-sdk-java
- 1.10.0
+ 1.11.0
jar
cardinity-sdk-java
Cardinity payments API client for Java projects
diff --git a/src/main/java/com/cardinity/model/Payment.java b/src/main/java/com/cardinity/model/Payment.java
index 7512f6c..308539a 100644
--- a/src/main/java/com/cardinity/model/Payment.java
+++ b/src/main/java/com/cardinity/model/Payment.java
@@ -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;
@@ -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() {
@@ -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() {
diff --git a/src/test/java/com/cardinity/CardinityIntegrationTest.java b/src/test/java/com/cardinity/CardinityIntegrationTest.java
index 194fe88..c76959e 100644
--- a/src/test/java/com/cardinity/CardinityIntegrationTest.java
+++ b/src/test/java/com/cardinity/CardinityIntegrationTest.java
@@ -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";
@@ -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() {
@@ -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");
@@ -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
@@ -130,13 +137,7 @@ public void testCreateApprovedPaymentWithDescriptorSuffix() {
Result 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
@@ -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 initialResult = client.createPayment(payment);
@@ -485,6 +498,15 @@ private Payment createApprovedPayment() {
return resultPayment;
}
+ private Payment createApprovedPassthroughPayment(String currency) {
+ Payment payment = getBaseCCPayment(currency, BigDecimal.valueOf(10));
+ Result 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 result = client.createPayment(payment);
assertTrue(result.isValid());
@@ -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());
+ }
}