Repository navigation
[CC-4239] Add recurring flag to SepaDirectDebit - #247
Conversation
For SEPA, recurrence intent is captured once at type registration via a recurring boolean on POST /v1/types/sepa-direct-debit. The CanRecur trait declared $recurring as a private property, so AbstractUnzerResource::expose() (which serializes only protected properties) silently omitted it from request bodies. Make the trait property protected and nullable (default null) and null-safe in isRecurring(), mirroring the 4.0.2 Keypair private->protected fix. SepaDirectDebit redeclares the property and adds a public fluent setRecurring(); the value is only sent when explicitly set, so request bodies are unchanged when unset. Response mapping is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Keep the recurring entry under the planned 4.1.0 release header instead of 5.0.0, consistent with CC-4078. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Changelog and version edits live in the release ticket (CC-4078), so this feature branch is code-only and won't conflict with the release changelog.
There was a problem hiding this comment.
🟡 Changes recommended
The shared recurring property leaks response-only state into PUT payloads for fetched Card, Paypal, and SepaDirectDebitSecured instances instead of limiting serialization to SepaDirectDebit.
1 open issue
What changed in this PR
Adds support for specifying recurring-payment intent when registering a SEPA Direct Debit payment type in the SDK.
Changes:
- Adds a public fluent
SepaDirectDebit::setRecurring()setter. - Makes the shared recurring property serializable while retaining a default-false getter and omitting unset values.
- Adds unit coverage and a sandbox integration test for recurring registration.
| File | Description |
|---|---|
test/unit/Resources/PaymentTypes/SepaDirectDebitTest.php |
Tests setter behavior, conditional serialization, and response mapping. |
test/integration/PaymentTypes/SepaDirectDebitTest.php |
Tests creating and fetching a recurring SEPA payment type. |
src/Traits/CanRecur.php |
Makes recurring state protected and nullable, with a null-safe getter. |
src/Resources/PaymentTypes/SepaDirectDebit.php |
Declares the recurring field and adds its public fluent setter. |
Review effort: Balanced
…t field private expose() serializes every protected property, so making CanRecur::$recurring protected leaked the response-only flag into requests for all trait consumers (Card, Paypal, SepaDirectDebitSecured) after a fetch-then-update. Revert it to private (nullable, null-safe getter) so it is never serialized for them, and have SepaDirectDebit expose recurring itself via an expose() override, only once set. Drops the now-redundant property redeclaration on SepaDirectDebit and adds a fetched-Card regression test. Addresses the Copilot review comment on PR #247.
Instead of changing the shared CanRecur trait, SepaDirectDebit no longer uses it for recurring. The trait is reverted to its original state, so $recurring stays private/response-only for Card, Paypal and SepaDirectDebitSecured. SEPA declares its own protected ?bool $recurring, which the default expose() serializes when set and omits when null (protected + null-skip) — no expose() override needed. The deprecated activateRecurring() is re-added on the type to preserve BC. Keeps the fetched-Card regression test.
With CanRecur left untouched, Card is no longer affected by this change, so the fetched-Card serialization test guards behaviour outside this PR's scope. The in-scope SepaDirectDebit unit tests already cover the recurring serialization.
There was a problem hiding this comment.
🟡 Changes recommended
Removing CanRecur causes the service’s trait-based capability check to reject SepaDirectDebit, breaking both existing recurring-activation entry points with a RuntimeException before reaching the API.
1 open issue
1 resolved since last review
Review effort: Balanced
| public function activateRecurring($returnUrl, $recurrenceType = null): Recurring | ||
| { | ||
| return $this->getUnzerObject()->activateRecurringPayment($this, $returnUrl, $recurrenceType); |
There was a problem hiding this comment.
Good catch — fixed by keeping CanRecur on SepaDirectDebit rather than removing it.
SepaDirectDebit now uses the trait again, so activateRecurringPayment()'s class_uses(CanRecur::class) gate accepts it and both $sdd->activateRecurring(...) and $unzer->activateRecurringPayment($sdd, ...) work. The deprecated activateRecurring() comes from the trait now (local copy dropped).
The original serialization fix is preserved without touching the trait for the other consumers:
CanRecur::$recurringstays private / response-only — Card, Paypal, SepaDirectDebitSecured unaffected (no leak on fetch-then-update).- The request-time flag is owned by
SepaDirectDebitvia a nullable$recurringRequestedshadow, emitted through anexpose()override only when explicitly set (includingfalse); a fresh instance's body is unchanged.
Added regression coverage:
ResourceServiceTest::activateRecurringPaymentAcceptsSepaDirectDebit— guards the capability gate so removing the trait fails loudly.SepaDirectDebitTest::recurringIsExposedWhenTypeIsOtherwiseEmpty— covers the expose() override on an empty (null-IBAN) type.
Full unit suite green (751 tests).
There was a problem hiding this comment.
🔵 Needs a closer look
Removing CanRecur from SepaDirectDebit without updating the service capability check causes legacy recurring activation calls to throw before reaching the API, breaking the existing SEPA integration test.
Review effort: Balanced
sixer1182
left a comment
There was a problem hiding this comment.
Review: changes requested
The mechanism matches the tech spec: the recurring flag is sent once at type registration, nothing is added to the charge, and CanRecur as well as the other payment types stay untouched. Unit tests pass locally (749) and in CI. There is one blocker, tests are missing, and some deviations from the ticket need a decision.
1. Blocker: backward compatibility is broken for the deprecated recurring activation
Backward compatibility must be guaranteed for this change. It is not at the moment.
SepaDirectDebit no longer uses CanRecur, but ResourceService::activateRecurringPayment() still decides per class_uses() whether a payment type supports recurring (src/Services/ResourceService.php:433). For SepaDirectDebit this check now fails. I reproduced it on the PR head (3bae334):
$resourceService->activateRecurringPayment($sdd, 'https://example.com/return');
-> RuntimeException: Recurring is not available for the given payment type.
Both public entry points are affected: $sdd->activateRecurring(...) and $unzer->activateRecurringPayment($sdd, ...). The local copy of activateRecurring() on SepaDirectDebit therefore does not preserve compatibility, and the statements "preserving backwards compatibility" and "zero blast radius" in the PR description are incorrect. This is a breaking change in a minor release. The ticket also explicitly says to keep the CanRecur trait and to leave the deprecated activation flow unchanged. (Copilot raised the same point: #247 (comment))
Please fix it so that existing callers of both entry points keep working exactly as before. Two options:
- Keep
use CanRecuronSepaDirectDebit(as the ticket asks). The trait's$recurringstays private, andSepaDirectDebitoverridesexpose()to addrecurringonly when it was explicitly set. This was the approach of an earlier commit on this branch. I did not test it. - Keep the current inline approach and make the check in
ResourceServiceacceptSepaDirectDebitwithout the trait.
Whichever option you choose, the local duplicate of activateRecurring() should only stay if it is still needed.
2. Missing tests (required before approval)
- Unit test for
ResourceService::activateRecurringPayment()with a realSepaDirectDebitinstance (object and id variant). The existing tests only use the dummyTraitDummyCanRecur, which is why this was not caught. - Unit test for
SepaDirectDebit::activateRecurring()calling through to the service without aRuntimeException. - Unit test for the behavior of a fetched type: after
handleResponse()withrecurring, what doesexpose()contain? Currently the response value is sent again on update requests ({"iban":…,"id":…,"recurring":false}). Please document the intended behavior in a test. If PAPI does not acceptrecurringonPUT /v1/types/sepa-direct-debit/{id}, this needs to be changed. Please confirm against the PAPI schema. - The new integration test has not been run (needs sandbox credentials, not part of CI). The ticket's acceptance criteria require it to pass. Please run it against the sandbox and state the result in the PR. Note that the registration call-through to the SEPA PMP sits behind a system property in PAPI; please confirm the sandbox returns
recurringon create and fetch.
3. Deviations from the ticket (CC-4239)
CanRecurremoved fromSepaDirectDebitinstead of kept. The ticket says to keep it and resolve the clash. Your reasoning about the private property clash is correct, and the deviation is documented in the ticket comment. It is, however, the cause of the blocker above, and the ticket lists the deprecated activation flow as out of scope for changes. Please resolve it as described in section 1.- Duplicated
activateRecurring()on the class. The ticket says to leave the deprecated flow as is. A copy with identical docblock creates two places to maintain. - No CHANGELOG entry in this PR, although the ticket lists
CHANGELOG.mdamong the files and the acceptance criteria. The entry is in #248 (whose title mentions only the version rename). That is acceptable if #247 and #248 are merged together, or #247 first. Please state this in the PR description so the changelog never mentions a feature that is not in the code yet. - Two PRs instead of one. The ticket asks for exactly one PR. Follows from point 3; please confirm this split is agreed.
recurringis serialized for fetched instances (see test item 3). The ticket's criterion "request body unchanged when nothing is set" holds for fresh instances only. This should be a deliberate decision, not a side effect.
4. What looks good
setRecurring(bool): selfis public and fluent;isRecurring()returnsfalsewhen nothing was set.- A fresh instance exposes no
recurringkey; set totrueorfalseit is exposed. - Response mapping works through
handleResponse()and nothing writes the value twice. SepaDirectDebitSecured,CardandPaypalare unchanged.
Changes requested for: the compatibility break (1), the missing tests (2), and a decision on the deviations (3).
…gate SepaDirectDebit no longer dropped the CanRecur trait. Removing it had broken the capability gate in ResourceService::activateRecurringPayment() (class_uses check), so both $sdd->activateRecurring(...) and $unzer->activateRecurringPayment($sdd, ...) threw RuntimeException before reaching the API. The trait's $recurring stays private/response-only (Card, Paypal, SepaDirectDebitSecured unaffected). The request-time flag is owned by SepaDirectDebit via a nullable $recurringRequested shadow, exposed through an expose() override that emits `recurring` only when explicitly set (including false); a fresh instance's request body is unchanged. Add ResourceServiceTest::activateRecurringPaymentAcceptsSepaDirectDebit as a regression guard. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…epaDirectDebit Exercises the expose() override's (array) cast when parent::expose() returns an empty stdClass (null IBAN), the edge case the override guards. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
6035f56 to
531f574
Compare
…e (default false) Drop the nullable $recurringRequested shadow and the isRecurring() override. SepaDirectDebit now writes the trait's own $recurring via a public setRecurring() and always serializes it (default false) in the type-registration body, instead of omitting it when unset. The trait's non-nullable bool can't model "unset", so the always-send-with-false-default is the chosen trade-off. isRecurring() and activateRecurring() come straight from the trait; the class_uses() gate in ResourceService still accepts the type. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…via use-adaptation
The override's body was identical to CanRecur::setRecurring() — its only
purpose was widening visibility. Replace it with `use CanRecur { setRecurring
as public; }`, which changes visibility without redefining the method.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ptation Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Reworked along your option 1 (re: #247 (review)). New approach: Blocker resolved: because the trait is retained, the Small caveat: the override always sends Full unit suite green (751). PR description and the Jira ticket updated to match. |
sixer1182
left a comment
There was a problem hiding this comment.
Follow-up review: changes still requested
Thanks for the rework. I re-checked the PR head (696dcc1) locally: 751 unit tests pass.
Resolved
- The compatibility break is fixed.
SepaDirectDebitusesCanRecuragain, the trait is untouched, and theclass_uses()check inResourceService::activateRecurringPayment()accepts the type.Card,PaypalandSepaDirectDebitSecuredserialize as before, also after a fetch. - The duplicated
activateRecurring()is gone.
Still open
1. recurring is now always sent: decision needed
The ticket's acceptance criterion says the request body must be unchanged when setRecurring() was never called. With the expose() override, {"iban":…,"recurring":false} is sent for every new SEPA type. The tech spec says false and absent mean the same (one-off mandate), so the behavior is functionally equivalent for a PAPI that has the field. I still see two risks and one alternative:
- A PAPI version without the field, or a strict schema check, could reject an unknown field. The epic names the PAPI release that introduced it, but nothing in this PR confirms that all environments have it.
- After a fetch,
expose()sends the value from the API response, including on the IBAN-amendmentPUTthat the tech spec adds. Please confirm with the PAPI team thatPUT /v1/types/sepa-direct-debit/{id}accepts or ignoresrecurring. The mandate type is set once at activation. - The reasoning that "unset" cannot be modeled is too narrow. A separate nullable property in
SepaDirectDebit(a different name than the trait's private$recurring, not an exposed protected property) does not collide with the trait.setRecurring()would set both, andexpose()would addrecurringonly when it was explicitly set. This keeps the acceptance criterion.
Please either implement option 3 or get a written confirmation for points 1 and 2 and update the ticket's acceptance criteria accordingly.
2. Missing tests (still requested)
SepaDirectDebit::activateRecurring()called directly on the type (not only through the service).activateRecurringPayment()with a type ID (the fetch variant), not only with an object.- Behavior after a fetch: what
expose()contains afterhandleResponse()withrecurringtrue and false, and without the field.
3. Integration test
The new integration test still has not been reported as run. Please run it against the sandbox and state the result in the PR, including whether the sandbox returns recurring on create and fetch.
4. Outdated descriptions
- The PR description says the CHANGELOG entry was added in this PR. It is not part of the diff (it is in #248). Please correct the text and state the merge order (#247 first or both together).
- An earlier comment on this PR describes a
$recurringRequestedproperty and anexpose()that sends the flag only when set. Neither exists in the current code. Please mark the comment as outdated.
Changes requested for points 1 to 3. Point 4 is clean-up.
|
Updated: points 2 and 3 resolved (tests added, integration run). Thanks @sixer1182 — glad the BC break and the duplicate 1. We're keeping always-send over option 3 deliberately: staying on On the amend 2. Tests. ✅ Done. The existing coverage ( 3. Integration test. ✅ Run against the sandbox — 4. Descriptions. Fixed: the PR description no longer claims the CHANGELOG is in this PR — it's scoped to #248 (CC-4078) with the version rename, and I added the merge order (disjoint files, either order). The earlier "expose only when set" inline comment is marked outdated below. |
…integration) Guards that keeping the CanRecur trait on SepaDirectDebit leaves the deprecated activateRecurring() flow working for the type (the ResourceService class_uses capability gate still accepts it).
…ected Verified against the sandbox: SEPA registers the mandate during charge/authorize, so a direct recurring call returns API.640.550.005. Asserting this confirms the type still passes the CanRecur capability gate and routes to the API.
sixer1182
left a comment
There was a problem hiding this comment.
Approving. Thanks for the rework and for the explanations.
I re-checked the PR head (aaa157e) locally: 751 unit tests pass. The compatibility break is fixed (CanRecur is kept, the capability check accepts SepaDirectDebit), the other payment types serialize as before, and the PR description now matches the diff.
I accept always sending recurring (default false). The tech spec treats false and absent the same, the field is in the released PAPI versions (1.191 and 1.192), and PAPI manages recurring itself on PUT. A one-line confirmation from the PAPI team that a recurring value in the PUT body is ignored would still be good.
Two points should be done, but they do not block the merge:
- Unit test for the fetched state. Please add a test that documents what
expose()contains afterhandleResponse()withrecurringtrue, false, and without the field (for example{"iban":…,"id":…,"recurring":true}after a fetch). The tests named in the last comment (recurringIsMappedFromResponse,recurringIsAlwaysExposed) do not check this: the first only checksisRecurring(), the second only fresh instances. - Acceptance criteria in the ticket. The description of CC-4239 still says "without calling
setRecurring()the request body is unchanged". The PR now always sendsrecurring. Please update the description of the ticket to the current behavior.
Minor: sepaDirectDebitShouldActivateRecurringViaType pins the PAPI error code API.640.550.005 and does not run in CI. That is acceptable, but it will break if PAPI changes that code.
|
Thanks for the approval. Both non-blocking points are addressed:
On the minor: agreed |
…G) (#248) * [CC-4078] Rename unreleased changelog section to planned 4.1.0 The PHP SDK release is planned as 4.1.0, not 5.0.0. Rename the top unreleased CHANGELOG section header (and its compare URL) accordingly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * [CC-4078] Add recurring entry to 4.1.0 changelog Scope the SepaDirectDebit recurring changelog entry under the release ticket (CC-4078) alongside the version rename, so the feature PR #247 (CC-4239) stays code-only and the two don't conflict. * [CC-4078] Complete the 4.1.0 changelog with all released changes Add the Keypair getRawResponse() addition (CC-4151) and the PIS payment-type deprecation (CC-4064) to the 4.1.0 section, alongside the recurring flag (CC-4239) and the PHP 8.1 removal (CC-4228) — the full set of merged changes for the release. * [CC-4078] Add CC-4256 Keypair boolean-parsing fix to 4.1.0 changelog Document the merged fix (#251): Keypair boolean flags sent as strings (validateBasket, cof) were coerced so "false" became true; now parsed correctly. CC-4255 (payment-type duplication, #250) will be added once merged. * [CC-4078] Prepare 4.1.0 release: bump SDK version and complete changelog Bump Unzer::SDK_VERSION to 4.1.0 and stage the remaining 4.1.0 changelog entries: deprecate Sofort (CC-4344, #252) and the Keypair plain-fetch payment-type de-duplication fix (CC-4255, #250). Those two feature PRs must merge before this release-preparation PR. --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…256) * [CC-4239] Name SepaDirectDebit::setRecurring param $recurring + add SEPA PHPDoc QA (CC-4239 comment 495774) on the merged PR #247 found the public setter's parameter is $active (inherited via `use CanRecur { setRecurring as public; }`), not $recurring as the ticket specified. Since PHP 8 makes the parameter name part of the public API, `->setRecurring(recurring: true)` threw "Unknown named parameter $recurring". Replace the trait alias with an explicit public override `setRecurring(bool $recurring): self` on SepaDirectDebit, carrying SEPA-specific PHPDoc (RCUR/OOFF mandate intent) — this fixes the parameter name (bug 1) and the missing docblock (bug 2) together. `use CanRecur` is kept, so isRecurring(), the deprecated activateRecurring() and the ResourceService class_uses(CanRecur) capability gate are unchanged (verified by reflection probe). Added a unit test pinning the named-argument form. Note: 4.1.0 is unreleased, so this only shapes the setter before release — no CHANGELOG churn. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * [CC-4239] Keep setRecurring parameter name as $active (deliberate) Reverts the parameter name from $recurring back to $active. With the method already named setRecurring, `$active` reads better than the redundant `setRecurring(recurring: true)` — a deliberate maintainer decision that supersedes the ticket AC's suggested `$recurring`. The important BC point still holds: the public parameter name is settled before release (4.1.0 unreleased), so there is no future named-argument break. The explicit public override is kept for the SEPA-specific PHPDoc (bug 2); only the parameter name changes. Named-argument test updated to `active: true`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * [CC-4239] Pin setRecurring param name via reflection, not a named-arg call A named-argument call (setRecurring(active: true)) reads contrived for a single-parameter setter. Replace it with a reflection assertion on the parameter (name `active`, type `bool`) — that pins the actual public-API surface directly and matches the repo's existing signature-pinning idiom (legacySignatureDataProvider). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * [CC-4239] Drop the brittle param-name reflection test A reflection test that hard-pins the parameter name is brittle and low-value: PHP parameter-name stability is only a BC concern if the library promises named-argument support, which this SDK does not (cf. Symfony excluding param names from its BC promise / @no-named-arguments). Behaviour is already covered by the setter/getter, expose, and response-mapping tests. The parameter stays $active for consistency with the CanRecur trait — no test needed to enforce it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * [CC-4239] Trim internal detail from setRecurring PHPDoc Drop the PMP / RCUR-OOFF mandate-derivation and charge-payload internals from the public docblock — that is internal platform behaviour an integrator should not need to know. Keep only the caller-facing contract: true = recurring (mandate-based) collection, false (default) = one-off, applied at type registration. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * [CC-4239] Drop redundant @param/@return from setRecurring docblock The parameter and return types are already declared in the typed signature (setRecurring(bool $active): self), so the @param/@return tags add nothing. Keep the descriptive text only. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

What
Adds a
recurringboolean request field to thesepa-direct-debitpayment type. For SEPA, recurrence intent is captured once at type registration viarecurringonPOST /v1/types/sepa-direct-debit.SepaDirectDebit::setRecurring(bool $recurring): self— public, fluent (matchessetIban/setBic/setHolder).SepaDirectDebit::isRecurring(): bool— getter (fromCanRecur); returns the set value, or the value mapped from a fetched resource,falsewhen never set.recurringis always included in the type-registration request body, defaulting tofalsewhen never set.Why
SepaDirectDebitrelies on the sharedCanRecurtrait whose$recurringproperty is private.AbstractUnzerResource::expose()serializes only protected (non-null) properties, so the flag never reached the request body — it only reflected the API's read-only response flag. This is the same class of bug fixed forKeypairin 4.0.2 ("silently omitted when serialized into a request payload").How it's implemented
The shared
CanRecurtrait is left untouched — its$recurringstaysprivate/response-only, soCard,PaypalandSepaDirectDebitSecuredare unaffected (zero blast radius).SepaDirectDebitkeepsuse CanRecurand adds only two members:setRecurring(bool): self— widens the trait'sprotectedsetter topublicand writes the trait's own$recurring, soisRecurring()(from the trait) reflects it.expose()override — always appendsrecurring(defaultfalse) to the serialized body.Keeping the trait means
activateRecurring()and theResourceService::activateRecurringPayment()capability gate (in_array(CanRecur::class, class_uses(...))) continue to acceptSepaDirectDebit. Removing the trait would have thrownRuntimeExceptionbefore reaching the API — see the resolved review thread.Trade-off
Ideally
recurringwould be omitted when never set, but the trait's property is a non-nullablebool(can't model "unset"), and a nullable redeclaration on the subclass collides with the trait. Always sending the flag with afalsedefault is the chosen compromise; it is scoped toSepaDirectDebitonly.Tests
test/unit/Resources/PaymentTypes/SepaDirectDebitTest.php): setter/getter round-trip,expose()always containsrecurring(true / false / default-false), empty-type edge case, and response-mapping viahandleResponse().test/unit/Services/ResourceServiceTest.php::activateRecurringPaymentAcceptsSepaDirectDebit— regression guard that the type keeps theCanRecurgate.test/integration/PaymentTypes/SepaDirectDebitTest.php): create-with-setRecurring(true)→ fetch →isRecurring()is true. Requires sandbox credentials; not run in CI.CHANGELOG
The CHANGELOG entry is not part of this PR. Changelog and version edits for the 4.1.0 release are scoped to the release ticket CC-4078 in #248, which adds the
### Addedentry for this feature alongside the5.0.0 → 4.1.0version rename. This keeps #247 code-only.Merge order
#247 and #248 both target the 4.1.0 release and change disjoint files, so either can merge first without a conflict.
🤖 Generated with Claude Code