From 4972b0a775c42ba880d17f4bbb834d84d1cef4b3 Mon Sep 17 00:00:00 2001 From: David Owusu Date: Thu, 5 Nov 2026 13:11:12 +0100 Subject: [PATCH 1/3] [CC-2923] Make PayPage V2 Risk.confirmedAmount nullable confirmedAmount was a primitive double defaulting to 0.0, so it was always serialized into the PayPage V2 request even when the merchant never set it. Change it to a nullable Double so Gson omits it unless explicitly set. Co-Authored-By: Claude Opus 4.8 (1M context) --- CHANGELOG.md | 6 ++++ .../unzer/payment/models/paypage/Risk.java | 2 +- .../payment/models/paypage/RiskTest.java | 34 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/unzer/payment/models/paypage/RiskTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 60b496dc..d4f1a4f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed + +* `confirmedAmount` on the PayPage V2 `Risk` object (`com.unzer.payment.models.paypage.Risk`) is now a nullable `Double` and is omitted from the request body when it was never set, instead of always defaulting to `0.0`. + ## [5.9.0](https://github.com/unzerdev/java-sdk/compare/5.8.2..5.9.0) ### Added diff --git a/src/main/java/com/unzer/payment/models/paypage/Risk.java b/src/main/java/com/unzer/payment/models/paypage/Risk.java index 0fcfce42..23a1df67 100644 --- a/src/main/java/com/unzer/payment/models/paypage/Risk.java +++ b/src/main/java/com/unzer/payment/models/paypage/Risk.java @@ -13,5 +13,5 @@ public class Risk { private Date registrationDate; private String customerGroup; private Integer confirmedOrders; - private double confirmedAmount; + private Double confirmedAmount; } diff --git a/src/test/java/com/unzer/payment/models/paypage/RiskTest.java b/src/test/java/com/unzer/payment/models/paypage/RiskTest.java new file mode 100644 index 00000000..faaca293 --- /dev/null +++ b/src/test/java/com/unzer/payment/models/paypage/RiskTest.java @@ -0,0 +1,34 @@ +package com.unzer.payment.models.paypage; + +import com.unzer.payment.communication.JsonParser; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class RiskTest { + + private final JsonParser jsonParser = new JsonParser(); + + @Test + void defaultRiskOmitsConfirmedAmount() { + Risk risk = new Risk(); + + assertNull(risk.getConfirmedAmount()); + assertFalse(jsonParser.toJson(risk).contains("confirmedAmount"), + "confirmedAmount must not be serialized when it was never set"); + } + + @ParameterizedTest + @ValueSource(doubles = {0.0, 100.0, -5.0}) + void confirmedAmountIsSerializedWhenSet(double amount) { + Risk risk = new Risk(); + risk.setConfirmedAmount(amount); + + assertTrue(jsonParser.toJson(risk).contains("\"confirmedAmount\": " + amount), + "confirmedAmount must be serialized once explicitly set, including 0.0"); + } +} From a1addba60a68f9a8bdd58552bc325a8a4c974d23 Mon Sep 17 00:00:00 2001 From: David Owusu Date: Thu, 5 Nov 2026 15:48:46 +0100 Subject: [PATCH 2/3] [CC-2923] Remove changelog entry; consolidated into CC-4252 release PR Changelog and version edits are scoped to the release ticket (CC-4252), so this feature branch no longer touches CHANGELOG and won't conflict. --- CHANGELOG.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4f1a4f6..60b496dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,12 +6,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [Unreleased] - -### Fixed - -* `confirmedAmount` on the PayPage V2 `Risk` object (`com.unzer.payment.models.paypage.Risk`) is now a nullable `Double` and is omitted from the request body when it was never set, instead of always defaulting to `0.0`. - ## [5.9.0](https://github.com/unzerdev/java-sdk/compare/5.8.2..5.9.0) ### Added From 48c399d33091efef768b6ee100330f831c7e6f70 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Wed, 2 Dec 2026 13:31:19 +0100 Subject: [PATCH 3/3] [CC-2923] [CC-2923] Keep primitive confirmedAmount API; omit only when unset Address review feedback: instead of changing Risk.confirmedAmount from double to Double (a source/binary break), keep the public double getConfirmedAmount() / setConfirmedAmount(double) signatures and back them with a nullable Double field so Gson omits the value only when it was never set. Preserves 5.9.0 compatibility (no NoSuchMethodError, no unbox NPE) while still satisfying CC-2923. Also assert serialized JSON by parsing instead of pretty-print string matching. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../java/com/unzer/payment/models/paypage/Risk.java | 9 +++++++++ .../com/unzer/payment/models/paypage/RiskTest.java | 10 +++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/unzer/payment/models/paypage/Risk.java b/src/main/java/com/unzer/payment/models/paypage/Risk.java index 23a1df67..ff9ff6fa 100644 --- a/src/main/java/com/unzer/payment/models/paypage/Risk.java +++ b/src/main/java/com/unzer/payment/models/paypage/Risk.java @@ -14,4 +14,13 @@ public class Risk { private String customerGroup; private Integer confirmedOrders; private Double confirmedAmount; + + public double getConfirmedAmount() { + return confirmedAmount == null ? 0.0 : confirmedAmount; + } + + public Risk setConfirmedAmount(double confirmedAmount) { + this.confirmedAmount = confirmedAmount; + return this; + } } diff --git a/src/test/java/com/unzer/payment/models/paypage/RiskTest.java b/src/test/java/com/unzer/payment/models/paypage/RiskTest.java index faaca293..84446fd8 100644 --- a/src/test/java/com/unzer/payment/models/paypage/RiskTest.java +++ b/src/test/java/com/unzer/payment/models/paypage/RiskTest.java @@ -1,12 +1,13 @@ package com.unzer.payment.models.paypage; +import com.google.gson.JsonObject; import com.unzer.payment.communication.JsonParser; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; class RiskTest { @@ -17,7 +18,7 @@ class RiskTest { void defaultRiskOmitsConfirmedAmount() { Risk risk = new Risk(); - assertNull(risk.getConfirmedAmount()); + assertEquals(0.0, risk.getConfirmedAmount(), "unset confirmedAmount reads as the 0.0 default"); assertFalse(jsonParser.toJson(risk).contains("confirmedAmount"), "confirmedAmount must not be serialized when it was never set"); } @@ -28,7 +29,10 @@ void confirmedAmountIsSerializedWhenSet(double amount) { Risk risk = new Risk(); risk.setConfirmedAmount(amount); - assertTrue(jsonParser.toJson(risk).contains("\"confirmedAmount\": " + amount), + JsonObject json = com.google.gson.JsonParser.parseString(jsonParser.toJson(risk)).getAsJsonObject(); + assertTrue(json.has("confirmedAmount"), "confirmedAmount must be serialized once explicitly set, including 0.0"); + assertEquals(amount, json.get("confirmedAmount").getAsDouble(), + "serialized confirmedAmount must equal the set value"); } }