From 5196fffd8c3a651f75686fd815a0baad5b5df305 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Wed, 25 Nov 2026 10:39:00 +0100 Subject: [PATCH 01/10] [CC-4346] Make paylater plan model nullable so all params are gettable 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) --- CHANGELOG.md | 4 +- .../Paylater/InstallmentPlan.php | 92 ++++++++++----- src/Resources/PaylaterPlans.php | 14 +-- .../paylaterDirectDebitPlansResponse.json | 23 ++++ .../paylaterInvoicePlansResponse.json | 23 ++++ .../jsonData/paylaterPlansResponse.json | 1 + .../PaymentTypes/PaylaterPlansTest.php | 41 ++++++- test/unit/Resources/PaylaterPlansTest.php | 109 +++++++++++++++++- 8 files changed, 261 insertions(+), 46 deletions(-) create mode 100644 test/Fixtures/jsonData/paylaterDirectDebitPlansResponse.json create mode 100644 test/Fixtures/jsonData/paylaterInvoicePlansResponse.json diff --git a/CHANGELOG.md b/CHANGELOG.md index eafaa934..13298605 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). * `Unzer::fetchPaylaterPlans(BasePaymentType $paymentType, PaylaterPlansQuery $query)` to fetch the available plans (including the `secciUrl`) for any paylater payment type, e.g. `new PaylaterInvoice()` or `new PaylaterDirectDebit()`. The SECCI PDF locale follows the client locale set via `Unzer::setLocale()` (`Accept-Language` header). The payment type and query values are passed through to the API unchanged; invalid input is rejected by the API with an `UnzerApiException`. * `\UnzerSDK\Resources\PaylaterPlans` and `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery` as the generalized plan result/query models. * `minimumInstallmentFee` is now exposed on `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan` via `getMinimumInstallmentFee()` (previously present in the API response but dropped by the SDK). +* `interestAmount` is now exposed on `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan` via `getInterestAmount()` (previously present in the API response but dropped by the SDK). ### Deprecated @@ -29,8 +30,7 @@ to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). * `\UnzerSDK\Resources\Keypair`: boolean flags (`validateBasket`, `cof`) that the API sends as the strings `"true"`/`"false"` were coerced so `"false"` evaluated to `true`. They are now parsed correctly, so `isValidateBasket()` and `expose()` reflect the real value; a missing field stays `null`. * `\UnzerSDK\Resources\Keypair`: a plain `fetchKeypair()` listed every payment type twice in `getPaymentTypes()` / `getAvailablePaymentTypes()`; the list is now de-duplicated (detailed keypair unchanged). - -## [4.0.2](https://github.com/unzerdev/php-sdk/compare/4.0.1..4.0.2) +* `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan`: the plan getters are now nullable (`getSecciUrl(): ?string`, `getEffectiveInterestRate(): ?float`, `getNominalInterestRate(): ?float`, `getNumberOfRates(): ?int`, `getTotalAmount(): ?string`, `getMinimumInstallmentFee(): ?string`). Fetching Paylater Invoice and Direct Debit plans — which omit the interest-rate fields — no longer throws a `TypeError`, and a null field in any plan response (`\UnzerSDK\Resources\PaylaterPlans` included) is tolerated instead of crashing the fetch. ### Changed diff --git a/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php b/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php index 810ee52a..b81a3a7f 100644 --- a/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php +++ b/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php @@ -7,140 +7,170 @@ use stdClass; /** - * Resource representing the installment plan for Paylater Installment. + * Resource representing a single plan item returned by the generalized paylater /plans endpoint. + * + * The same PAPI schema backs all three paylater types (installment, invoice, direct debit), but each + * type only populates a subset of the optional fields: invoice and direct debit omit the interest-rate + * fields and send rates without a date, while installment carries the full set. Every getter is therefore + * nullable so a field a given type does not return reads back as null instead of throwing. * * @link https://docs.unzer.com/ * */ class InstallmentPlan extends AbstractUnzerResource { - /** @var int $numberOfRates */ + /** @var int|null $numberOfRates */ private $numberOfRates; + /** @var string|null $totalAmount */ private $totalAmount; + /** @var string|null $interestAmount */ + private $interestAmount; + + /** @var string|null $minimumInstallmentFee */ private $minimumInstallmentFee; + /** @var float|null $nominalInterestRate */ private $nominalInterestRate; - /** @var float $effectiveInterestRate */ + /** @var float|null $effectiveInterestRate */ private $effectiveInterestRate; - /** @var string $secciUrl */ + /** @var string|null $secciUrl */ private $secciUrl; - /** @var InstallmentRate */ + /** @var InstallmentRate[]|null $installmentRates */ private $installmentRates; /** - * @return string + * @return string|null */ - public function getSecciUrl(): string + public function getSecciUrl(): ?string { return $this->secciUrl; } /** - * @param string $secciUrl + * @param string|null $secciUrl * * @return InstallmentPlan */ - public function setSecciUrl(string $secciUrl): InstallmentPlan + public function setSecciUrl(?string $secciUrl): InstallmentPlan { $this->secciUrl = $secciUrl; return $this; } /** - * @return int + * @return int|null */ - public function getNumberOfRates(): int + public function getNumberOfRates(): ?int { return $this->numberOfRates; } /** - * @param int $numberOfRates + * @param int|null $numberOfRates * * @return InstallmentPlan */ - public function setNumberOfRates(int $numberOfRates): InstallmentPlan + public function setNumberOfRates(?int $numberOfRates): InstallmentPlan { $this->numberOfRates = $numberOfRates; return $this; } /** - * @return mixed + * @return string|null */ - public function getTotalAmount() + public function getTotalAmount(): ?string { return $this->totalAmount; } /** - * @param mixed $totalAmount + * @param string|null $totalAmount * * @return InstallmentPlan */ - public function setTotalAmount($totalAmount) + public function setTotalAmount(?string $totalAmount): InstallmentPlan { $this->totalAmount = $totalAmount; return $this; } /** - * @return mixed + * @return string|null + */ + public function getInterestAmount(): ?string + { + return $this->interestAmount; + } + + /** + * @param string|null $interestAmount + * + * @return InstallmentPlan + */ + public function setInterestAmount(?string $interestAmount): InstallmentPlan + { + $this->interestAmount = $interestAmount; + return $this; + } + + /** + * @return string|null */ - public function getMinimumInstallmentFee() + public function getMinimumInstallmentFee(): ?string { return $this->minimumInstallmentFee; } /** - * @param mixed $minimumInstallmentFee + * @param string|null $minimumInstallmentFee * * @return InstallmentPlan */ - public function setMinimumInstallmentFee($minimumInstallmentFee) + public function setMinimumInstallmentFee(?string $minimumInstallmentFee): InstallmentPlan { $this->minimumInstallmentFee = $minimumInstallmentFee; return $this; } /** - * @return mixed + * @return float|null */ - public function getNominalInterestRate() + public function getNominalInterestRate(): ?float { return $this->nominalInterestRate; } /** - * @param mixed $nominalInterestRate + * @param float|null $nominalInterestRate * * @return InstallmentPlan */ - public function setNominalInterestRate($nominalInterestRate) + public function setNominalInterestRate(?float $nominalInterestRate): InstallmentPlan { $this->nominalInterestRate = $nominalInterestRate; return $this; } /** - * @return float + * @return float|null */ - public function getEffectiveInterestRate(): float + public function getEffectiveInterestRate(): ?float { return $this->effectiveInterestRate; } /** - * @param float $effectiveInterestRate + * @param float|null $effectiveInterestRate * * @return InstallmentPlan */ - public function setEffectiveInterestRate(float $effectiveInterestRate): InstallmentPlan + public function setEffectiveInterestRate(?float $effectiveInterestRate): InstallmentPlan { $this->effectiveInterestRate = $effectiveInterestRate; return $this; @@ -155,11 +185,11 @@ public function getInstallmentRates(): ?array } /** - * @param InstallmentRate[] $installmentRates + * @param InstallmentRate[]|null $installmentRates * * @return InstallmentPlan */ - protected function setInstallmentRates(array $installmentRates): InstallmentPlan + protected function setInstallmentRates(?array $installmentRates): InstallmentPlan { $this->installmentRates = $installmentRates; return $this; diff --git a/src/Resources/PaylaterPlans.php b/src/Resources/PaylaterPlans.php index 927937b7..4d446b9c 100644 --- a/src/Resources/PaylaterPlans.php +++ b/src/Resources/PaylaterPlans.php @@ -47,11 +47,11 @@ public function getAmount(): ?float } /** - * @param float $amount + * @param float|null $amount * * @return PaylaterPlans */ - public function setAmount(float $amount): PaylaterPlans + public function setAmount(?float $amount): PaylaterPlans { $this->amount = $amount; return $this; @@ -66,11 +66,11 @@ public function getCurrency(): ?string } /** - * @param string $currency + * @param string|null $currency * * @return PaylaterPlans */ - public function setCurrency(string $currency): PaylaterPlans + public function setCurrency(?string $currency): PaylaterPlans { $this->currency = $currency; return $this; @@ -123,13 +123,13 @@ public function getPlans(): array } /** - * @param stdClass[] $plans + * @param stdClass[]|null $plans * * @return PaylaterPlans */ - protected function setPlans(array $plans): PaylaterPlans + protected function setPlans(?array $plans): PaylaterPlans { - $this->plans = $plans; + $this->plans = $plans ?? []; return $this; } diff --git a/test/Fixtures/jsonData/paylaterDirectDebitPlansResponse.json b/test/Fixtures/jsonData/paylaterDirectDebitPlansResponse.json new file mode 100644 index 00000000..4be80434 --- /dev/null +++ b/test/Fixtures/jsonData/paylaterDirectDebitPlansResponse.json @@ -0,0 +1,23 @@ +{ + "id": "Tg-elv-xyz", + "amount": "100.00", + "currency": "EUR", + "plans": [ + { + "numberOfRates": 1, + "totalAmount": "100.00", + "interestAmount": "0.00", + "minimumInstallmentFee": "0.00", + "secciUrl": "https://test-payment.paylater.unzer.com/payolution-payment/infoport/creditagreementdraft/Tg-elv-xyz?channelId=auto-elv&amount=100.00", + "installmentRates": [ + { + "rate": "100.00" + } + ] + } + ], + "isSuccess": true, + "isPending": false, + "isResumed": false, + "isError": false +} diff --git a/test/Fixtures/jsonData/paylaterInvoicePlansResponse.json b/test/Fixtures/jsonData/paylaterInvoicePlansResponse.json new file mode 100644 index 00000000..2ceae19e --- /dev/null +++ b/test/Fixtures/jsonData/paylaterInvoicePlansResponse.json @@ -0,0 +1,23 @@ +{ + "id": "Tg-invoice-xyz", + "amount": "100.00", + "currency": "EUR", + "plans": [ + { + "numberOfRates": 1, + "totalAmount": "100.00", + "interestAmount": "0.00", + "minimumInstallmentFee": "0.00", + "secciUrl": "https://test-payment.paylater.unzer.com/payolution-payment/infoport/creditagreementdraft/Tg-invoice-xyz?channelId=auto-invoice&amount=100.00", + "installmentRates": [ + { + "rate": "100.00" + } + ] + } + ], + "isSuccess": true, + "isPending": false, + "isResumed": false, + "isError": false +} diff --git a/test/Fixtures/jsonData/paylaterPlansResponse.json b/test/Fixtures/jsonData/paylaterPlansResponse.json index d586eefd..22942ea4 100644 --- a/test/Fixtures/jsonData/paylaterPlansResponse.json +++ b/test/Fixtures/jsonData/paylaterPlansResponse.json @@ -6,6 +6,7 @@ { "numberOfRates": 3, "totalAmount": "101.31", + "interestAmount": "1.31", "nominalInterestRate": 9.95, "effectiveInterestRate": 10.43, "minimumInstallmentFee": "2.50", diff --git a/test/integration/PaymentTypes/PaylaterPlansTest.php b/test/integration/PaymentTypes/PaylaterPlansTest.php index ea9b9d25..375f9688 100644 --- a/test/integration/PaymentTypes/PaylaterPlansTest.php +++ b/test/integration/PaymentTypes/PaylaterPlansTest.php @@ -19,25 +19,31 @@ use UnzerSDK\Constants\CustomerTypes; use UnzerSDK\Exceptions\UnzerApiException; +use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan; use UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery; use UnzerSDK\Resources\PaymentTypes\BasePaymentType; use UnzerSDK\Resources\PaymentTypes\PaylaterDirectDebit; +use UnzerSDK\Resources\PaymentTypes\PaylaterInstallment; use UnzerSDK\Resources\PaymentTypes\PaylaterInvoice; use UnzerSDK\Resources\PaymentTypes\SepaDirectDebit; use UnzerSDK\test\BaseIntegrationTest; use function count; +use function is_array; +use function is_float; class PaylaterPlansTest extends BaseIntegrationTest { /** - * Verify real plans can be fetched for Paylater Invoice and Direct Debit, exposing a secciUrl. + * Verify real plans can be fetched via the generalized endpoint for all three supported paylater + * types, and that every plan parameter is gettable from the response (null for the optional fields + * a given type does not send) rather than throwing. * * @test * * @dataProvider supportedPaylaterTypeDataProvider */ - public function plansAreFetchableWithSecciUrl(BasePaymentType $paymentType): void + public function plansAreFetchableWithAllParametersGettable(BasePaymentType $paymentType): void { $query = new PaylaterPlansQuery(99.99, 'EUR', 'DE', CustomerTypes::B2C); $plans = $this->unzer->fetchPaylaterPlans($paymentType, $query); @@ -46,6 +52,7 @@ public function plansAreFetchableWithSecciUrl(BasePaymentType $paymentType): voi $this->assertGreaterThan(0, count($plans->getPlans())); foreach ($plans->getPlans() as $plan) { $this->assertNotEmpty($plan->getSecciUrl()); + $this->assertAllPlanParametersGettable($plan); } } @@ -89,11 +96,41 @@ public function invalidInputThrowsUnzerApiException(float $amount, string $curre } } + // + + /** + * Asserts every plan parameter is gettable from the live response: the fields all three types send + * are present, and the installment-only interest rates read back as float or null without throwing. + */ + private function assertAllPlanParametersGettable(InstallmentPlan $plan): void + { + $this->assertIsInt($plan->getNumberOfRates()); + $this->assertIsString($plan->getTotalAmount()); + $this->assertIsString($plan->getInterestAmount()); + $this->assertIsString($plan->getMinimumInstallmentFee()); + $this->assertNotEmpty($plan->getSecciUrl()); + + $nominal = $plan->getNominalInterestRate(); + $this->assertTrue($nominal === null || is_float($nominal)); + $effective = $plan->getEffectiveInterestRate(); + $this->assertTrue($effective === null || is_float($effective)); + + $rates = $plan->getInstallmentRates(); + $this->assertTrue($rates === null || is_array($rates)); + foreach ($rates ?? [] as $rate) { + $this->assertNotNull($rate->getRate()); + $this->assertTrue($rate->getDate() === null || is_string($rate->getDate())); + } + } + + // + // public function supportedPaylaterTypeDataProvider(): array { return [ + 'installment' => [new PaylaterInstallment()], 'invoice' => [new PaylaterInvoice()], 'directDebit' => [new PaylaterDirectDebit('DE89370400440532013000', 'Peter Mustermann')], ]; diff --git a/test/unit/Resources/PaylaterPlansTest.php b/test/unit/Resources/PaylaterPlansTest.php index 5748ed12..1eab0365 100644 --- a/test/unit/Resources/PaylaterPlansTest.php +++ b/test/unit/Resources/PaylaterPlansTest.php @@ -163,8 +163,106 @@ public function installmentRateWithoutDateMapsWithoutWarning(): void $this->assertEquals('0.00', $rate->getRate()); } + /** + * Every plan parameter is gettable (never throws) for each supported paylater type, returning the + * mapped value or null for the optional fields a given type does not send. + * + * @test + * + * @dataProvider responseFixtureDataProvider + */ + public function allPlanParametersAreGettableForEachType(string $fixture): void + { + $plans = new PaylaterPlans(); + $plans->handleResponse(json_decode(JsonProvider::getJsonFromFile($fixture))); + + $this->assertNotEmpty($plans->getPlans()); + foreach ($plans->getPlans() as $plan) { + $this->assertAllPlanParametersGettable($plan); + } + } + + /** + * A response where optional fields arrive as null is mapped without a TypeError (same pattern as + * CC-4255/CC-4256); the affected getters return null and the fetch succeeds. + * + * @test + */ + public function nullPlanAndEnvelopeFieldsMapWithoutError(): void + { + $response = json_decode(json_encode([ + 'id' => 'Tx-null', + 'amount' => null, + 'currency' => 'EUR', + 'plans' => [[ + 'numberOfRates' => 1, + 'totalAmount' => '100.00', + 'interestAmount' => null, + 'minimumInstallmentFee' => null, + 'nominalInterestRate' => null, + 'effectiveInterestRate' => null, + 'secciUrl' => null, + 'installmentRates' => null, + ]], + ])); + + $plans = new PaylaterPlans(); + $plans->handleResponse($response); + + $this->assertNull($plans->getAmount()); + $plan = $plans->getPlans()[0]; + $this->assertSame(1, $plan->getNumberOfRates()); + $this->assertNull($plan->getSecciUrl()); + $this->assertNull($plan->getInterestAmount()); + $this->assertNull($plan->getMinimumInstallmentFee()); + $this->assertNull($plan->getNominalInterestRate()); + $this->assertNull($plan->getEffectiveInterestRate()); + $this->assertNull($plan->getInstallmentRates()); + } + + /** + * A null plans array in the response maps to an empty list instead of throwing. + * + * @test + */ + public function nullPlansArrayMapsToEmptyList(): void + { + $response = json_decode(json_encode(['id' => 'Tx-null-plans', 'currency' => 'EUR', 'plans' => null])); + + $plans = new PaylaterPlans(); + $plans->handleResponse($response); + + $this->assertIsArray($plans->getPlans()); + $this->assertEmpty($plans->getPlans()); + } + // + /** + * Asserts every getter of a plan item is callable and returns the expected nullable type. + */ + private function assertAllPlanParametersGettable(InstallmentPlan $plan): void + { + $this->assertIsInt($plan->getNumberOfRates()); + $this->assertIsString($plan->getTotalAmount()); + $this->assertIsString($plan->getMinimumInstallmentFee()); + $this->assertNotEmpty($plan->getSecciUrl()); + + $interestAmount = $plan->getInterestAmount(); + $this->assertTrue($interestAmount === null || is_string($interestAmount)); + $nominal = $plan->getNominalInterestRate(); + $this->assertTrue($nominal === null || is_float($nominal)); + $effective = $plan->getEffectiveInterestRate(); + $this->assertTrue($effective === null || is_float($effective)); + + $rates = $plan->getInstallmentRates(); + $this->assertTrue($rates === null || is_array($rates)); + foreach ($rates ?? [] as $rate) { + $this->assertNotNull($rate->getRate()); + $this->assertTrue($rate->getDate() === null || is_string($rate->getDate())); + } + } + /** * @param object[] $expected * @param InstallmentPlan[] $actual @@ -172,7 +270,9 @@ public function installmentRateWithoutDateMapsWithoutWarning(): void private function comparePlans(array $expected, array $actual): void { foreach ($expected as $index => $plan) { + $this->assertEquals($plan->numberOfRates ?? null, $actual[$index]->getNumberOfRates()); $this->assertEquals($plan->totalAmount ?? null, $actual[$index]->getTotalAmount()); + $this->assertEquals($plan->interestAmount ?? null, $actual[$index]->getInterestAmount()); $this->assertEquals($plan->minimumInstallmentFee ?? null, $actual[$index]->getMinimumInstallmentFee()); $this->assertEquals($plan->nominalInterestRate ?? null, $actual[$index]->getNominalInterestRate()); $this->assertEquals($plan->effectiveInterestRate ?? null, $actual[$index]->getEffectiveInterestRate()); @@ -189,8 +289,8 @@ private function comparePlans(array $expected, array $actual): void private function compareRates(array $expected, array $actual): void { foreach ($expected as $index => $rate) { - $this->assertEquals($rate->date, $actual[$index]->getDate()); - $this->assertEquals($rate->rate, $actual[$index]->getRate()); + $this->assertEquals($rate->date ?? null, $actual[$index]->getDate()); + $this->assertEquals($rate->rate ?? null, $actual[$index]->getRate()); } } @@ -210,8 +310,9 @@ public function queryStringDataProvider(): array public function responseFixtureDataProvider(): array { return [ - 'invoice' => ['paylaterPlansResponse.json'], - 'directDebit' => ['paylaterPlansResponseNoRates.json'], + 'installment' => ['paylaterPlansResponse.json'], + 'invoice' => ['paylaterInvoicePlansResponse.json'], + 'directDebit' => ['paylaterDirectDebitPlansResponse.json'], ]; } From e00e631687bf34dafe84bd8343c213f725569305 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Wed, 25 Nov 2026 10:53:58 +0100 Subject: [PATCH 02/10] [CC-4346] Pin numberOfRates and interestAmount on the legacy installment 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) --- test/unit/Resources/PaylaterInstallmentPlansTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/unit/Resources/PaylaterInstallmentPlansTest.php b/test/unit/Resources/PaylaterInstallmentPlansTest.php index 634dfd5e..e429206b 100644 --- a/test/unit/Resources/PaylaterInstallmentPlansTest.php +++ b/test/unit/Resources/PaylaterInstallmentPlansTest.php @@ -152,7 +152,9 @@ protected function comparePlans(array $expected, array $actual): void $this->assertCount(count($expected), $actual); foreach ($expected as $index => $plan) { + $this->assertEquals($plan->numberOfRates ?? null, $actual[$index]->getNumberOfRates()); $this->assertEquals($plan->totalAmount ?? null, $actual[$index]->getTotalAmount()); + $this->assertEquals($plan->interestAmount ?? null, $actual[$index]->getInterestAmount()); $this->assertEquals($plan->minimumInstallmentFee ?? null, $actual[$index]->getMinimumInstallmentFee()); $this->assertEquals($plan->nominalInterestRate ?? null, $actual[$index]->getNominalInterestRate()); $this->assertEquals($plan->effectiveInterestRate ?? null, $actual[$index]->getEffectiveInterestRate()); From 8e32df189cccf544c15b20e409f6d56deaf39927 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Wed, 25 Nov 2026 13:29:57 +0100 Subject: [PATCH 03/10] [CC-4346] Introduce PaylaterPlan item; deprecate InstallmentPlan as a 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) --- CHANGELOG.md | 8 +- .../Paylater/InstallmentPlan.php | 210 +---------------- .../Paylater/PaylaterPlan.php | 213 ++++++++++++++++++ src/Resources/PaylaterPlans.php | 12 +- .../PaymentTypes/PaylaterPlansTest.php | 4 +- .../PaylaterInstallmentPlansTest.php | 19 ++ test/unit/Resources/PaylaterPlansTest.php | 7 +- 7 files changed, 257 insertions(+), 216 deletions(-) create mode 100644 src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 13298605..ce3c77bc 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,14 +13,16 @@ to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). * `getRawResponse()` on `\UnzerSDK\Resources\Keypair`, exposing the exact raw API response string from a Keypair fetch. * `Unzer::fetchPaylaterPlans(BasePaymentType $paymentType, PaylaterPlansQuery $query)` to fetch the available plans (including the `secciUrl`) for any paylater payment type, e.g. `new PaylaterInvoice()` or `new PaylaterDirectDebit()`. The SECCI PDF locale follows the client locale set via `Unzer::setLocale()` (`Accept-Language` header). The payment type and query values are passed through to the API unchanged; invalid input is rejected by the API with an `UnzerApiException`. * `\UnzerSDK\Resources\PaylaterPlans` and `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery` as the generalized plan result/query models. -* `minimumInstallmentFee` is now exposed on `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan` via `getMinimumInstallmentFee()` (previously present in the API response but dropped by the SDK). -* `interestAmount` is now exposed on `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan` via `getInterestAmount()` (previously present in the API response but dropped by the SDK). +* `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan` as the generalized plan-item model returned by `PaylaterPlans::getPlans()`. It replaces the installment-specific `InstallmentPlan` name (see _Deprecated_); adopting the new `fetchPaylaterPlans()` flow should type-hint `PaylaterPlan`. +* `minimumInstallmentFee` is now exposed on `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan` via `getMinimumInstallmentFee()` (previously present in the API response but dropped by the SDK). +* `interestAmount` is now exposed on `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan` via `getInterestAmount()` (previously present in the API response but dropped by the SDK). ### Deprecated * `\UnzerSDK\Resources\PaymentTypes\PIS` (Unzer Bank Transfer / FlexiPay Direct) payment type. It is no longer supported and will be removed in a future major version. * `\UnzerSDK\Resources\PaymentTypes\Sofort` payment type. It is no longer supported and will be removed in a future major version. * `\UnzerSDK\Resources\PaylaterInstallmentPlans` (use `\UnzerSDK\Resources\PaylaterPlans`) and `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery` (use `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery`). The legacy classes are left unchanged as standalone deprecated aliases with their original public signatures (no inheritance from the new generalized classes), so existing code keeps working. `Unzer::fetchPaylaterInstallmentPlans()` is unchanged. +* `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan` (use `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan`). It is now a subclass of `PaylaterPlan` kept for backward compatibility: the deprecated `Unzer::fetchPaylaterInstallmentPlans()` flow still returns `InstallmentPlan` items and existing `InstallmentPlan` type hints keep working (an `InstallmentPlan` is-a `PaylaterPlan`). It will be removed in a future major version. ### Removed @@ -30,7 +32,7 @@ to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). * `\UnzerSDK\Resources\Keypair`: boolean flags (`validateBasket`, `cof`) that the API sends as the strings `"true"`/`"false"` were coerced so `"false"` evaluated to `true`. They are now parsed correctly, so `isValidateBasket()` and `expose()` reflect the real value; a missing field stays `null`. * `\UnzerSDK\Resources\Keypair`: a plain `fetchKeypair()` listed every payment type twice in `getPaymentTypes()` / `getAvailablePaymentTypes()`; the list is now de-duplicated (detailed keypair unchanged). -* `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan`: the plan getters are now nullable (`getSecciUrl(): ?string`, `getEffectiveInterestRate(): ?float`, `getNominalInterestRate(): ?float`, `getNumberOfRates(): ?int`, `getTotalAmount(): ?string`, `getMinimumInstallmentFee(): ?string`). Fetching Paylater Invoice and Direct Debit plans — which omit the interest-rate fields — no longer throws a `TypeError`, and a null field in any plan response (`\UnzerSDK\Resources\PaylaterPlans` included) is tolerated instead of crashing the fetch. +* `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan` (and therefore its deprecated subclass `InstallmentPlan`): the plan getters are now nullable (`getSecciUrl(): ?string`, `getEffectiveInterestRate(): ?float`, `getNominalInterestRate(): ?float`, `getNumberOfRates(): ?int`, `getTotalAmount(): ?string`, `getMinimumInstallmentFee(): ?string`). Fetching Paylater Invoice and Direct Debit plans — which omit the interest-rate fields — no longer throws a `TypeError`, and a null field in any plan response (`\UnzerSDK\Resources\PaylaterPlans` included) is tolerated instead of crashing the fetch. ### Changed diff --git a/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php b/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php index b81a3a7f..8508588d 100644 --- a/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php +++ b/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php @@ -2,212 +2,18 @@ namespace UnzerSDK\Resources\EmbeddedResources\Paylater; -use UnzerSDK\Adapter\HttpAdapterInterface; -use UnzerSDK\Resources\AbstractUnzerResource; -use stdClass; - /** - * Resource representing a single plan item returned by the generalized paylater /plans endpoint. + * Resource representing a single plan item of the legacy installment plans flow. * - * The same PAPI schema backs all three paylater types (installment, invoice, direct debit), but each - * type only populates a subset of the optional fields: invoice and direct debit omit the interest-rate - * fields and send rates without a date, while installment carries the full set. Every getter is therefore - * nullable so a field a given type does not return reads back as null instead of throwing. + * @deprecated since the plan item was generalized across all paylater types. Use {@see PaylaterPlan} + * instead; it is the item type returned by the generalized `Unzer::fetchPaylaterPlans()` + * flow. This class is kept as an unchanged subclass so the deprecated + * `Unzer::fetchPaylaterInstallmentPlans()` flow and existing type hints keep working + * (an InstallmentPlan is-a PaylaterPlan). It will be removed in a future major version. * - * @link https://docs.unzer.com/ + * @link https://docs.unzer.com/ * */ -class InstallmentPlan extends AbstractUnzerResource +class InstallmentPlan extends PaylaterPlan { - /** @var int|null $numberOfRates */ - private $numberOfRates; - - /** @var string|null $totalAmount */ - private $totalAmount; - - /** @var string|null $interestAmount */ - private $interestAmount; - - /** @var string|null $minimumInstallmentFee */ - private $minimumInstallmentFee; - - /** @var float|null $nominalInterestRate */ - private $nominalInterestRate; - - /** @var float|null $effectiveInterestRate */ - private $effectiveInterestRate; - - /** @var string|null $secciUrl */ - private $secciUrl; - - /** @var InstallmentRate[]|null $installmentRates */ - private $installmentRates; - - /** - * @return string|null - */ - public function getSecciUrl(): ?string - { - return $this->secciUrl; - } - - /** - * @param string|null $secciUrl - * - * @return InstallmentPlan - */ - public function setSecciUrl(?string $secciUrl): InstallmentPlan - { - $this->secciUrl = $secciUrl; - return $this; - } - - /** - * @return int|null - */ - public function getNumberOfRates(): ?int - { - return $this->numberOfRates; - } - - /** - * @param int|null $numberOfRates - * - * @return InstallmentPlan - */ - public function setNumberOfRates(?int $numberOfRates): InstallmentPlan - { - $this->numberOfRates = $numberOfRates; - return $this; - } - - /** - * @return string|null - */ - public function getTotalAmount(): ?string - { - return $this->totalAmount; - } - - /** - * @param string|null $totalAmount - * - * @return InstallmentPlan - */ - public function setTotalAmount(?string $totalAmount): InstallmentPlan - { - $this->totalAmount = $totalAmount; - return $this; - } - - /** - * @return string|null - */ - public function getInterestAmount(): ?string - { - return $this->interestAmount; - } - - /** - * @param string|null $interestAmount - * - * @return InstallmentPlan - */ - public function setInterestAmount(?string $interestAmount): InstallmentPlan - { - $this->interestAmount = $interestAmount; - return $this; - } - - /** - * @return string|null - */ - public function getMinimumInstallmentFee(): ?string - { - return $this->minimumInstallmentFee; - } - - /** - * @param string|null $minimumInstallmentFee - * - * @return InstallmentPlan - */ - public function setMinimumInstallmentFee(?string $minimumInstallmentFee): InstallmentPlan - { - $this->minimumInstallmentFee = $minimumInstallmentFee; - return $this; - } - - /** - * @return float|null - */ - public function getNominalInterestRate(): ?float - { - return $this->nominalInterestRate; - } - - /** - * @param float|null $nominalInterestRate - * - * @return InstallmentPlan - */ - public function setNominalInterestRate(?float $nominalInterestRate): InstallmentPlan - { - $this->nominalInterestRate = $nominalInterestRate; - return $this; - } - - /** - * @return float|null - */ - public function getEffectiveInterestRate(): ?float - { - return $this->effectiveInterestRate; - } - - /** - * @param float|null $effectiveInterestRate - * - * @return InstallmentPlan - */ - public function setEffectiveInterestRate(?float $effectiveInterestRate): InstallmentPlan - { - $this->effectiveInterestRate = $effectiveInterestRate; - return $this; - } - - /** - * @return InstallmentRate[]|null - */ - public function getInstallmentRates(): ?array - { - return $this->installmentRates; - } - - /** - * @param InstallmentRate[]|null $installmentRates - * - * @return InstallmentPlan - */ - protected function setInstallmentRates(?array $installmentRates): InstallmentPlan - { - $this->installmentRates = $installmentRates; - return $this; - } - - /** - * {@inheritDoc} - */ - public function handleResponse(stdClass $response, string $method = HttpAdapterInterface::REQUEST_GET): void - { - parent::handleResponse($response, $method); - - if (isset($response->installmentRates)) { - $rates = []; - foreach ($response->installmentRates as $rate) { - $rates[] = new InstallmentRate($rate->date ?? null, $rate->rate ?? null); - } - $this->setInstallmentRates($rates); - } - } } diff --git a/src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php b/src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php new file mode 100644 index 00000000..6ca67fe9 --- /dev/null +++ b/src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php @@ -0,0 +1,213 @@ +secciUrl; + } + + /** + * @param string|null $secciUrl + * + * @return static + */ + public function setSecciUrl(?string $secciUrl): static + { + $this->secciUrl = $secciUrl; + return $this; + } + + /** + * @return int|null + */ + public function getNumberOfRates(): ?int + { + return $this->numberOfRates; + } + + /** + * @param int|null $numberOfRates + * + * @return static + */ + public function setNumberOfRates(?int $numberOfRates): static + { + $this->numberOfRates = $numberOfRates; + return $this; + } + + /** + * @return string|null + */ + public function getTotalAmount(): ?string + { + return $this->totalAmount; + } + + /** + * @param string|null $totalAmount + * + * @return static + */ + public function setTotalAmount(?string $totalAmount): static + { + $this->totalAmount = $totalAmount; + return $this; + } + + /** + * @return string|null + */ + public function getInterestAmount(): ?string + { + return $this->interestAmount; + } + + /** + * @param string|null $interestAmount + * + * @return static + */ + public function setInterestAmount(?string $interestAmount): static + { + $this->interestAmount = $interestAmount; + return $this; + } + + /** + * @return string|null + */ + public function getMinimumInstallmentFee(): ?string + { + return $this->minimumInstallmentFee; + } + + /** + * @param string|null $minimumInstallmentFee + * + * @return static + */ + public function setMinimumInstallmentFee(?string $minimumInstallmentFee): static + { + $this->minimumInstallmentFee = $minimumInstallmentFee; + return $this; + } + + /** + * @return float|null + */ + public function getNominalInterestRate(): ?float + { + return $this->nominalInterestRate; + } + + /** + * @param float|null $nominalInterestRate + * + * @return static + */ + public function setNominalInterestRate(?float $nominalInterestRate): static + { + $this->nominalInterestRate = $nominalInterestRate; + return $this; + } + + /** + * @return float|null + */ + public function getEffectiveInterestRate(): ?float + { + return $this->effectiveInterestRate; + } + + /** + * @param float|null $effectiveInterestRate + * + * @return static + */ + public function setEffectiveInterestRate(?float $effectiveInterestRate): static + { + $this->effectiveInterestRate = $effectiveInterestRate; + return $this; + } + + /** + * @return InstallmentRate[]|null + */ + public function getInstallmentRates(): ?array + { + return $this->installmentRates; + } + + /** + * @param InstallmentRate[]|null $installmentRates + * + * @return static + */ + protected function setInstallmentRates(?array $installmentRates): static + { + $this->installmentRates = $installmentRates; + return $this; + } + + /** + * {@inheritDoc} + */ + public function handleResponse(stdClass $response, string $method = HttpAdapterInterface::REQUEST_GET): void + { + parent::handleResponse($response, $method); + + if (isset($response->installmentRates)) { + $rates = []; + foreach ($response->installmentRates as $rate) { + $rates[] = new InstallmentRate($rate->date ?? null, $rate->rate ?? null); + } + $this->setInstallmentRates($rates); + } + } +} diff --git a/src/Resources/PaylaterPlans.php b/src/Resources/PaylaterPlans.php index 4d446b9c..65fe2e41 100644 --- a/src/Resources/PaylaterPlans.php +++ b/src/Resources/PaylaterPlans.php @@ -5,7 +5,7 @@ use UnzerSDK\Adapter\HttpAdapterInterface; use stdClass; use UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery; -use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan; +use UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan; use UnzerSDK\Traits\HasStates; /** @@ -32,7 +32,7 @@ class PaylaterPlans extends AbstractUnzerResource /** @var string */ private $customerType; - /** @var InstallmentPlan[] $plans */ + /** @var PaylaterPlan[] $plans */ private $plans = []; /** @var PaylaterPlansQuery Query parameter used to fetch available plans. */ @@ -115,7 +115,7 @@ public function setCustomerType(string $customerType): PaylaterPlans } /** - * @return InstallmentPlan[] + * @return PaylaterPlan[] */ public function getPlans(): array { @@ -195,9 +195,9 @@ public function handleResponse(stdClass $response, string $method = HttpAdapterI if (isset($response->plans)) { $plans = []; foreach ($response->plans as $plan) { - $instalment = new InstallmentPlan(); - $instalment->handleResponse($plan); - $plans[] = $instalment; + $paylaterPlan = new PaylaterPlan(); + $paylaterPlan->handleResponse($plan); + $plans[] = $paylaterPlan; } $this->setPlans($plans); } diff --git a/test/integration/PaymentTypes/PaylaterPlansTest.php b/test/integration/PaymentTypes/PaylaterPlansTest.php index 375f9688..b3c6b573 100644 --- a/test/integration/PaymentTypes/PaylaterPlansTest.php +++ b/test/integration/PaymentTypes/PaylaterPlansTest.php @@ -19,7 +19,7 @@ use UnzerSDK\Constants\CustomerTypes; use UnzerSDK\Exceptions\UnzerApiException; -use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan; +use UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan; use UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery; use UnzerSDK\Resources\PaymentTypes\BasePaymentType; use UnzerSDK\Resources\PaymentTypes\PaylaterDirectDebit; @@ -102,7 +102,7 @@ public function invalidInputThrowsUnzerApiException(float $amount, string $curre * Asserts every plan parameter is gettable from the live response: the fields all three types send * are present, and the installment-only interest rates read back as float or null without throwing. */ - private function assertAllPlanParametersGettable(InstallmentPlan $plan): void + private function assertAllPlanParametersGettable(PaylaterPlan $plan): void { $this->assertIsInt($plan->getNumberOfRates()); $this->assertIsString($plan->getTotalAmount()); diff --git a/test/unit/Resources/PaylaterInstallmentPlansTest.php b/test/unit/Resources/PaylaterInstallmentPlansTest.php index e429206b..0f6d4960 100644 --- a/test/unit/Resources/PaylaterInstallmentPlansTest.php +++ b/test/unit/Resources/PaylaterInstallmentPlansTest.php @@ -16,6 +16,7 @@ use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery; use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentRate; use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan; +use UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan; use UnzerSDK\Resources\PaylaterInstallmentPlans; use UnzerSDK\test\BasePaymentTest; use UnzerSDK\test\Fixtures\JsonProvider; @@ -128,6 +129,12 @@ public function verifyJsonResponseIsHandledProperly(): void $this->assertCount(count($jsonResponse->plans), $paylaterInstallmentPlans->getPlans()); + // Backward compatibility: the legacy flow still returns InstallmentPlan items, which are now a + // subclass of the generalized PaylaterPlan. + $firstPlan = $paylaterInstallmentPlans->getPlans()[0]; + $this->assertInstanceOf(InstallmentPlan::class, $firstPlan); + $this->assertInstanceOf(PaylaterPlan::class, $firstPlan); + // then $this->assertEquals($jsonResponse->id ?? null, $paylaterInstallmentPlans->getId()); $this->assertEquals($jsonResponse->amount ?? null, $paylaterInstallmentPlans->getAmount()); @@ -139,6 +146,18 @@ public function verifyJsonResponseIsHandledProperly(): void $this->comparePlans($jsonResponse->plans, $paylaterInstallmentPlans->getPlans()); } + /** + * The deprecated InstallmentPlan is kept as a subclass of the generalized PaylaterPlan, so existing + * code that type-hints or checks InstallmentPlan keeps working after the rename. + * + * @test + */ + public function installmentPlanIsADeprecatedSubclassOfPaylaterPlan(): void + { + $this->assertTrue(is_subclass_of(InstallmentPlan::class, PaylaterPlan::class)); + $this->assertInstanceOf(PaylaterPlan::class, new InstallmentPlan()); + } + // /** diff --git a/test/unit/Resources/PaylaterPlansTest.php b/test/unit/Resources/PaylaterPlansTest.php index 1eab0365..c10341ac 100644 --- a/test/unit/Resources/PaylaterPlansTest.php +++ b/test/unit/Resources/PaylaterPlansTest.php @@ -12,8 +12,8 @@ namespace UnzerSDK\test\unit\Resources; use UnzerSDK\Constants\CustomerTypes; -use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan; use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentRate; +use UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan; use UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery; use UnzerSDK\Resources\PaylaterPlans; use UnzerSDK\test\BasePaymentTest; @@ -241,8 +241,9 @@ public function nullPlansArrayMapsToEmptyList(): void /** * Asserts every getter of a plan item is callable and returns the expected nullable type. */ - private function assertAllPlanParametersGettable(InstallmentPlan $plan): void + private function assertAllPlanParametersGettable(PaylaterPlan $plan): void { + $this->assertInstanceOf(PaylaterPlan::class, $plan); $this->assertIsInt($plan->getNumberOfRates()); $this->assertIsString($plan->getTotalAmount()); $this->assertIsString($plan->getMinimumInstallmentFee()); @@ -265,7 +266,7 @@ private function assertAllPlanParametersGettable(InstallmentPlan $plan): void /** * @param object[] $expected - * @param InstallmentPlan[] $actual + * @param PaylaterPlan[] $actual */ private function comparePlans(array $expected, array $actual): void { From e7bd2b6616c9fb41d359f36334475db31d4a617a Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Wed, 25 Nov 2026 13:40:03 +0100 Subject: [PATCH 04/10] [CC-4346] Make PaylaterPlan/InstallmentPlan standalone, not inheritance, to preserve BC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- CHANGELOG.md | 4 +- .../Paylater/InstallmentPlan.php | 182 +++++++++++++++++- .../Paylater/PaylaterPlan.php | 32 +-- .../PaylaterInstallmentPlansTest.php | 32 +-- 4 files changed, 215 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce3c77bc..ee9de01a 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). * `\UnzerSDK\Resources\PaymentTypes\PIS` (Unzer Bank Transfer / FlexiPay Direct) payment type. It is no longer supported and will be removed in a future major version. * `\UnzerSDK\Resources\PaymentTypes\Sofort` payment type. It is no longer supported and will be removed in a future major version. * `\UnzerSDK\Resources\PaylaterInstallmentPlans` (use `\UnzerSDK\Resources\PaylaterPlans`) and `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery` (use `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery`). The legacy classes are left unchanged as standalone deprecated aliases with their original public signatures (no inheritance from the new generalized classes), so existing code keeps working. `Unzer::fetchPaylaterInstallmentPlans()` is unchanged. -* `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan` (use `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan`). It is now a subclass of `PaylaterPlan` kept for backward compatibility: the deprecated `Unzer::fetchPaylaterInstallmentPlans()` flow still returns `InstallmentPlan` items and existing `InstallmentPlan` type hints keep working (an `InstallmentPlan` is-a `PaylaterPlan`). It will be removed in a future major version. +* `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan` (use `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan`). It is left as a **standalone** deprecated class with its original public signatures unchanged (no inheritance from `PaylaterPlan`), so the deprecated `Unzer::fetchPaylaterInstallmentPlans()` flow still returns `InstallmentPlan` and existing integrations that subclass it or rely on its return types keep working. It will be removed in a future major version. ### Removed @@ -32,7 +32,7 @@ to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). * `\UnzerSDK\Resources\Keypair`: boolean flags (`validateBasket`, `cof`) that the API sends as the strings `"true"`/`"false"` were coerced so `"false"` evaluated to `true`. They are now parsed correctly, so `isValidateBasket()` and `expose()` reflect the real value; a missing field stays `null`. * `\UnzerSDK\Resources\Keypair`: a plain `fetchKeypair()` listed every payment type twice in `getPaymentTypes()` / `getAvailablePaymentTypes()`; the list is now de-duplicated (detailed keypair unchanged). -* `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan` (and therefore its deprecated subclass `InstallmentPlan`): the plan getters are now nullable (`getSecciUrl(): ?string`, `getEffectiveInterestRate(): ?float`, `getNominalInterestRate(): ?float`, `getNumberOfRates(): ?int`, `getTotalAmount(): ?string`, `getMinimumInstallmentFee(): ?string`). Fetching Paylater Invoice and Direct Debit plans — which omit the interest-rate fields — no longer throws a `TypeError`, and a null field in any plan response (`\UnzerSDK\Resources\PaylaterPlans` included) is tolerated instead of crashing the fetch. +* `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan`: the plan getters are nullable (`getSecciUrl(): ?string`, `getEffectiveInterestRate(): ?float`, `getNominalInterestRate(): ?float`, `getNumberOfRates(): ?int`, `getTotalAmount(): ?string`, `getMinimumInstallmentFee(): ?string`). Fetching Paylater Invoice and Direct Debit plans — which omit the interest-rate fields — no longer throws a `TypeError`, and a null field in any plan response (`\UnzerSDK\Resources\PaylaterPlans` included) is tolerated instead of crashing the fetch. (The deprecated `InstallmentPlan` keeps its original non-nullable signatures.) ### Changed diff --git a/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php b/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php index 8508588d..1e85cf11 100644 --- a/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php +++ b/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php @@ -2,18 +2,188 @@ namespace UnzerSDK\Resources\EmbeddedResources\Paylater; +use UnzerSDK\Adapter\HttpAdapterInterface; +use UnzerSDK\Resources\AbstractUnzerResource; +use stdClass; + /** - * Resource representing a single plan item of the legacy installment plans flow. + * Resource representing the installment plan for Paylater Installment. * * @deprecated since the plan item was generalized across all paylater types. Use {@see PaylaterPlan} * instead; it is the item type returned by the generalized `Unzer::fetchPaylaterPlans()` - * flow. This class is kept as an unchanged subclass so the deprecated - * `Unzer::fetchPaylaterInstallmentPlans()` flow and existing type hints keep working - * (an InstallmentPlan is-a PaylaterPlan). It will be removed in a future major version. + * flow. This standalone class keeps its original public signatures unchanged so the + * deprecated `Unzer::fetchPaylaterInstallmentPlans()` flow and existing integrations keep + * working. It will be removed in a future major version. * - * @link https://docs.unzer.com/ + * @link https://docs.unzer.com/ * */ -class InstallmentPlan extends PaylaterPlan +class InstallmentPlan extends AbstractUnzerResource { + /** @var int $numberOfRates */ + private $numberOfRates; + + private $totalAmount; + + private $minimumInstallmentFee; + + private $nominalInterestRate; + + /** @var float $effectiveInterestRate */ + private $effectiveInterestRate; + + /** @var string $secciUrl */ + private $secciUrl; + + /** @var InstallmentRate */ + private $installmentRates; + + /** + * @return string + */ + public function getSecciUrl(): string + { + return $this->secciUrl; + } + + /** + * @param string $secciUrl + * + * @return InstallmentPlan + */ + public function setSecciUrl(string $secciUrl): InstallmentPlan + { + $this->secciUrl = $secciUrl; + return $this; + } + + /** + * @return int + */ + public function getNumberOfRates(): int + { + return $this->numberOfRates; + } + + /** + * @param int $numberOfRates + * + * @return InstallmentPlan + */ + public function setNumberOfRates(int $numberOfRates): InstallmentPlan + { + $this->numberOfRates = $numberOfRates; + return $this; + } + + /** + * @return mixed + */ + public function getTotalAmount() + { + return $this->totalAmount; + } + + /** + * @param mixed $totalAmount + * + * @return InstallmentPlan + */ + public function setTotalAmount($totalAmount) + { + $this->totalAmount = $totalAmount; + return $this; + } + + /** + * @return mixed + */ + public function getMinimumInstallmentFee() + { + return $this->minimumInstallmentFee; + } + + /** + * @param mixed $minimumInstallmentFee + * + * @return InstallmentPlan + */ + public function setMinimumInstallmentFee($minimumInstallmentFee) + { + $this->minimumInstallmentFee = $minimumInstallmentFee; + return $this; + } + + /** + * @return mixed + */ + public function getNominalInterestRate() + { + return $this->nominalInterestRate; + } + + /** + * @param mixed $nominalInterestRate + * + * @return InstallmentPlan + */ + public function setNominalInterestRate($nominalInterestRate) + { + $this->nominalInterestRate = $nominalInterestRate; + return $this; + } + + /** + * @return float + */ + public function getEffectiveInterestRate(): float + { + return $this->effectiveInterestRate; + } + + /** + * @param float $effectiveInterestRate + * + * @return InstallmentPlan + */ + public function setEffectiveInterestRate(float $effectiveInterestRate): InstallmentPlan + { + $this->effectiveInterestRate = $effectiveInterestRate; + return $this; + } + + /** + * @return InstallmentRate[]|null + */ + public function getInstallmentRates(): ?array + { + return $this->installmentRates; + } + + /** + * @param InstallmentRate[] $installmentRates + * + * @return InstallmentPlan + */ + protected function setInstallmentRates(array $installmentRates): InstallmentPlan + { + $this->installmentRates = $installmentRates; + return $this; + } + + /** + * {@inheritDoc} + */ + public function handleResponse(stdClass $response, string $method = HttpAdapterInterface::REQUEST_GET): void + { + parent::handleResponse($response, $method); + + if (isset($response->installmentRates)) { + $rates = []; + foreach ($response->installmentRates as $rate) { + $rates[] = new InstallmentRate($rate->date ?? null, $rate->rate ?? null); + } + $this->setInstallmentRates($rates); + } + } } diff --git a/src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php b/src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php index 6ca67fe9..648cecb8 100644 --- a/src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php +++ b/src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php @@ -54,9 +54,9 @@ public function getSecciUrl(): ?string /** * @param string|null $secciUrl * - * @return static + * @return PaylaterPlan */ - public function setSecciUrl(?string $secciUrl): static + public function setSecciUrl(?string $secciUrl): PaylaterPlan { $this->secciUrl = $secciUrl; return $this; @@ -73,9 +73,9 @@ public function getNumberOfRates(): ?int /** * @param int|null $numberOfRates * - * @return static + * @return PaylaterPlan */ - public function setNumberOfRates(?int $numberOfRates): static + public function setNumberOfRates(?int $numberOfRates): PaylaterPlan { $this->numberOfRates = $numberOfRates; return $this; @@ -92,9 +92,9 @@ public function getTotalAmount(): ?string /** * @param string|null $totalAmount * - * @return static + * @return PaylaterPlan */ - public function setTotalAmount(?string $totalAmount): static + public function setTotalAmount(?string $totalAmount): PaylaterPlan { $this->totalAmount = $totalAmount; return $this; @@ -111,9 +111,9 @@ public function getInterestAmount(): ?string /** * @param string|null $interestAmount * - * @return static + * @return PaylaterPlan */ - public function setInterestAmount(?string $interestAmount): static + public function setInterestAmount(?string $interestAmount): PaylaterPlan { $this->interestAmount = $interestAmount; return $this; @@ -130,9 +130,9 @@ public function getMinimumInstallmentFee(): ?string /** * @param string|null $minimumInstallmentFee * - * @return static + * @return PaylaterPlan */ - public function setMinimumInstallmentFee(?string $minimumInstallmentFee): static + public function setMinimumInstallmentFee(?string $minimumInstallmentFee): PaylaterPlan { $this->minimumInstallmentFee = $minimumInstallmentFee; return $this; @@ -149,9 +149,9 @@ public function getNominalInterestRate(): ?float /** * @param float|null $nominalInterestRate * - * @return static + * @return PaylaterPlan */ - public function setNominalInterestRate(?float $nominalInterestRate): static + public function setNominalInterestRate(?float $nominalInterestRate): PaylaterPlan { $this->nominalInterestRate = $nominalInterestRate; return $this; @@ -168,9 +168,9 @@ public function getEffectiveInterestRate(): ?float /** * @param float|null $effectiveInterestRate * - * @return static + * @return PaylaterPlan */ - public function setEffectiveInterestRate(?float $effectiveInterestRate): static + public function setEffectiveInterestRate(?float $effectiveInterestRate): PaylaterPlan { $this->effectiveInterestRate = $effectiveInterestRate; return $this; @@ -187,9 +187,9 @@ public function getInstallmentRates(): ?array /** * @param InstallmentRate[]|null $installmentRates * - * @return static + * @return PaylaterPlan */ - protected function setInstallmentRates(?array $installmentRates): static + protected function setInstallmentRates(?array $installmentRates): PaylaterPlan { $this->installmentRates = $installmentRates; return $this; diff --git a/test/unit/Resources/PaylaterInstallmentPlansTest.php b/test/unit/Resources/PaylaterInstallmentPlansTest.php index 0f6d4960..f16d3ca0 100644 --- a/test/unit/Resources/PaylaterInstallmentPlansTest.php +++ b/test/unit/Resources/PaylaterInstallmentPlansTest.php @@ -129,11 +129,8 @@ public function verifyJsonResponseIsHandledProperly(): void $this->assertCount(count($jsonResponse->plans), $paylaterInstallmentPlans->getPlans()); - // Backward compatibility: the legacy flow still returns InstallmentPlan items, which are now a - // subclass of the generalized PaylaterPlan. - $firstPlan = $paylaterInstallmentPlans->getPlans()[0]; - $this->assertInstanceOf(InstallmentPlan::class, $firstPlan); - $this->assertInstanceOf(PaylaterPlan::class, $firstPlan); + // Backward compatibility: the legacy flow still returns InstallmentPlan items. + $this->assertInstanceOf(InstallmentPlan::class, $paylaterInstallmentPlans->getPlans()[0]); // then $this->assertEquals($jsonResponse->id ?? null, $paylaterInstallmentPlans->getId()); @@ -147,15 +144,20 @@ public function verifyJsonResponseIsHandledProperly(): void } /** - * The deprecated InstallmentPlan is kept as a subclass of the generalized PaylaterPlan, so existing - * code that type-hints or checks InstallmentPlan keeps working after the rename. + * The deprecated InstallmentPlan is a standalone class (it does NOT inherit from the generalized + * PaylaterPlan), so its original public return types are preserved byte-for-byte and existing + * integrations that subclass it or rely on the return type keep working. * * @test + * + * @dataProvider installmentPlanReturnTypeDataProvider */ - public function installmentPlanIsADeprecatedSubclassOfPaylaterPlan(): void + public function installmentPlanSetterReturnTypesAreUnchanged(string $method): void { - $this->assertTrue(is_subclass_of(InstallmentPlan::class, PaylaterPlan::class)); - $this->assertInstanceOf(PaylaterPlan::class, new InstallmentPlan()); + $returnType = (new ReflectionMethod(InstallmentPlan::class, $method))->getReturnType(); + $this->assertNotNull($returnType); + $this->assertSame(InstallmentPlan::class, $returnType->getName()); + $this->assertFalse(is_subclass_of(InstallmentPlan::class, PaylaterPlan::class)); } // @@ -173,7 +175,6 @@ protected function comparePlans(array $expected, array $actual): void foreach ($expected as $index => $plan) { $this->assertEquals($plan->numberOfRates ?? null, $actual[$index]->getNumberOfRates()); $this->assertEquals($plan->totalAmount ?? null, $actual[$index]->getTotalAmount()); - $this->assertEquals($plan->interestAmount ?? null, $actual[$index]->getInterestAmount()); $this->assertEquals($plan->minimumInstallmentFee ?? null, $actual[$index]->getMinimumInstallmentFee()); $this->assertEquals($plan->nominalInterestRate ?? null, $actual[$index]->getNominalInterestRate()); $this->assertEquals($plan->effectiveInterestRate ?? null, $actual[$index]->getEffectiveInterestRate()); @@ -212,6 +213,15 @@ public function verifyQueryStringDP(): array ]; } + public function installmentPlanReturnTypeDataProvider(): array + { + return [ + 'setSecciUrl' => ['setSecciUrl'], + 'setNumberOfRates' => ['setNumberOfRates'], + 'setEffectiveInterestRate' => ['setEffectiveInterestRate'], + ]; + } + /** * Pins the original (pre-generalization) public signatures of the deprecated legacy classes. * From 669fe719e3181f7137ffe92431df91320dd5e3ea Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Wed, 25 Nov 2026 14:04:42 +0100 Subject: [PATCH 05/10] [CC-4346] Add migration-equivalence test: new flow maps same data as 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) --- test/unit/Resources/PaylaterPlansTest.php | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/unit/Resources/PaylaterPlansTest.php b/test/unit/Resources/PaylaterPlansTest.php index c10341ac..56b2ffec 100644 --- a/test/unit/Resources/PaylaterPlansTest.php +++ b/test/unit/Resources/PaylaterPlansTest.php @@ -15,6 +15,7 @@ use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentRate; use UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan; use UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery; +use UnzerSDK\Resources\PaylaterInstallmentPlans; use UnzerSDK\Resources\PaylaterPlans; use UnzerSDK\test\BasePaymentTest; use UnzerSDK\test\Fixtures\JsonProvider; @@ -236,6 +237,46 @@ public function nullPlansArrayMapsToEmptyList(): void $this->assertEmpty($plans->getPlans()); } + /** + * Migration guard: for the installment response, the new PaylaterPlans flow maps to the same plan + * data as the deprecated PaylaterInstallmentPlans flow. Confirms switching is a rename (plus passing + * the payment type to fetchPaylaterPlans()) and not a data-shape change. + * + * @test + */ + public function newFlowMapsSameInstallmentDataAsLegacyFlow(): void + { + $json = JsonProvider::getJsonFromFile('paylaterPlansResponse.json'); + + $legacy = new PaylaterInstallmentPlans(); + $legacy->handleResponse(json_decode($json)); + $new = new PaylaterPlans(); + $new->handleResponse(json_decode($json)); + + $this->assertSame($legacy->getId(), $new->getId()); + $this->assertSame($legacy->getAmount(), $new->getAmount()); + $this->assertSame($legacy->getCurrency(), $new->getCurrency()); + $this->assertCount(count($legacy->getPlans()), $new->getPlans()); + + foreach ($legacy->getPlans() as $index => $legacyPlan) { + $newPlan = $new->getPlans()[$index]; + $this->assertSame($legacyPlan->getSecciUrl(), $newPlan->getSecciUrl()); + $this->assertSame($legacyPlan->getNumberOfRates(), $newPlan->getNumberOfRates()); + $this->assertSame($legacyPlan->getTotalAmount(), $newPlan->getTotalAmount()); + $this->assertSame($legacyPlan->getMinimumInstallmentFee(), $newPlan->getMinimumInstallmentFee()); + $this->assertSame($legacyPlan->getNominalInterestRate(), $newPlan->getNominalInterestRate()); + $this->assertSame($legacyPlan->getEffectiveInterestRate(), $newPlan->getEffectiveInterestRate()); + + $legacyRates = $legacyPlan->getInstallmentRates() ?? []; + $newRates = $newPlan->getInstallmentRates() ?? []; + $this->assertCount(count($legacyRates), $newRates); + foreach ($legacyRates as $rateIndex => $legacyRate) { + $this->assertSame($legacyRate->getDate(), $newRates[$rateIndex]->getDate()); + $this->assertSame($legacyRate->getRate(), $newRates[$rateIndex]->getRate()); + } + } + } + // /** From 70c6fbec0fc546a2adb83e286292858a1de628ff Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Wed, 25 Nov 2026 15:03:51 +0100 Subject: [PATCH 06/10] [CC-4346] Address QA review: null-tolerant country/customerType, CHANGELOG fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- CHANGELOG.md | 6 ++++++ src/Resources/PaylaterPlans.php | 8 ++++---- test/unit/Resources/PaylaterPlansTest.php | 7 ++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee9de01a..c14cb0c5 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). * `minimumInstallmentFee` is now exposed on `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan` via `getMinimumInstallmentFee()` (previously present in the API response but dropped by the SDK). * `interestAmount` is now exposed on `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan` via `getInterestAmount()` (previously present in the API response but dropped by the SDK). +### Changed + +* `\UnzerSDK\Interfaces\PaymentServiceInterface` gained the `fetchPaylaterPlans(BasePaymentType $paymentType, PaylaterPlansQuery $query): PaylaterPlans` method. **Breaking change for any external class that implements `PaymentServiceInterface`** — it must now implement this method. The bundled `\UnzerSDK\Services\PaymentService` already implements it, so typical SDK consumers are unaffected. + ### Deprecated * `\UnzerSDK\Resources\PaymentTypes\PIS` (Unzer Bank Transfer / FlexiPay Direct) payment type. It is no longer supported and will be removed in a future major version. @@ -34,6 +38,8 @@ to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). * `\UnzerSDK\Resources\Keypair`: a plain `fetchKeypair()` listed every payment type twice in `getPaymentTypes()` / `getAvailablePaymentTypes()`; the list is now de-duplicated (detailed keypair unchanged). * `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan`: the plan getters are nullable (`getSecciUrl(): ?string`, `getEffectiveInterestRate(): ?float`, `getNominalInterestRate(): ?float`, `getNumberOfRates(): ?int`, `getTotalAmount(): ?string`, `getMinimumInstallmentFee(): ?string`). Fetching Paylater Invoice and Direct Debit plans — which omit the interest-rate fields — no longer throws a `TypeError`, and a null field in any plan response (`\UnzerSDK\Resources\PaylaterPlans` included) is tolerated instead of crashing the fetch. (The deprecated `InstallmentPlan` keeps its original non-nullable signatures.) +## [4.0.2](https://github.com/unzerdev/php-sdk/compare/4.0.1..4.0.2) + ### Changed * Change `\UnzerSDK\Resources\Keypair` properties from `private` to `protected`, fixing them being silently omitted when the resource is serialized into a request payload. diff --git a/src/Resources/PaylaterPlans.php b/src/Resources/PaylaterPlans.php index 65fe2e41..99bef658 100644 --- a/src/Resources/PaylaterPlans.php +++ b/src/Resources/PaylaterPlans.php @@ -85,11 +85,11 @@ public function getCountry(): ?string } /** - * @param string $country + * @param string|null $country * * @return PaylaterPlans */ - public function setCountry(string $country): PaylaterPlans + public function setCountry(?string $country): PaylaterPlans { $this->country = $country; return $this; @@ -104,11 +104,11 @@ public function getCustomerType(): ?string } /** - * @param string $customerType + * @param string|null $customerType * * @return PaylaterPlans */ - public function setCustomerType(string $customerType): PaylaterPlans + public function setCustomerType(?string $customerType): PaylaterPlans { $this->customerType = $customerType; return $this; diff --git a/test/unit/Resources/PaylaterPlansTest.php b/test/unit/Resources/PaylaterPlansTest.php index 56b2ffec..f8e956a6 100644 --- a/test/unit/Resources/PaylaterPlansTest.php +++ b/test/unit/Resources/PaylaterPlansTest.php @@ -194,7 +194,9 @@ public function nullPlanAndEnvelopeFieldsMapWithoutError(): void $response = json_decode(json_encode([ 'id' => 'Tx-null', 'amount' => null, - 'currency' => 'EUR', + 'currency' => null, + 'country' => null, + 'customerType' => null, 'plans' => [[ 'numberOfRates' => 1, 'totalAmount' => '100.00', @@ -211,6 +213,9 @@ public function nullPlanAndEnvelopeFieldsMapWithoutError(): void $plans->handleResponse($response); $this->assertNull($plans->getAmount()); + $this->assertNull($plans->getCurrency()); + $this->assertNull($plans->getCountry()); + $this->assertNull($plans->getCustomerType()); $plan = $plans->getPlans()[0]; $this->assertSame(1, $plan->getNumberOfRates()); $this->assertNull($plan->getSecciUrl()); From 6e720eaef424dbd2b854b8fe589b865712f7b0b8 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Wed, 25 Nov 2026 15:16:07 +0100 Subject: [PATCH 07/10] [CC-4346] Trim 4.1.0 CHANGELOG to net changes; drop non-consumer interface 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) --- CHANGELOG.md | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c14cb0c5..38273264 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,22 +11,14 @@ to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). * `recurring` flag on `\UnzerSDK\Resources\PaymentTypes\SepaDirectDebit` for registering a payment type for recurring (mandate-based) collection. * `getRawResponse()` on `\UnzerSDK\Resources\Keypair`, exposing the exact raw API response string from a Keypair fetch. -* `Unzer::fetchPaylaterPlans(BasePaymentType $paymentType, PaylaterPlansQuery $query)` to fetch the available plans (including the `secciUrl`) for any paylater payment type, e.g. `new PaylaterInvoice()` or `new PaylaterDirectDebit()`. The SECCI PDF locale follows the client locale set via `Unzer::setLocale()` (`Accept-Language` header). The payment type and query values are passed through to the API unchanged; invalid input is rejected by the API with an `UnzerApiException`. -* `\UnzerSDK\Resources\PaylaterPlans` and `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery` as the generalized plan result/query models. -* `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan` as the generalized plan-item model returned by `PaylaterPlans::getPlans()`. It replaces the installment-specific `InstallmentPlan` name (see _Deprecated_); adopting the new `fetchPaylaterPlans()` flow should type-hint `PaylaterPlan`. -* `minimumInstallmentFee` is now exposed on `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan` via `getMinimumInstallmentFee()` (previously present in the API response but dropped by the SDK). -* `interestAmount` is now exposed on `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan` via `getInterestAmount()` (previously present in the API response but dropped by the SDK). - -### Changed - -* `\UnzerSDK\Interfaces\PaymentServiceInterface` gained the `fetchPaylaterPlans(BasePaymentType $paymentType, PaylaterPlansQuery $query): PaylaterPlans` method. **Breaking change for any external class that implements `PaymentServiceInterface`** — it must now implement this method. The bundled `\UnzerSDK\Services\PaymentService` already implements it, so typical SDK consumers are unaffected. +* `Unzer::fetchPaylaterPlans(BasePaymentType $paymentType, PaylaterPlansQuery $query): PaylaterPlans` to fetch the available plans (including the `secciUrl`) for any paylater payment type — `PaylaterInstallment`, `PaylaterInvoice` or `PaylaterDirectDebit`. The SECCI PDF locale follows `Unzer::setLocale()` (`Accept-Language`); query values are passed through and invalid input is rejected by the API with an `UnzerApiException`. +* `\UnzerSDK\Resources\PaylaterPlans`, `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery`, and the plan-item model `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan` (exposes `secciUrl`, `numberOfRates`, `totalAmount`, `interestAmount`, `minimumInstallmentFee`, `nominalInterestRate`, `effectiveInterestRate` and `installmentRates`; the interest-rate fields are `null` for Invoice and Direct Debit). ### Deprecated * `\UnzerSDK\Resources\PaymentTypes\PIS` (Unzer Bank Transfer / FlexiPay Direct) payment type. It is no longer supported and will be removed in a future major version. * `\UnzerSDK\Resources\PaymentTypes\Sofort` payment type. It is no longer supported and will be removed in a future major version. -* `\UnzerSDK\Resources\PaylaterInstallmentPlans` (use `\UnzerSDK\Resources\PaylaterPlans`) and `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery` (use `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery`). The legacy classes are left unchanged as standalone deprecated aliases with their original public signatures (no inheritance from the new generalized classes), so existing code keeps working. `Unzer::fetchPaylaterInstallmentPlans()` is unchanged. -* `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan` (use `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan`). It is left as a **standalone** deprecated class with its original public signatures unchanged (no inheritance from `PaylaterPlan`), so the deprecated `Unzer::fetchPaylaterInstallmentPlans()` flow still returns `InstallmentPlan` and existing integrations that subclass it or rely on its return types keep working. It will be removed in a future major version. +* `\UnzerSDK\Resources\PaylaterInstallmentPlans`, `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery` and `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan` — use `\UnzerSDK\Resources\PaylaterPlans`, `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery` and `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan`. `Unzer::fetchPaylaterInstallmentPlans()` and the types it returns are unchanged. These will be removed in a future major version. ### Removed @@ -36,7 +28,6 @@ to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). * `\UnzerSDK\Resources\Keypair`: boolean flags (`validateBasket`, `cof`) that the API sends as the strings `"true"`/`"false"` were coerced so `"false"` evaluated to `true`. They are now parsed correctly, so `isValidateBasket()` and `expose()` reflect the real value; a missing field stays `null`. * `\UnzerSDK\Resources\Keypair`: a plain `fetchKeypair()` listed every payment type twice in `getPaymentTypes()` / `getAvailablePaymentTypes()`; the list is now de-duplicated (detailed keypair unchanged). -* `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlan`: the plan getters are nullable (`getSecciUrl(): ?string`, `getEffectiveInterestRate(): ?float`, `getNominalInterestRate(): ?float`, `getNumberOfRates(): ?int`, `getTotalAmount(): ?string`, `getMinimumInstallmentFee(): ?string`). Fetching Paylater Invoice and Direct Debit plans — which omit the interest-rate fields — no longer throws a `TypeError`, and a null field in any plan response (`\UnzerSDK\Resources\PaylaterPlans` included) is tolerated instead of crashing the fetch. (The deprecated `InstallmentPlan` keeps its original non-nullable signatures.) ## [4.0.2](https://github.com/unzerdev/php-sdk/compare/4.0.1..4.0.2) From e398fa0d1204f369a51e5099e1270c062dbfe66b Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Wed, 25 Nov 2026 15:54:56 +0100 Subject: [PATCH 08/10] [CC-4346] Use typed properties on PaylaterPlan (PHP 7.4+, min is now 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) --- .../Paylater/PaylaterPlan.php | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php b/src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php index 648cecb8..207248bd 100644 --- a/src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php +++ b/src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php @@ -19,29 +19,22 @@ */ class PaylaterPlan extends AbstractUnzerResource { - /** @var int|null $numberOfRates */ - private $numberOfRates; + private ?int $numberOfRates = null; - /** @var string|null $totalAmount */ - private $totalAmount; + private ?string $totalAmount = null; - /** @var string|null $interestAmount */ - private $interestAmount; + private ?string $interestAmount = null; - /** @var string|null $minimumInstallmentFee */ - private $minimumInstallmentFee; + private ?string $minimumInstallmentFee = null; - /** @var float|null $nominalInterestRate */ - private $nominalInterestRate; + private ?float $nominalInterestRate = null; - /** @var float|null $effectiveInterestRate */ - private $effectiveInterestRate; + private ?float $effectiveInterestRate = null; - /** @var string|null $secciUrl */ - private $secciUrl; + private ?string $secciUrl = null; - /** @var InstallmentRate[]|null $installmentRates */ - private $installmentRates; + /** @var InstallmentRate[]|null */ + private ?array $installmentRates = null; /** * @return string|null From 28dd7d677858fd17747d8a5bf464ecb71f6273f3 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Wed, 25 Nov 2026 16:01:19 +0100 Subject: [PATCH 09/10] [CC-4346] Use typed properties on PaylaterPlans too 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) --- src/Resources/PaylaterPlans.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Resources/PaylaterPlans.php b/src/Resources/PaylaterPlans.php index 99bef658..c1f5a418 100644 --- a/src/Resources/PaylaterPlans.php +++ b/src/Resources/PaylaterPlans.php @@ -20,23 +20,19 @@ class PaylaterPlans extends AbstractUnzerResource { use HasStates; - /** @var float */ - private $amount; + private ?float $amount = null; - /** @var string */ - private $currency; + private ?string $currency = null; - /** @var string */ - private $country; + private ?string $country = null; - /** @var string */ - private $customerType; + private ?string $customerType = null; /** @var PaylaterPlan[] $plans */ - private $plans = []; + private array $plans = []; /** @var PaylaterPlansQuery Query parameter used to fetch available plans. */ - private $queryParameter; + private ?PaylaterPlansQuery $queryParameter = null; /** * @return float From 929a9b2a67bc11e86c11160e36f041be0cf33418 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Wed, 25 Nov 2026 16:38:39 +0100 Subject: [PATCH 10/10] [CC-4346] Polish from independent review: docblocks, null-tolerance coverage 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) --- src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php | 6 +++--- src/Resources/PaylaterPlans.php | 8 ++++---- test/unit/Resources/PaylaterPlansTest.php | 7 ++++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php b/src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php index 207248bd..8c58531c 100644 --- a/src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php +++ b/src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php @@ -10,9 +10,9 @@ * Resource representing a single plan item returned by the generalized paylater /plans endpoint. * * The same PAPI schema backs all three paylater types (installment, invoice, direct debit), but each - * type only populates a subset of the optional fields: invoice and direct debit omit the interest-rate - * fields and send rates without a date, while installment carries the full set. Every getter is therefore - * nullable so a field a given type does not return reads back as null instead of throwing. + * type only populates a subset of the optional fields: invoice and direct debit omit `nominalInterestRate` + * and `effectiveInterestRate` and send rates without a date, while installment carries the full set. Every + * getter is therefore nullable so a field a given type does not return reads back as null instead of throwing. * * @link https://docs.unzer.com/ * diff --git a/src/Resources/PaylaterPlans.php b/src/Resources/PaylaterPlans.php index c1f5a418..36b0a4e4 100644 --- a/src/Resources/PaylaterPlans.php +++ b/src/Resources/PaylaterPlans.php @@ -35,7 +35,7 @@ class PaylaterPlans extends AbstractUnzerResource private ?PaylaterPlansQuery $queryParameter = null; /** - * @return float + * @return float|null */ public function getAmount(): ?float { @@ -54,7 +54,7 @@ public function setAmount(?float $amount): PaylaterPlans } /** - * @return string + * @return string|null */ public function getCurrency(): ?string { @@ -73,7 +73,7 @@ public function setCurrency(?string $currency): PaylaterPlans } /** - * @return string + * @return string|null */ public function getCountry(): ?string { @@ -92,7 +92,7 @@ public function setCountry(?string $country): PaylaterPlans } /** - * @return string + * @return string|null */ public function getCustomerType(): ?string { diff --git a/test/unit/Resources/PaylaterPlansTest.php b/test/unit/Resources/PaylaterPlansTest.php index f8e956a6..db10a63f 100644 --- a/test/unit/Resources/PaylaterPlansTest.php +++ b/test/unit/Resources/PaylaterPlansTest.php @@ -198,8 +198,8 @@ public function nullPlanAndEnvelopeFieldsMapWithoutError(): void 'country' => null, 'customerType' => null, 'plans' => [[ - 'numberOfRates' => 1, - 'totalAmount' => '100.00', + 'numberOfRates' => null, + 'totalAmount' => null, 'interestAmount' => null, 'minimumInstallmentFee' => null, 'nominalInterestRate' => null, @@ -217,7 +217,8 @@ public function nullPlanAndEnvelopeFieldsMapWithoutError(): void $this->assertNull($plans->getCountry()); $this->assertNull($plans->getCustomerType()); $plan = $plans->getPlans()[0]; - $this->assertSame(1, $plan->getNumberOfRates()); + $this->assertNull($plan->getNumberOfRates()); + $this->assertNull($plan->getTotalAmount()); $this->assertNull($plan->getSecciUrl()); $this->assertNull($plan->getInterestAmount()); $this->assertNull($plan->getMinimumInstallmentFee());