From e8a3aa65a8b73d7cb0bd4818e888c2799dec9e8f Mon Sep 17 00:00:00 2001 From: David Owusu Date: Thu, 5 Nov 2026 13:21:08 +0100 Subject: [PATCH 01/13] [CC-4239] Add recurring request flag to SepaDirectDebit payment type 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) --- CHANGELOG.md | 4 + .../PaymentTypes/SepaDirectDebit.php | 16 ++++ src/Traits/CanRecur.php | 6 +- .../PaymentTypes/SepaDirectDebitTest.php | 18 +++++ .../PaymentTypes/SepaDirectDebitTest.php | 81 +++++++++++++++++++ 5 files changed, 122 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e8b23eb6..337828d2e 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [5.0.0](https://github.com/unzerdev/php-sdk/compare/4.0.2..5.0.0) +### Added + +* `recurring` flag on `\UnzerSDK\Resources\PaymentTypes\SepaDirectDebit` for registering a payment type for recurring (mandate-based) collection. + ### Removed * Support for PHP 8.1. The minimum supported PHP version is now 8.2 (`composer.json` requires `~8.2.0|~8.3.0|~8.4.0|~8.5.0`). PHP 8.1 is end of life and has no official fix for the PHP2Shell vulnerabilities (CVE-2026-109618, CVE-2026-109619). diff --git a/src/Resources/PaymentTypes/SepaDirectDebit.php b/src/Resources/PaymentTypes/SepaDirectDebit.php index ba7e51e18..e9e01dbbe 100755 --- a/src/Resources/PaymentTypes/SepaDirectDebit.php +++ b/src/Resources/PaymentTypes/SepaDirectDebit.php @@ -27,6 +27,9 @@ class SepaDirectDebit extends BasePaymentType /** @var string $holder */ protected $holder; + /** @var bool|null $recurring */ + protected ?bool $recurring = null; + /** * @param string|null $iban */ @@ -91,4 +94,17 @@ public function setHolder(?string $holder): self $this->holder = $holder; return $this; } + + /** + * Registers the payment type for recurring (mandate-based) collection. + * + * @param bool $recurring + * + * @return $this + */ + public function setRecurring(bool $recurring): self + { + $this->recurring = $recurring; + return $this; + } } diff --git a/src/Traits/CanRecur.php b/src/Traits/CanRecur.php index 23e05fb60..4c7a05fb1 100644 --- a/src/Traits/CanRecur.php +++ b/src/Traits/CanRecur.php @@ -15,8 +15,8 @@ trait CanRecur { - /** @var bool $recurring */ - private $recurring = false; + /** @var bool|null $recurring */ + protected ?bool $recurring = null; /** * Activates recurring payment for the payment type. @@ -46,7 +46,7 @@ public function activateRecurring($returnUrl, $recurrenceType = null): Recurring */ public function isRecurring(): bool { - return $this->recurring; + return $this->recurring ?? false; } /** diff --git a/test/integration/PaymentTypes/SepaDirectDebitTest.php b/test/integration/PaymentTypes/SepaDirectDebitTest.php index b97268e02..f1e2cad63 100755 --- a/test/integration/PaymentTypes/SepaDirectDebitTest.php +++ b/test/integration/PaymentTypes/SepaDirectDebitTest.php @@ -60,6 +60,24 @@ public function sepaDirectDebitShouldBeCreatable(): void $this->assertEquals($sdd->expose(), $fetchedDirectDebit->expose()); } + /** + * Verify sepa direct debit can be registered for recurring collection. + * + * @test + */ + public function sepaDirectDebitShouldBeCreatableWithRecurringFlag(): void + { + $sdd = (new SepaDirectDebit('DE89370400440532013000'))->setRecurring(true); + /** @var SepaDirectDebit $sdd */ + $sdd = $this->unzer->createPaymentType($sdd); + $this->assertInstanceOf(SepaDirectDebit::class, $sdd); + $this->assertNotNull($sdd->getId()); + + /** @var SepaDirectDebit $fetchedDirectDebit */ + $fetchedDirectDebit = $this->unzer->fetchPaymentType($sdd->getId()); + $this->assertTrue($fetchedDirectDebit->isRecurring()); + } + /** * Verify authorization is not allowed for sepa direct debit. * diff --git a/test/unit/Resources/PaymentTypes/SepaDirectDebitTest.php b/test/unit/Resources/PaymentTypes/SepaDirectDebitTest.php index 50c316772..28617eca0 100755 --- a/test/unit/Resources/PaymentTypes/SepaDirectDebitTest.php +++ b/test/unit/Resources/PaymentTypes/SepaDirectDebitTest.php @@ -7,6 +7,7 @@ use UnzerSDK\Resources\PaymentTypes\SepaDirectDebit; use UnzerSDK\test\BasePaymentTest; +use stdClass; class SepaDirectDebitTest extends BasePaymentTest { @@ -42,4 +43,84 @@ public function getterAndSetterWorkAsExpected(): void $sdd->setHolder('Max Mustermann'); $this->assertEquals('Max Mustermann', $sdd->getHolder()); } + + /** + * Verify the recurring flag defaults to false and round-trips through the fluent setter. + * + * @test + * + * @dataProvider recurringValueProvider + */ + public function recurringSetterAndGetterWorkAsExpected(bool $value): void + { + $sdd = new SepaDirectDebit('DE89370400440532013000'); + $this->assertFalse($sdd->isRecurring()); + + $this->assertSame($sdd, $sdd->setRecurring($value)); + $this->assertSame($value, $sdd->isRecurring()); + } + + /** + * Verify the recurring flag is only exposed once explicitly set. + * + * @test + * + * @dataProvider exposeRecurringProvider + */ + public function recurringIsExposedOnlyWhenSet(?bool $value, bool $shouldBeExposed): void + { + $sdd = new SepaDirectDebit('DE89370400440532013000'); + if ($value !== null) { + $sdd->setRecurring($value); + } + + $exposed = $sdd->expose(); + if ($shouldBeExposed) { + $this->assertArrayHasKey('recurring', $exposed); + $this->assertSame($value, $exposed['recurring']); + } else { + $this->assertArrayNotHasKey('recurring', $exposed); + } + } + + /** + * Verify a response containing the recurring flag is mapped onto the resource. + * + * @test + * + * @dataProvider recurringValueProvider + */ + public function recurringIsMappedFromResponse(bool $value): void + { + $sdd = new SepaDirectDebit('DE89370400440532013000'); + + $response = new stdClass(); + $response->recurring = $value; + $sdd->handleResponse($response); + + $this->assertSame($value, $sdd->isRecurring()); + } + + /** + * @return array + */ + public function recurringValueProvider(): array + { + return [ + 'recurring true' => [true], + 'recurring false' => [false], + ]; + } + + /** + * @return array + */ + public function exposeRecurringProvider(): array + { + return [ + 'set to true' => [true, true], + 'set to false' => [false, true], + 'not set' => [null, false], + ]; + } } From 18ac10e1dcccadffeeb4e82b838f1215491f8eb5 Mon Sep 17 00:00:00 2001 From: David Owusu Date: Thu, 5 Nov 2026 15:05:28 +0100 Subject: [PATCH 02/13] [CC-4239] Align changelog section to planned 4.1.0 version 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) --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 337828d2e..faea18338 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. 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). -## [5.0.0](https://github.com/unzerdev/php-sdk/compare/4.0.2..5.0.0) +## [4.1.0](https://github.com/unzerdev/php-sdk/compare/4.0.2..4.1.0) ### Added From 6a6c50bbb12db9557b058906aaa76b64ca2c6d64 Mon Sep 17 00:00:00 2001 From: David Owusu Date: Thu, 5 Nov 2026 15:50:12 +0100 Subject: [PATCH 03/13] [CC-4239] Remove changelog entry; scoped under CC-4078 release PR 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. --- CHANGELOG.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index faea18338..9e8b23eb6 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +5,7 @@ All notable changes to this project will be documented in this file. 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). -## [4.1.0](https://github.com/unzerdev/php-sdk/compare/4.0.2..4.1.0) - -### Added - -* `recurring` flag on `\UnzerSDK\Resources\PaymentTypes\SepaDirectDebit` for registering a payment type for recurring (mandate-based) collection. +## [5.0.0](https://github.com/unzerdev/php-sdk/compare/4.0.2..5.0.0) ### Removed From db4b609a092cf856eb3791bb8d539617bdb7f6f5 Mon Sep 17 00:00:00 2001 From: David Owusu Date: Mon, 9 Nov 2026 11:28:38 +0100 Subject: [PATCH 04/13] [CC-4239] Scope recurring serialization to SepaDirectDebit; keep trait 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. --- .../PaymentTypes/SepaDirectDebit.php | 25 ++++++++++++++++--- src/Traits/CanRecur.php | 10 ++++++-- test/unit/Resources/PaymentTypes/CardTest.php | 18 +++++++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/Resources/PaymentTypes/SepaDirectDebit.php b/src/Resources/PaymentTypes/SepaDirectDebit.php index e9e01dbbe..259e667dc 100755 --- a/src/Resources/PaymentTypes/SepaDirectDebit.php +++ b/src/Resources/PaymentTypes/SepaDirectDebit.php @@ -27,9 +27,6 @@ class SepaDirectDebit extends BasePaymentType /** @var string $holder */ protected $holder; - /** @var bool|null $recurring */ - protected ?bool $recurring = null; - /** * @param string|null $iban */ @@ -107,4 +104,26 @@ public function setRecurring(bool $recurring): self $this->recurring = $recurring; return $this; } + + /** + * {@inheritDoc} + * + * Adds the `recurring` flag to the request body. Unlike the other CanRecur consumers (where it stays a + * read-only response flag), sepa-direct-debit accepts `recurring` on type registration, so it is exposed + * here — but only once it has a value, keeping a fresh, never-set instance byte-for-byte as before. + */ + public function expose() + { + $exposeArray = parent::expose(); + + if ($this->recurring !== null) { + if (!is_array($exposeArray)) { + $exposeArray = []; + } + $exposeArray['recurring'] = $this->recurring; + ksort($exposeArray); + } + + return $exposeArray; + } } diff --git a/src/Traits/CanRecur.php b/src/Traits/CanRecur.php index 4c7a05fb1..7130fe0c6 100644 --- a/src/Traits/CanRecur.php +++ b/src/Traits/CanRecur.php @@ -15,8 +15,14 @@ trait CanRecur { - /** @var bool|null $recurring */ - protected ?bool $recurring = null; + /** + * @var bool|null $recurring + * + * Kept private so it is never serialized into a request for the trait's consumers: for every + * payment type except SepaDirectDebit this is a read-only flag returned by the API. SepaDirectDebit + * exposes it as a request field itself via its own expose() override. + */ + private ?bool $recurring = null; /** * Activates recurring payment for the payment type. diff --git a/test/unit/Resources/PaymentTypes/CardTest.php b/test/unit/Resources/PaymentTypes/CardTest.php index d956d0a8c..5d98cba6e 100755 --- a/test/unit/Resources/PaymentTypes/CardTest.php +++ b/test/unit/Resources/PaymentTypes/CardTest.php @@ -74,6 +74,24 @@ protected function setUp(): void $this->card = new Card($this->number, $this->expiryDate); } + /** + * A `recurring` flag returned by the API is response-only for Card and must never be sent back in a + * follow-up request (e.g. a fetch-then-update flow). Regression guard for the CanRecur trait: its + * `$recurring` property stays private so it is not serialized for trait consumers other than + * SepaDirectDebit. + * + * @test + */ + public function recurringFlagMappedFromResponseIsNeverExposed(): void + { + $response = new stdClass(); + $response->recurring = true; + $this->card->handleResponse($response); + + $this->assertTrue($this->card->isRecurring()); + $this->assertArrayNotHasKey('recurring', $this->card->expose()); + } + /** * Verify the resource data is set properly. * From 93839f3ca371842747ccdc53442bf7f533f1a3f1 Mon Sep 17 00:00:00 2001 From: David Owusu Date: Mon, 9 Nov 2026 12:02:10 +0100 Subject: [PATCH 05/13] [CC-4239] Move recurring onto SepaDirectDebit; keep CanRecur untouched MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../PaymentTypes/SepaDirectDebit.php | 47 +++++++++++-------- src/Traits/CanRecur.php | 12 ++--- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/Resources/PaymentTypes/SepaDirectDebit.php b/src/Resources/PaymentTypes/SepaDirectDebit.php index 259e667dc..53a678480 100755 --- a/src/Resources/PaymentTypes/SepaDirectDebit.php +++ b/src/Resources/PaymentTypes/SepaDirectDebit.php @@ -8,15 +8,14 @@ namespace UnzerSDK\Resources\PaymentTypes; +use UnzerSDK\Resources\Recurring; use UnzerSDK\Traits\CanDirectCharge; use UnzerSDK\Traits\CanPayout; -use UnzerSDK\Traits\CanRecur; class SepaDirectDebit extends BasePaymentType { use CanDirectCharge; use CanPayout; - use CanRecur; /** @var string $iban */ protected $iban; @@ -27,6 +26,9 @@ class SepaDirectDebit extends BasePaymentType /** @var string $holder */ protected $holder; + /** @var bool|null $recurring Mandate-based recurring flag, accepted on type registration. */ + protected ?bool $recurring = null; + /** * @param string|null $iban */ @@ -93,7 +95,17 @@ public function setHolder(?string $holder): self } /** - * Registers the payment type for recurring (mandate-based) collection. + * @return bool Whether the payment type is registered for recurring (mandate-based) collection. + */ + public function isRecurring(): bool + { + return $this->recurring ?? false; + } + + /** + * Registers the payment type for recurring (mandate-based) collection. Set this before creating the type; + * it is sent in the `POST /v1/types/sepa-direct-debit` request body. A fresh instance that never sets it + * leaves the flag out of the request entirely. * * @param bool $recurring * @@ -106,24 +118,21 @@ public function setRecurring(bool $recurring): self } /** - * {@inheritDoc} + * Activates recurring payment for the payment type. * - * Adds the `recurring` flag to the request body. Unlike the other CanRecur consumers (where it stays a - * read-only response flag), sepa-direct-debit accepts `recurring` on type registration, so it is exposed - * here — but only once it has a value, keeping a fresh, never-set instance byte-for-byte as before. + * @param string $returnUrl The URL to which the customer gets redirected in case of a 3ds transaction. + * @param null|mixed $recurrenceType Recurrence type used for recurring payment. + * + * @return Recurring + * + * @throws \UnzerSDK\Exceptions\UnzerApiException An UnzerApiException is thrown if there is an error returned + * on API-request. + * + * @deprecated since 1.3.0.0 Please set the recurrence type in your Charge/Authorize object using + * `setRecurrenceType` before performing the transaction request. */ - public function expose() + public function activateRecurring($returnUrl, $recurrenceType = null): Recurring { - $exposeArray = parent::expose(); - - if ($this->recurring !== null) { - if (!is_array($exposeArray)) { - $exposeArray = []; - } - $exposeArray['recurring'] = $this->recurring; - ksort($exposeArray); - } - - return $exposeArray; + return $this->getUnzerObject()->activateRecurringPayment($this, $returnUrl, $recurrenceType); } } diff --git a/src/Traits/CanRecur.php b/src/Traits/CanRecur.php index 7130fe0c6..23e05fb60 100644 --- a/src/Traits/CanRecur.php +++ b/src/Traits/CanRecur.php @@ -15,14 +15,8 @@ trait CanRecur { - /** - * @var bool|null $recurring - * - * Kept private so it is never serialized into a request for the trait's consumers: for every - * payment type except SepaDirectDebit this is a read-only flag returned by the API. SepaDirectDebit - * exposes it as a request field itself via its own expose() override. - */ - private ?bool $recurring = null; + /** @var bool $recurring */ + private $recurring = false; /** * Activates recurring payment for the payment type. @@ -52,7 +46,7 @@ public function activateRecurring($returnUrl, $recurrenceType = null): Recurring */ public function isRecurring(): bool { - return $this->recurring ?? false; + return $this->recurring; } /** From 3bae334d6dcd5a7afbebba96c7f983a554038bc9 Mon Sep 17 00:00:00 2001 From: David Owusu Date: Mon, 9 Nov 2026 13:20:50 +0100 Subject: [PATCH 06/13] [CC-4239] Drop out-of-scope 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. --- test/unit/Resources/PaymentTypes/CardTest.php | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/test/unit/Resources/PaymentTypes/CardTest.php b/test/unit/Resources/PaymentTypes/CardTest.php index 5d98cba6e..d956d0a8c 100755 --- a/test/unit/Resources/PaymentTypes/CardTest.php +++ b/test/unit/Resources/PaymentTypes/CardTest.php @@ -74,24 +74,6 @@ protected function setUp(): void $this->card = new Card($this->number, $this->expiryDate); } - /** - * A `recurring` flag returned by the API is response-only for Card and must never be sent back in a - * follow-up request (e.g. a fetch-then-update flow). Regression guard for the CanRecur trait: its - * `$recurring` property stays private so it is not serialized for trait consumers other than - * SepaDirectDebit. - * - * @test - */ - public function recurringFlagMappedFromResponseIsNeverExposed(): void - { - $response = new stdClass(); - $response->recurring = true; - $this->card->handleResponse($response); - - $this->assertTrue($this->card->isRecurring()); - $this->assertArrayNotHasKey('recurring', $this->card->expose()); - } - /** * Verify the resource data is set properly. * From 608d884f644f9c2fa9011fcbc3b7b75abe525b3a Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Tue, 17 Nov 2026 10:07:18 +0100 Subject: [PATCH 07/13] [CC-4239] Keep CanRecur on SepaDirectDebit; fix recurring activation 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) --- .../PaymentTypes/SepaDirectDebit.php | 48 ++++++++++++------- test/unit/Services/ResourceServiceTest.php | 22 +++++++++ 2 files changed, 52 insertions(+), 18 deletions(-) diff --git a/src/Resources/PaymentTypes/SepaDirectDebit.php b/src/Resources/PaymentTypes/SepaDirectDebit.php index 53a678480..ad772c51a 100755 --- a/src/Resources/PaymentTypes/SepaDirectDebit.php +++ b/src/Resources/PaymentTypes/SepaDirectDebit.php @@ -8,14 +8,15 @@ namespace UnzerSDK\Resources\PaymentTypes; -use UnzerSDK\Resources\Recurring; use UnzerSDK\Traits\CanDirectCharge; use UnzerSDK\Traits\CanPayout; +use UnzerSDK\Traits\CanRecur; class SepaDirectDebit extends BasePaymentType { use CanDirectCharge; use CanPayout; + use CanRecur; /** @var string $iban */ protected $iban; @@ -26,8 +27,14 @@ class SepaDirectDebit extends BasePaymentType /** @var string $holder */ protected $holder; - /** @var bool|null $recurring Mandate-based recurring flag, accepted on type registration. */ - protected ?bool $recurring = null; + /** + * Explicit request intent for the mandate-based recurring flag. CanRecur::$recurring is private and + * response-only (never serialized); this nullable shadow lets expose() emit `recurring` — including an + * explicit false — only once set, leaving a fresh instance's request body unchanged. + * + * @var bool|null + */ + private ?bool $recurringRequested = null; /** * @param string|null $iban @@ -95,11 +102,14 @@ public function setHolder(?string $holder): self } /** + * Overrides CanRecur::isRecurring() to read the request-time intent. Returns false for a fresh + * instance and reflects the value mapped from a fetched resource. + * * @return bool Whether the payment type is registered for recurring (mandate-based) collection. */ public function isRecurring(): bool { - return $this->recurring ?? false; + return $this->recurringRequested ?? false; } /** @@ -107,32 +117,34 @@ public function isRecurring(): bool * it is sent in the `POST /v1/types/sepa-direct-debit` request body. A fresh instance that never sets it * leaves the flag out of the request entirely. * + * Widens CanRecur::setRecurring() to public; the trait's own setter is protected. + * * @param bool $recurring * * @return $this */ public function setRecurring(bool $recurring): self { - $this->recurring = $recurring; + $this->recurringRequested = $recurring; return $this; } /** - * Activates recurring payment for the payment type. + * Appends the recurring flag — including an explicit false — once set, without turning the trait's + * private, response-only property into a serialized one. * - * @param string $returnUrl The URL to which the customer gets redirected in case of a 3ds transaction. - * @param null|mixed $recurrenceType Recurrence type used for recurring payment. - * - * @return Recurring - * - * @throws \UnzerSDK\Exceptions\UnzerApiException An UnzerApiException is thrown if there is an error returned - * on API-request. - * - * @deprecated since 1.3.0.0 Please set the recurrence type in your Charge/Authorize object using - * `setRecurrenceType` before performing the transaction request. + * {@inheritDoc} */ - public function activateRecurring($returnUrl, $recurrenceType = null): Recurring + public function expose() { - return $this->getUnzerObject()->activateRecurringPayment($this, $returnUrl, $recurrenceType); + $exposed = parent::expose(); + + if ($this->recurringRequested !== null) { + $exposed = (array) $exposed; + $exposed['recurring'] = $this->recurringRequested; + ksort($exposed); + } + + return $exposed; } } diff --git a/test/unit/Services/ResourceServiceTest.php b/test/unit/Services/ResourceServiceTest.php index fcc910b65..2a889a049 100755 --- a/test/unit/Services/ResourceServiceTest.php +++ b/test/unit/Services/ResourceServiceTest.php @@ -1335,6 +1335,28 @@ public function createRecurringShouldNotFetchThePaymentTypeByObject(): void $resourceSrvMock->activateRecurringPayment($paymentType, 'returnUrl', null); } + /** + * Verify activateRecurringPayment accepts a SepaDirectDebit, i.e. the type keeps the CanRecur trait the + * capability gate checks via class_uses(). Guards against removing the trait and silently breaking both + * $sdd->activateRecurring(...) and $unzer->activateRecurringPayment($sdd, ...). + * + * @test + */ + public function activateRecurringPaymentAcceptsSepaDirectDebit(): void + { + $paymentType = (new SepaDirectDebit('DE89370400440532013000'))->setId('myId'); + /** @var ResourceServiceInterface|MockObject $resourceSrvMock */ + $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->disableOriginalConstructor()->setMethods(['fetchPaymentType', 'createResource'])->getMock(); + $resourceSrvMock->expects(self::never())->method('fetchPaymentType'); + /** @noinspection PhpParamsInspection */ + $resourceSrvMock->expects(self::once())->method('createResource') + ->with($this::callback(static function ($data) { + return $data instanceof Recurring && $data->getReturnUrl() === 'returnUrl' && $data->getPaymentTypeId() === 'myId'; + })); + + $resourceSrvMock->activateRecurringPayment($paymentType, 'returnUrl', null); + } + /** * Verify createRecurring throws exception if it is called with a payment type which does not support recurring payment. * From 531f5747d25a2003768b2698c9cc115263d25db0 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Tue, 17 Nov 2026 10:08:17 +0100 Subject: [PATCH 08/13] [CC-4239] test: cover expose() recurring flag on an otherwise-empty SepaDirectDebit 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) --- .../PaymentTypes/SepaDirectDebitTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/unit/Resources/PaymentTypes/SepaDirectDebitTest.php b/test/unit/Resources/PaymentTypes/SepaDirectDebitTest.php index 28617eca0..09c905bb2 100755 --- a/test/unit/Resources/PaymentTypes/SepaDirectDebitTest.php +++ b/test/unit/Resources/PaymentTypes/SepaDirectDebitTest.php @@ -83,6 +83,22 @@ public function recurringIsExposedOnlyWhenSet(?bool $value, bool $shouldBeExpose } } + /** + * Verify the recurring flag is still exposed when the type is otherwise empty, i.e. the expose() + * override handles parent::expose() returning an empty stdClass rather than an array. + * + * @test + */ + public function recurringIsExposedWhenTypeIsOtherwiseEmpty(): void + { + $sdd = (new SepaDirectDebit(null))->setRecurring(true); + + $exposed = $sdd->expose(); + + $this->assertIsArray($exposed); + $this->assertSame(['recurring' => true], $exposed); + } + /** * Verify a response containing the recurring flag is mapped onto the resource. * From c424359b6c1053260fd21d93d9811f9ab0e7fb85 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Tue, 17 Nov 2026 10:46:18 +0100 Subject: [PATCH 09/13] [CC-4239] Simplify recurring: reuse CanRecur's property, always expose (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) --- .../PaymentTypes/SepaDirectDebit.php | 44 +++++-------------- .../PaymentTypes/SepaDirectDebitTest.php | 21 ++++----- 2 files changed, 19 insertions(+), 46 deletions(-) diff --git a/src/Resources/PaymentTypes/SepaDirectDebit.php b/src/Resources/PaymentTypes/SepaDirectDebit.php index ad772c51a..2cec23d26 100755 --- a/src/Resources/PaymentTypes/SepaDirectDebit.php +++ b/src/Resources/PaymentTypes/SepaDirectDebit.php @@ -27,15 +27,6 @@ class SepaDirectDebit extends BasePaymentType /** @var string $holder */ protected $holder; - /** - * Explicit request intent for the mandate-based recurring flag. CanRecur::$recurring is private and - * response-only (never serialized); this nullable shadow lets expose() emit `recurring` — including an - * explicit false — only once set, leaving a fresh instance's request body unchanged. - * - * @var bool|null - */ - private ?bool $recurringRequested = null; - /** * @param string|null $iban */ @@ -102,22 +93,11 @@ public function setHolder(?string $holder): self } /** - * Overrides CanRecur::isRecurring() to read the request-time intent. Returns false for a fresh - * instance and reflects the value mapped from a fetched resource. + * Registers the payment type for recurring (mandate-based) collection. Sent in the + * `POST /v1/types/sepa-direct-debit` request body; defaults to false and is always included. * - * @return bool Whether the payment type is registered for recurring (mandate-based) collection. - */ - public function isRecurring(): bool - { - return $this->recurringRequested ?? false; - } - - /** - * Registers the payment type for recurring (mandate-based) collection. Set this before creating the type; - * it is sent in the `POST /v1/types/sepa-direct-debit` request body. A fresh instance that never sets it - * leaves the flag out of the request entirely. - * - * Widens CanRecur::setRecurring() to public; the trait's own setter is protected. + * Widens CanRecur::setRecurring() to public (the trait's own setter is protected) and writes the + * trait's $recurring property so isRecurring() reflects it. * * @param bool $recurring * @@ -125,25 +105,21 @@ public function isRecurring(): bool */ public function setRecurring(bool $recurring): self { - $this->recurringRequested = $recurring; + $this->recurring = $recurring; return $this; } /** - * Appends the recurring flag — including an explicit false — once set, without turning the trait's - * private, response-only property into a serialized one. + * Always exposes the recurring flag (default false) so the SEPA direct debit type registration + * carries the mandate intent. * * {@inheritDoc} */ public function expose() { - $exposed = parent::expose(); - - if ($this->recurringRequested !== null) { - $exposed = (array) $exposed; - $exposed['recurring'] = $this->recurringRequested; - ksort($exposed); - } + $exposed = (array) parent::expose(); + $exposed['recurring'] = $this->recurring; + ksort($exposed); return $exposed; } diff --git a/test/unit/Resources/PaymentTypes/SepaDirectDebitTest.php b/test/unit/Resources/PaymentTypes/SepaDirectDebitTest.php index 09c905bb2..6bd5bf827 100755 --- a/test/unit/Resources/PaymentTypes/SepaDirectDebitTest.php +++ b/test/unit/Resources/PaymentTypes/SepaDirectDebitTest.php @@ -61,13 +61,13 @@ public function recurringSetterAndGetterWorkAsExpected(bool $value): void } /** - * Verify the recurring flag is only exposed once explicitly set. + * Verify the recurring flag is always exposed, defaulting to false when never set. * * @test * * @dataProvider exposeRecurringProvider */ - public function recurringIsExposedOnlyWhenSet(?bool $value, bool $shouldBeExposed): void + public function recurringIsAlwaysExposed(?bool $value, bool $expected): void { $sdd = new SepaDirectDebit('DE89370400440532013000'); if ($value !== null) { @@ -75,16 +75,13 @@ public function recurringIsExposedOnlyWhenSet(?bool $value, bool $shouldBeExpose } $exposed = $sdd->expose(); - if ($shouldBeExposed) { - $this->assertArrayHasKey('recurring', $exposed); - $this->assertSame($value, $exposed['recurring']); - } else { - $this->assertArrayNotHasKey('recurring', $exposed); - } + + $this->assertArrayHasKey('recurring', $exposed); + $this->assertSame($expected, $exposed['recurring']); } /** - * Verify the recurring flag is still exposed when the type is otherwise empty, i.e. the expose() + * Verify the recurring flag is exposed even when the type is otherwise empty, i.e. the expose() * override handles parent::expose() returning an empty stdClass rather than an array. * * @test @@ -134,9 +131,9 @@ public function recurringValueProvider(): array public function exposeRecurringProvider(): array { return [ - 'set to true' => [true, true], - 'set to false' => [false, true], - 'not set' => [null, false], + 'set to true' => [true, true], + 'set to false' => [false, false], + 'not set defaults false' => [null, false], ]; } } From ffc0a66c1c13dbda58a9d0868ec92b5984960522 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Tue, 17 Nov 2026 10:58:41 +0100 Subject: [PATCH 10/13] [CC-4239] Drop redundant setRecurring() override; widen trait method via use-adaptation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .../PaymentTypes/SepaDirectDebit.php | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/Resources/PaymentTypes/SepaDirectDebit.php b/src/Resources/PaymentTypes/SepaDirectDebit.php index 2cec23d26..4d156ccce 100755 --- a/src/Resources/PaymentTypes/SepaDirectDebit.php +++ b/src/Resources/PaymentTypes/SepaDirectDebit.php @@ -16,7 +16,10 @@ class SepaDirectDebit extends BasePaymentType { use CanDirectCharge; use CanPayout; - use CanRecur; + // Widen CanRecur::setRecurring() to public so it can be set before type registration. + use CanRecur { + setRecurring as public; + } /** @var string $iban */ protected $iban; @@ -92,23 +95,6 @@ public function setHolder(?string $holder): self return $this; } - /** - * Registers the payment type for recurring (mandate-based) collection. Sent in the - * `POST /v1/types/sepa-direct-debit` request body; defaults to false and is always included. - * - * Widens CanRecur::setRecurring() to public (the trait's own setter is protected) and writes the - * trait's $recurring property so isRecurring() reflects it. - * - * @param bool $recurring - * - * @return $this - */ - public function setRecurring(bool $recurring): self - { - $this->recurring = $recurring; - return $this; - } - /** * Always exposes the recurring flag (default false) so the SEPA direct debit type registration * carries the mandate intent. From 696dcc1d5a622eee7141ead24dd3dbcee974c555 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Tue, 17 Nov 2026 11:05:15 +0100 Subject: [PATCH 11/13] [CC-4239] Remove redundant comment restating the trait visibility adaptation Co-Authored-By: Claude Opus 4.8 (1M context) --- src/Resources/PaymentTypes/SepaDirectDebit.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Resources/PaymentTypes/SepaDirectDebit.php b/src/Resources/PaymentTypes/SepaDirectDebit.php index 4d156ccce..8686525a8 100755 --- a/src/Resources/PaymentTypes/SepaDirectDebit.php +++ b/src/Resources/PaymentTypes/SepaDirectDebit.php @@ -16,7 +16,6 @@ class SepaDirectDebit extends BasePaymentType { use CanDirectCharge; use CanPayout; - // Widen CanRecur::setRecurring() to public so it can be set before type registration. use CanRecur { setRecurring as public; } From a150a25581ff5db98c98dd6f3d5990ac227c447e Mon Sep 17 00:00:00 2001 From: David Owusu Date: Wed, 18 Nov 2026 11:57:07 +0100 Subject: [PATCH 12/13] [CC-4239] test: activate recurring directly on SepaDirectDebit type (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). --- .../PaymentTypes/SepaDirectDebitTest.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/integration/PaymentTypes/SepaDirectDebitTest.php b/test/integration/PaymentTypes/SepaDirectDebitTest.php index f1e2cad63..008657f0b 100755 --- a/test/integration/PaymentTypes/SepaDirectDebitTest.php +++ b/test/integration/PaymentTypes/SepaDirectDebitTest.php @@ -78,6 +78,26 @@ public function sepaDirectDebitShouldBeCreatableWithRecurringFlag(): void $this->assertTrue($fetchedDirectDebit->isRecurring()); } + /** + * Verify recurring can be activated directly on the sepa direct debit type via activateRecurring(). + * Guards that keeping the CanRecur trait on the type leaves the (deprecated) activation flow working. + * + * @test + */ + public function sepaDirectDebitShouldActivateRecurringViaType(): void + { + /** @var SepaDirectDebit $sdd */ + $sdd = $this->unzer->createPaymentType(new SepaDirectDebit('DE89370400440532013000')); + $this->assertFalse($sdd->isRecurring()); + + $recurring = $sdd->activateRecurring(self::RETURN_URL); + $this->assertSuccess($recurring); + + /** @var SepaDirectDebit $fetchedDirectDebit */ + $fetchedDirectDebit = $this->unzer->fetchPaymentType($sdd->getId()); + $this->assertTrue($fetchedDirectDebit->isRecurring()); + } + /** * Verify authorization is not allowed for sepa direct debit. * From aaa157e0a30c158732d53814ae11aa9997a83096 Mon Sep 17 00:00:00 2001 From: David Owusu Date: Wed, 18 Nov 2026 12:03:13 +0100 Subject: [PATCH 13/13] [CC-4239] test: assert SEPA activateRecurring reaches PAPI and is rejected 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. --- .../PaymentTypes/SepaDirectDebitTest.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/test/integration/PaymentTypes/SepaDirectDebitTest.php b/test/integration/PaymentTypes/SepaDirectDebitTest.php index 008657f0b..6da35a576 100755 --- a/test/integration/PaymentTypes/SepaDirectDebitTest.php +++ b/test/integration/PaymentTypes/SepaDirectDebitTest.php @@ -79,8 +79,12 @@ public function sepaDirectDebitShouldBeCreatableWithRecurringFlag(): void } /** - * Verify recurring can be activated directly on the sepa direct debit type via activateRecurring(). - * Guards that keeping the CanRecur trait on the type leaves the (deprecated) activation flow working. + * Verify the (deprecated) recurring activation still routes a SepaDirectDebit through to PAPI. + * + * Keeping the `CanRecur` trait on the type means `activateRecurring()` passes the ResourceService + * capability gate and reaches the API instead of failing client-side. For SEPA the mandate is + * registered during a charge/authorize, so PAPI rejects a direct recurring call — asserting that + * specific API error confirms the activation flow is still wired correctly for the type. * * @test */ @@ -90,12 +94,10 @@ public function sepaDirectDebitShouldActivateRecurringViaType(): void $sdd = $this->unzer->createPaymentType(new SepaDirectDebit('DE89370400440532013000')); $this->assertFalse($sdd->isRecurring()); - $recurring = $sdd->activateRecurring(self::RETURN_URL); - $this->assertSuccess($recurring); - - /** @var SepaDirectDebit $fetchedDirectDebit */ - $fetchedDirectDebit = $this->unzer->fetchPaymentType($sdd->getId()); - $this->assertTrue($fetchedDirectDebit->isRecurring()); + // SEPA activates the mandate via charge/authorize, so a direct recurring call is rejected by PAPI. + $this->expectException(UnzerApiException::class); + $this->expectExceptionCode('API.640.550.005'); + $sdd->activateRecurring(self::RETURN_URL); } /**