Skip to content

[CC-4346] Nullable paylater plan model: all params gettable for invoice & direct debit - #255

Merged
Ryouzanpaku merged 10 commits into
mainfrom
CC-4346/plan-nullable-mapping
Nov 26, 2026
Merged

Ryouzanpaku merged 10 commits into
mainfrom
CC-4346/plan-nullable-mapping

Conversation

@Ryouzanpaku

Copy link
Copy Markdown
Contributor

Supersedes #254 (closed automatically when its branch was renamed from CC-4346-plan-nullable-mapping to CC-4346/plan-nullable-mapping to satisfy the CC-{ticket}/{title} branch-name check). Same commits (929a9b2a); the QA review, Copilot review, and discussion threads live on #254.

Why

Follow-up to merged CC-4346 (#253). QA found the three paylater plan types return structurally different plan objects, but the SDK forced them through one InstallmentPlan with non-nullable getters, so invoice/direct-debit plans threw a TypeError, and interestAmount was dropped.

What

  • PaylaterPlan — new canonical plan-item model (all getters nullable; adds getInterestAmount()); uses native typed properties. Fixes the invoice/direct-debit TypeError and null-field crashes.
  • PaylaterPlans — new result container (null-tolerant envelope setters); getPlans() returns PaylaterPlan[]. Typed properties.
  • PaylaterPlansQuery — generalized query (already typed).
  • Legacy BC preserved: InstallmentPlan, InstallmentPlansQuery, PaylaterInstallmentPlans, fetchPaylaterInstallmentPlans() are byte-for-byte unchanged (only @deprecated docblocks added). InstallmentPlan is a standalone deprecated class (not a subclass of PaylaterPlan) so its return types stay exactly as released — verified by reflection test.
  • CHANGELOG trimmed to net consumer-facing changes.

Verification

  • Unit: 809 tests / 3301 assertions green (PHP 8.2–8.5 in CI).
  • Integration against live sandbox: new flow 7 tests/185 assertions, legacy flow green — all three types' real responses confirm every plan parameter is gettable (interest-rate fields null for invoice/DD, no TypeError).
  • Independent subagent review: safe to ship as a minor; legacy BC byte-identical; minor findings applied.

🤖 Generated with Claude Code

Ryouzanpaku and others added 10 commits November 25, 2026 10:39
…e for every type

QA on PR #253 (CC-4346) found the three paylater plan types return
structurally different plan objects, but the SDK forced them all through
one InstallmentPlan class with non-nullable getters. The live Unzer OpenAPI
spec declares a single schema for all three /plans endpoints with every
field optional and no type discriminator; the types differ only in which
optional fields they populate at runtime (invoice/direct-debit omit the
interest-rate fields and send rates without a date). So one tolerant class
with every field nullable is the correct mapping, not a subclass split.

- InstallmentPlan: all getters/setters nullable; add interestAmount
  (getInterestAmount) that was dropped. Fixes getSecciUrl()/
  getEffectiveInterestRate() throwing on invoice/direct-debit plans.
- PaylaterPlans: setAmount/setCurrency/setPlans tolerate null (a null field
  in the response no longer TypeErrors the fetch; null plans -> empty list).
- Tests: real invoice + direct-debit response fixtures (previously only
  installment-shaped data existed, which hid the crash); unit mapping now
  parameterized over all three types incl. interestAmount; a null-field
  regression test; the integration test exercises all three types via
  fetchPaylaterPlans and asserts every plan parameter is gettable.

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

The legacy fetchPaylaterInstallmentPlans() flow maps through the same
InstallmentPlan class widened to nullable here. Its mapping regression test
(PaylaterInstallmentPlansTest::verifyJsonResponseIsHandledProperly) already
asserts the plan getters still map, but not the two fields this change
touched. Pin getNumberOfRates() and the new getInterestAmount() on the
legacy path so backward compatibility covers exactly what changed.

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

Mirror the container-level rename (PaylaterInstallmentPlans -> PaylaterPlans)
at the plan-item level so early adopters of the new fetchPaylaterPlans() flow
never have to migrate twice. Since PaylaterPlans is unreleased (4.1.0),
changing what getPlans() returns is free now.

- Add PaylaterPlan as the canonical item model (carries the nullable getters
  + interestAmount). Fluent setters return `static` so the subclass keeps its
  own return typing.
- InstallmentPlan becomes an empty @deprecated subclass of PaylaterPlan: the
  legacy fetchPaylaterInstallmentPlans() flow still returns InstallmentPlan
  and existing type hints / instanceof checks keep working (is-a PaylaterPlan).
  Unlike the standalone container deprecation, inheritance is safe here: the
  item has no sibling-typed parameter method that could widen and fatal.
- PaylaterPlans now maps to PaylaterPlan; PaylaterInstallmentPlans unchanged.
- Tests: new flow asserts PaylaterPlan instances; legacy flow asserts items are
  still InstallmentPlan and now also PaylaterPlan; added a deprecated-subclass
  guard. CHANGELOG: PaylaterPlan added, InstallmentPlan deprecated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ce, to preserve BC

The previous commit made InstallmentPlan a subclass of PaylaterPlan. With
`static` fluent-setter returns this changed InstallmentPlan::setX()'s declared
return type to `static` and made an existing integration that subclasses
InstallmentPlan and overrides a setter with `: InstallmentPlan` fatal
("must be compatible with ... : static") — the same signature-widening break
the container deprecation (PaylaterInstallmentPlans) deliberately avoided.

Switch to the standalone pattern used for the legacy containers:
- InstallmentPlan is reverted to its original signatures byte-for-byte (only an
  @deprecated docblock added); it does NOT extend PaylaterPlan. Its setters
  return `: InstallmentPlan` exactly as released, so existing type hints and
  subclasses keep working.
- PaylaterPlan is an independent new class with the nullable getters +
  interestAmount and `: PaylaterPlan` returns (no `static`).
- Legacy fetchPaylaterInstallmentPlans() returns InstallmentPlan; new
  fetchPaylaterPlans() returns PaylaterPlan. No is-a relationship between them,
  matching the container decision.

Tests: replaced the subclass guard with a reflection test pinning
InstallmentPlan's setter return types to InstallmentPlan and asserting it is
not a subclass of PaylaterPlan. Full unit suite: 808 tests green.

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

Feeds the same installment response to both PaylaterInstallmentPlans (legacy)
and PaylaterPlans (new) and asserts the mapped plan data is identical
(id, amount, currency, and per plan: secciUrl, numberOfRates, totalAmount,
minimumInstallmentFee, nominal/effective interest rate, and rates). Documents
that switching flows is a rename of the query/result/item types plus passing
the payment type to fetchPaylaterPlans(), not a data-shape change.

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

From QA review on PR #254:
- Make PaylaterPlans::setCountry()/setCustomerType() accept null, completing the
  bug-4 null-tolerance (a null field in the response no longer TypeErrors the
  fetch). These are query-only fields not present in the /plans response, so the
  path was unreachable via the real API, but the guard is free and uniform.
  Extended the null-field regression test to cover currency/country/customerType.
- Restore the "## [4.0.2]" CHANGELOG heading that a prior edit accidentally
  dropped, which had mis-nested the 4.0.2 Changed entries under 4.1.0.
- Document the PaymentServiceInterface BC: fetchPaylaterPlans() was added to the
  interface (breaks external implementors) — noted under a 4.1.0 ### Changed.

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

- Remove the PaymentServiceInterface "### Changed/Breaking change" note. Adding
  fetchPaylaterPlans() to the interface is not a consumer-facing break: the
  interface already declared fetchPaylaterInstallmentPlans() in the released
  4.0.2, Unzer::getPaymentService() is typed to the interface, and only an
  external class that itself implements the interface is affected (same pattern
  as the already-shipped legacy method). No breaking change for SDK users.
- Collapse the paylater "now exposed / previously dropped" and the nullable
  "Fixed" bullets (they describe churn within this unreleased feature, not a net
  change vs 4.0.2) into one Added entry describing PaylaterPlan's fields.
- Simplify the deprecation entries (drop the standalone/inheritance detail).

The setCountry/setCustomerType null-tolerance code fix stays; it just no longer
needs a CHANGELOG line.

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

Replace the docblock-only `@var` properties with native typed properties
(`?int`/`?string`/`?float`/`?array`, each defaulting to null). The engine now
enforces the types at the language level instead of relying on annotations,
matching the newer resource style (e.g. Resources/V2/Paypage). Safe here: the
fields are private (expose() only reflects protected properties) and default to
null, so there is no uninitialized-typed-property access. Values still flow
through the existing typed setters, so mapping is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Convert the PaylaterPlans container's docblock-only `@var` properties to native
typed properties (`?float`/`?string`/`array`/`?PaylaterPlansQuery`, defaulting to
null / []). Matches the already-typed PaylaterPlansQuery and PaylaterPlan.
Properties are private (not read by expose(), which only reflects protected) and
default-initialized, and values still flow through the typed setters, so mapping
and behaviour are unchanged.

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

Minor follow-ups from an independent PR review (no behaviour change):
- Fix @return docblocks on PaylaterPlans getters to match the nullable
  signatures (float -> float|null, string -> string|null).
- Clarify PaylaterPlan class docblock: invoice/direct-debit omit
  nominalInterestRate and effectiveInterestRate specifically (interestAmount is
  sent by all three types, so the "omit interest-rate fields" wording was
  ambiguous).
- Strengthen nullPlanAndEnvelopeFieldsMapWithoutError: set numberOfRates and
  totalAmount to null too, so their null-tolerance is actually exercised.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Ryouzanpaku
Ryouzanpaku requested a review from a team as a code owner November 26, 2026 09:50

@Khaled-Mahmoud-Unzer Khaled-Mahmoud-Unzer left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

QA review against the bugs from CC-4346 comment 497250 and my review on #254. I ran the CC-4346 tests in php-sdk-test-automation (offline and live sandbox) against this branch: 66 of 67 pass. The one failure is the lowercase-currency error, which is on the API side, not the SDK.

Fixed

  1. Calling getEffectiveInterestRate() on invoice and direct debit plans returns null instead of crashing.
  2. getInterestAmount() exists and returns the value from the response.
  3. getSecciUrl() returns null when the plan has no SECCI link.
  4. A null value in any field no longer crashes the fetch, now including country, customerType, and a plan where every field is null.
  5. The deleted ## [4.0.2] CHANGELOG heading is back.

Backward compatibility is kept: the legacy fetchPaylaterInstallmentPlans() still returns InstallmentPlan, and the legacy classes keep their 4.0.2 signatures.

Not fixed

  • Bug 5: there's still no CHANGELOG line about fetchPaylaterPlans() being added to PaymentServiceInterface. I understand it was left out on purpose. It only affects external classes that implement the interface, and it's docs only, so I'm not blocking on it. It was suggested in CC-4346 comment 496917, so please confirm there that leaving it out is fine.

Approving.

@Ryouzanpaku
Ryouzanpaku enabled auto-merge (squash) November 26, 2026 10:16

@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.

Approving. The nullable PaylaterPlan model fixes the invoice / direct debit TypeError, and the legacy classes are untouched apart from the @deprecated docblocks.

Two non-blocking CHANGELOG suggestions:

  1. The line about getMinimumInstallmentFee() on the legacy InstallmentPlan was removed, but that method is new compared to 4.0.2. I would restore it, since the entry now says the legacy types are unchanged.
  2. fetchPaylaterPlans() was added to PaymentServiceInterface. A one-line note would help anyone who implements that interface themselves.

@Ryouzanpaku
Ryouzanpaku merged commit 2bb58d0 into main Nov 26, 2026
13 of 14 checks passed
@Ryouzanpaku
Ryouzanpaku deleted the CC-4346/plan-nullable-mapping branch November 26, 2026 11:09
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.

3 participants