Skip to content

[CC-2923] Make PayPage V2 Risk.confirmedAmount nullable - #193

Open
Ryouzanpaku wants to merge 3 commits into
mainfrom
CC-2923/risk-confirmed-amount-nullable
Open

Ryouzanpaku wants to merge 3 commits into
mainfrom
CC-2923/risk-confirmed-amount-nullable

Conversation

@Ryouzanpaku

Copy link
Copy Markdown
Contributor

What

com.unzer.payment.models.paypage.Risk.confirmedAmount was a primitive double, which defaults to 0.0. Because Gson serializes primitives unconditionally, every PayPage V2 request carried "confirmedAmount": 0.0 even when the merchant never called setConfirmedAmount(...).

This changes the field to a nullable Double so it is only serialized when explicitly set (Gson omits null fields by default). Lombok @Data keeps generating the getter/setter.

Why

CC-2923 — confirmedAmount should remain unset unless setConfirmedAmount() is called.

Tests

RiskTest (new): default Risk omits confirmedAmount from the serialized body; a set value (including 0.0 and negatives) is serialized. Verified with mvn test -Dtest=RiskTest on JDK 17 — 4/4 pass.

🤖 Generated with Claude Code

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) <noreply@anthropic.com>
Changelog and version edits are scoped to the release ticket (CC-4252),
so this feature branch no longer touches CHANGELOG and won't conflict.
@Ryouzanpaku
Ryouzanpaku marked this pull request as ready for review November 16, 2026 09:43
@sixer1182

Copy link
Copy Markdown
Member

The change fulfils the ticket. One note for the release notes: getConfirmedAmount() now returns Double instead of double. Callers that assign the result to a primitive double will get a NullPointerException when the value was never set. Please mention this in the Fixed entry of the 5.10.0 changelog (#197).

Ryouzanpaku added a commit that referenced this pull request Nov 24, 2026
…medAmount in changelog

getConfirmedAmount() now returns Double instead of primitive double; callers
assigning to a primitive double can hit a NullPointerException when unset.
Addresses PR #193 review note (sixer1182).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Ryouzanpaku

Copy link
Copy Markdown
Contributor Author

Thanks — added the note to the 5.10.0 Fixed entry in #197 (f2182f2): getConfirmedAmount() now returns Double instead of primitive double, with the NPE caveat for callers assigning to a primitive.

@Ryouzanpaku Ryouzanpaku left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Code Review — [CC-2923] Make PayPage V2 Risk.confirmedAmount nullable

Summary

The change switches Risk.confirmedAmount from primitive double to boxed Double. Because Gson omits null fields and JsonParser uses default (non-null-serializing) config, an unset confirmedAmount is now left out of the PayPage V2 request body, while a value set via setConfirmedAmount(...) — including 0.0 — is still serialized. This precisely matches the bug and both acceptance criteria in CC-2923 ("only set when setConfirmedAmount() is used" / "default creation does not assign a value"). Lombok @Data with the repo's lombok.accessors.chain=true regenerates the getter/setter, so existing chained usages (PaypageV2Test, PaylaterInvoiceTest) still compile via autoboxing. The new RiskTest is a focused, API-key-free unit test with good edge coverage (0.0, positive, negative). Minimal, correct, well-scoped fix.

Issues (to resolve before merge — no code change to this diff expected)

  • Required Unit tests / build check is currently red. The build job runs mvn test --fail-at-end, which also executes the ~35 integration tests that hit the live sandbox (token.test.upcgw.com, paypage.test.unzer.com) and depend on secrets/live availability — a known flaky source. The visible log is truncated before the failure summary, and the new RiskTest is a pure unit test unrelated to that suite (author reports mvn test -Dtest=RiskTest → 4/4 green on JDK 17). Please confirm the failure is the pre-existing integration flakiness (not this change) and get the required check green before merging; I could not positively see RiskTest execute in the truncated CI log.

Suggestions (non-blocking)

  • Public-API / binary breaking change. The generated accessors change signature: getter return double → Double and setter param double → Double. Source-compatible for callers via auto-(un)boxing, but binary-incompatible for pre-compiled consumers, and double x = risk.getConfirmedAmount() can now NPE when unset. Appropriate for a published SDK to call out in release notes. Already acknowledged by @sixer1182 and documented by the author in the 5.10.0 Fixed entry in #197 — note the implied merge dependency on that changelog PR.
  • Assertion robustness (minor). confirmedAmountIsSerializedWhenSet relies on contains("\"confirmedAmount\": " + amount), which couples the test to Gson's pretty-print spacing and double→string formatting. It passes against the current JsonParser config, but deserializing and asserting the numeric field would be marginally more resilient. Optional.

Overall: the code change is correct and complete for CC-2923. Posting as a comment (not a block on the code) — the only merge gate is confirming the red CI is unrelated and green.

private String customerGroup;
private Integer confirmedOrders;
private double confirmedAmount;
private Double confirmedAmount;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct fix for the Gson-omits-null behaviour. Note: via Lombok @Data this changes the generated accessors' signatures (getter double→Double, setter param double→Double) — source-compatible through auto-(un)boxing but a binary-incompatible change for pre-compiled SDK consumers, and double x = risk.getConfirmedAmount() can NPE when unset. Worth the release note (already captured in #197).

@sixer1182 sixer1182 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for two reasons.

  1. Binary compatibility. Changing Risk.confirmedAmount from double to Double changes the getter and setter signatures (D to Ljava/lang/Double;). Code compiled against 5.9.0 that calls getConfirmedAmount() or setConfirmedAmount(double) fails at runtime with NoSuchMethodError. Callers that unbox the getter result get an NPE when the value was never set. The CHANGELOG entry in #197 places this in 5.10.0, a minor release. Please either (a) confirm that a major version bump is intended, or (b) keep the primitive getter and setter signatures and change only the serialization (for example a Gson exclusion for unset values), so the public API stays unchanged. If the break stays, the changelog must state it.

  2. Test assertion. RiskTest.confirmedAmountIsSerializedWhenSet checks for the exact string "confirmedAmount": <value> with one space after the colon. That depends on the pretty-printer in JsonParser. Please compare parsed JSON instead, or confirm the formatting is stable.

…n 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) <noreply@anthropic.com>
Ryouzanpaku added a commit that referenced this pull request Dec 2, 2026
…ount note

Move the SECCI plans feature, minimumInstallmentFee, and fetchPaylaterInstallmentPlans
deprecation (from #198) into this release changelog, which owns the 5.10.0 version
bump. Correct the Risk.confirmedAmount Fixed entry: the public double API is kept
(see #193), so there is no source/binary break.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Ryouzanpaku

Copy link
Copy Markdown
Contributor Author

Thanks — addressed both points in 48c399d:

  1. Binary compatibility. Rather than a major bump, I kept the public API unchanged: Risk.confirmedAmount stays serialized via a nullable Double field, but the accessors are now hand-written as double getConfirmedAmount() / Risk setConfirmedAmount(double) — identical signatures to 5.9.0. Lombok skips generating accessors that already exist, so there is no NoSuchMethodError and no unbox NPE (unset reads as 0.0, exactly as before). Serialization still omits the field when never set and includes any explicitly set value incl. 0.0. The 5.10.0 Fixed entry in [CC-4252] CHANGELOG for Java-SDK 5.10.0 release #197 is updated to state there is no source/binary break.
  2. Test assertion. confirmedAmountIsSerializedWhenSet now parses the JSON and asserts the numeric field instead of matching the pretty-printed string. RiskTest is 4/4 green locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants