From 8183f892c3bed0449b56e846852146de7b7bd116 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:37:32 +0100 Subject: [PATCH 01/10] [CC-4346] Support SECCI /plans endpoint for Paylater Invoice and Direct Debit Generalize the paylater installment plan flow so plans (including the SECCI PDF URL) can be fetched for any paylater payment type via the new PAPI `types/paylater-invoice/plans` and `types/paylater-direct-debit/plans` endpoints, mirroring the existing installment endpoint. - Add PaylaterPlansQuery (query DTO) and PaylaterPlans (result) as the generalized models; keep InstallmentPlansQuery and PaylaterInstallmentPlans as deprecated subclasses for backward compatibility. - Add Unzer::fetchPaylaterPlans(BasePaymentType, PaylaterPlansQuery) and the PaymentService method. The payment type and query are passed through to PAPI unchanged (permissive design, no SDK-side validation or allowlist); the endpoint segment is derived from the payment type class name via parent- resource URI chaining. - fetchPaylaterInstallmentPlans keeps its signature and return type unchanged. - Add unit tests (path per type, query assembly/default, response mapping, missing/empty rates, BC) and skipped integration tests pending CC-4014. - Bump SDK_VERSION to 5.0.0 and update CHANGELOG. Co-Authored-By: Claude Opus 4.8 (1M context) --- CHANGELOG.md | 9 + src/Interfaces/PaymentServiceInterface.php | 19 ++ .../Paylater/InstallmentPlansQuery.php | 101 +-------- .../Paylater/PaylaterPlansQuery.php | 111 ++++++++++ src/Resources/PaylaterInstallmentPlans.php | 199 +---------------- src/Resources/PaylaterPlans.php | 205 ++++++++++++++++++ src/Services/PaymentService.php | 12 + src/Unzer.php | 12 +- .../jsonData/paylaterPlansResponseEmpty.json | 10 + .../paylaterPlansResponseNoRates.json | 27 +++ .../PaymentTypes/PaylaterPlansTest.php | 105 +++++++++ test/unit/Resources/PaylaterPlansTest.php | 204 +++++++++++++++++ test/unit/Services/PaymentServiceTest.php | 105 +++++++++ 13 files changed, 826 insertions(+), 293 deletions(-) create mode 100644 src/Resources/EmbeddedResources/Paylater/PaylaterPlansQuery.php create mode 100644 src/Resources/PaylaterPlans.php create mode 100644 test/Fixtures/jsonData/paylaterPlansResponseEmpty.json create mode 100644 test/Fixtures/jsonData/paylaterPlansResponseNoRates.json create mode 100644 test/integration/PaymentTypes/PaylaterPlansTest.php create mode 100644 test/unit/Resources/PaylaterPlansTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e8b23eb6..713de6ad6 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ 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 + +* `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. + +### Deprecated + +* `\UnzerSDK\Resources\PaylaterInstallmentPlans` (use `\UnzerSDK\Resources\PaylaterPlans`) and `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery` (use `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery`). Both remain as subclasses for backward compatibility. `Unzer::fetchPaylaterInstallmentPlans()` is unchanged. + ### 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/Interfaces/PaymentServiceInterface.php b/src/Interfaces/PaymentServiceInterface.php index ad05a505e..fbd5a1ab7 100644 --- a/src/Interfaces/PaymentServiceInterface.php +++ b/src/Interfaces/PaymentServiceInterface.php @@ -15,9 +15,11 @@ use UnzerSDK\Resources\Basket; use UnzerSDK\Resources\Customer; use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery; +use UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery; use UnzerSDK\Resources\InstalmentPlans; use UnzerSDK\Resources\Metadata; use UnzerSDK\Resources\PaylaterInstallmentPlans; +use UnzerSDK\Resources\PaylaterPlans; use UnzerSDK\Resources\Payment; use UnzerSDK\Resources\PaymentTypes\BasePaymentType; use UnzerSDK\Resources\PaymentTypes\Paypage; @@ -391,6 +393,23 @@ public function fetchInstallmentPlans( */ public function fetchPaylaterInstallmentPlans(InstallmentPlansQuery $plansRequest): PaylaterInstallmentPlans; + /** + * Returns a PaylaterPlans object containing all available plan options for the given paylater payment type + * (e.g. Paylater Installment, Paylater Invoice, Paylater Direct Debit). + * + * The payment type is passed through to the API as-is; the SDK neither validates it nor the query values. + * An unsupported payment type or invalid input is rejected by the API with an UnzerApiException. + * + * @param BasePaymentType $paymentType The paylater payment type the plans are requested for. + * @param PaylaterPlansQuery $query The query holding amount, currency, country and customer type. + * + * @return PaylaterPlans The object containing all available plans. + * + * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. + * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. + */ + public function fetchPaylaterPlans(BasePaymentType $paymentType, PaylaterPlansQuery $query): PaylaterPlans; + /** * Perform an SCA transaction. * diff --git a/src/Resources/EmbeddedResources/Paylater/InstallmentPlansQuery.php b/src/Resources/EmbeddedResources/Paylater/InstallmentPlansQuery.php index 7d949c45b..ba5e58635 100644 --- a/src/Resources/EmbeddedResources/Paylater/InstallmentPlansQuery.php +++ b/src/Resources/EmbeddedResources/Paylater/InstallmentPlansQuery.php @@ -2,109 +2,14 @@ namespace UnzerSDK\Resources\EmbeddedResources\Paylater; -use UnzerSDK\Constants\CustomerTypes; -use UnzerSDK\Resources\AbstractUnzerResource; - /** * This class contains the query properties which are used to fetch paylater installment plans. * + * @deprecated since the introduction of the generalized paylater plans endpoint. Use + * {@see PaylaterPlansQuery} together with Unzer::fetchPaylaterPlans() instead. * @link https://docs.unzer.com/ * */ -class InstallmentPlansQuery extends AbstractUnzerResource +class InstallmentPlansQuery extends PaylaterPlansQuery { - protected float $amount; - protected string $currency; - protected string $country; - protected string $customerType; - - /** - * @param float $amount - * @param string $currency - * @param string $country - * @param string $customerType - */ - public function __construct(float $amount, string $currency, string $country, string $customerType = CustomerTypes::B2C) - { - $this->amount = $amount; - $this->currency = $currency; - $this->country = $country; - $this->customerType = $customerType; - } - - /** - * @return float - */ - public function getAmount(): float - { - return $this->amount; - } - - /** - * @param float $amount - * - * @return InstallmentPlansQuery - */ - public function setAmount(float $amount): InstallmentPlansQuery - { - $this->amount = $amount; - return $this; - } - - /** - * @return string - */ - public function getCurrency(): string - { - return $this->currency; - } - - /** - * @param string $currency - * - * @return InstallmentPlansQuery - */ - public function setCurrency(string $currency): InstallmentPlansQuery - { - $this->currency = $currency; - return $this; - } - - /** - * @return string - */ - public function getCountry(): string - { - return $this->country; - } - - /** - * @param string $country - * - * @return InstallmentPlansQuery - */ - public function setCountry(string $country): InstallmentPlansQuery - { - $this->country = $country; - return $this; - } - - /** - * @return string - */ - public function getCustomerType(): string - { - return $this->customerType; - } - - /** - * @param string $customerType - * - * @return InstallmentPlansQuery - */ - public function setCustomerType(string $customerType): InstallmentPlansQuery - { - $this->customerType = $customerType; - return $this; - } } diff --git a/src/Resources/EmbeddedResources/Paylater/PaylaterPlansQuery.php b/src/Resources/EmbeddedResources/Paylater/PaylaterPlansQuery.php new file mode 100644 index 000000000..5ec1446bb --- /dev/null +++ b/src/Resources/EmbeddedResources/Paylater/PaylaterPlansQuery.php @@ -0,0 +1,111 @@ +amount = $amount; + $this->currency = $currency; + $this->country = $country; + $this->customerType = $customerType; + } + + /** + * @return float + */ + public function getAmount(): float + { + return $this->amount; + } + + /** + * @param float $amount + * + * @return PaylaterPlansQuery + */ + public function setAmount(float $amount): PaylaterPlansQuery + { + $this->amount = $amount; + return $this; + } + + /** + * @return string + */ + public function getCurrency(): string + { + return $this->currency; + } + + /** + * @param string $currency + * + * @return PaylaterPlansQuery + */ + public function setCurrency(string $currency): PaylaterPlansQuery + { + $this->currency = $currency; + return $this; + } + + /** + * @return string + */ + public function getCountry(): string + { + return $this->country; + } + + /** + * @param string $country + * + * @return PaylaterPlansQuery + */ + public function setCountry(string $country): PaylaterPlansQuery + { + $this->country = $country; + return $this; + } + + /** + * @return string + */ + public function getCustomerType(): string + { + return $this->customerType; + } + + /** + * @param string $customerType + * + * @return PaylaterPlansQuery + */ + public function setCustomerType(string $customerType): PaylaterPlansQuery + { + $this->customerType = $customerType; + return $this; + } +} diff --git a/src/Resources/PaylaterInstallmentPlans.php b/src/Resources/PaylaterInstallmentPlans.php index 4e132d2a7..98445ecb9 100644 --- a/src/Resources/PaylaterInstallmentPlans.php +++ b/src/Resources/PaylaterInstallmentPlans.php @@ -2,204 +2,15 @@ namespace UnzerSDK\Resources; -use UnzerSDK\Adapter\HttpAdapterInterface; -use stdClass; -use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery; -use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan; -use UnzerSDK\Traits\HasStates; - /** - * Resource used to fetch instalment plans for Installment Secured payment method specified as parent resource. - * Please use Unzer methods to fetch the list of instalment plans - * (e.g. Unzer::fetchInstallmentPlans(...)). + * Resource used to fetch instalment plans for the Paylater Installment payment method specified as parent resource. + * Please use Unzer methods to fetch the list of instalment plans (e.g. Unzer::fetchPaylaterInstallmentPlans(...)). * + * @deprecated since the introduction of the generalized paylater plans endpoint. Use + * {@see PaylaterPlans} together with Unzer::fetchPaylaterPlans() instead. * @link https://docs.unzer.com/ * */ -class PaylaterInstallmentPlans extends AbstractUnzerResource +class PaylaterInstallmentPlans extends PaylaterPlans { - use HasStates; - - /** @var float */ - private $amount; - - /** @var string */ - private $currency; - - /** @var string */ - private $country; - - /** @var string */ - private $customerType; - - /** @var InstallmentPlan[] $plans */ - private $plans = []; - - /** @var InstallmentPlansQuery Query parameter used to fetch available installment plans. */ - private $queryParameter; - - /** - * @return float - */ - public function getAmount(): ?float - { - return $this->amount; - } - - /** - * @param float $amount - * - * @return PaylaterInstallmentPlans - */ - public function setAmount(float $amount): PaylaterInstallmentPlans - { - $this->amount = $amount; - return $this; - } - - /** - * @return string - */ - public function getCurrency(): ?string - { - return $this->currency; - } - - /** - * @param string $currency - * - * @return InstalmentPlans - */ - public function setCurrency(string $currency): PaylaterInstallmentPlans - { - $this->currency = $currency; - return $this; - } - - /** - * @return string - */ - public function getCountry(): ?string - { - return $this->country; - } - - /** - * @param string $country - * - * @return PaylaterInstallmentPlans - */ - public function setCountry(string $country): PaylaterInstallmentPlans - { - $this->country = $country; - return $this; - } - - /** - * @return string - */ - public function getCustomerType(): ?string - { - return $this->customerType; - } - - /** - * @param string $customerType - * - * @return PaylaterInstallmentPlans - */ - public function setCustomerType(string $customerType): PaylaterInstallmentPlans - { - $this->customerType = $customerType; - return $this; - } - - /** - * @return InstallmentPlan[] - */ - public function getPlans(): array - { - return $this->plans; - } - - /** - * @param stdClass[] $plans - * - * @return InstalmentPlans - */ - protected function setPlans(array $plans): PaylaterInstallmentPlans - { - $this->plans = $plans; - return $this; - } - - /** - * {@inheritDoc} - */ - public function getResourcePath(string $httpMethod = HttpAdapterInterface::REQUEST_GET): string - { - return 'plans' . $this->getQueryString(); - } - - /** - * Returns the query string for this resource. - * - * @return string - */ - protected function getQueryString(): string - { - return '?' . http_build_query($this->getQueryArray()); - } - - /** - * Returns the parameter array containing the values for the query string. - * - * @return array - */ - protected function getQueryArray(): array - { - $parameters = []; - if ($this->queryParameter === null) { - return $parameters; - } - - return $this->getQueryParameter()->expose(); - } - - /** - * @return InstallmentPlansQuery - */ - public function getQueryParameter(): InstallmentPlansQuery - { - return $this->queryParameter; - } - - /** - * @param InstallmentPlansQuery $queryParameter - * - * @return PaylaterInstallmentPlans - */ - public function setQueryParameter(InstallmentPlansQuery $queryParameter): PaylaterInstallmentPlans - { - $this->queryParameter = $queryParameter; - return $this; - } - - /** - * {@inheritDoc} - */ - public function handleResponse(stdClass $response, string $method = HttpAdapterInterface::REQUEST_GET): void - { - parent::handleResponse($response, $method); - - if (isset($response->plans)) { - $plans = []; - foreach ($response->plans as $plan) { - $instalment = new InstallmentPlan(); - $instalment->handleResponse($plan); - $plans[] = $instalment; - } - $this->setPlans($plans); - } - } } diff --git a/src/Resources/PaylaterPlans.php b/src/Resources/PaylaterPlans.php new file mode 100644 index 000000000..927937b71 --- /dev/null +++ b/src/Resources/PaylaterPlans.php @@ -0,0 +1,205 @@ +amount; + } + + /** + * @param float $amount + * + * @return PaylaterPlans + */ + public function setAmount(float $amount): PaylaterPlans + { + $this->amount = $amount; + return $this; + } + + /** + * @return string + */ + public function getCurrency(): ?string + { + return $this->currency; + } + + /** + * @param string $currency + * + * @return PaylaterPlans + */ + public function setCurrency(string $currency): PaylaterPlans + { + $this->currency = $currency; + return $this; + } + + /** + * @return string + */ + public function getCountry(): ?string + { + return $this->country; + } + + /** + * @param string $country + * + * @return PaylaterPlans + */ + public function setCountry(string $country): PaylaterPlans + { + $this->country = $country; + return $this; + } + + /** + * @return string + */ + public function getCustomerType(): ?string + { + return $this->customerType; + } + + /** + * @param string $customerType + * + * @return PaylaterPlans + */ + public function setCustomerType(string $customerType): PaylaterPlans + { + $this->customerType = $customerType; + return $this; + } + + /** + * @return InstallmentPlan[] + */ + public function getPlans(): array + { + return $this->plans; + } + + /** + * @param stdClass[] $plans + * + * @return PaylaterPlans + */ + protected function setPlans(array $plans): PaylaterPlans + { + $this->plans = $plans; + return $this; + } + + /** + * {@inheritDoc} + */ + public function getResourcePath(string $httpMethod = HttpAdapterInterface::REQUEST_GET): string + { + return 'plans' . $this->getQueryString(); + } + + /** + * Returns the query string for this resource. + * + * @return string + */ + protected function getQueryString(): string + { + return '?' . http_build_query($this->getQueryArray()); + } + + /** + * Returns the parameter array containing the values for the query string. + * + * @return array + */ + protected function getQueryArray(): array + { + $parameters = []; + if ($this->queryParameter === null) { + return $parameters; + } + + return $this->getQueryParameter()->expose(); + } + + /** + * @return PaylaterPlansQuery + */ + public function getQueryParameter(): PaylaterPlansQuery + { + return $this->queryParameter; + } + + /** + * @param PaylaterPlansQuery $queryParameter + * + * @return PaylaterPlans + */ + public function setQueryParameter(PaylaterPlansQuery $queryParameter): PaylaterPlans + { + $this->queryParameter = $queryParameter; + return $this; + } + + /** + * {@inheritDoc} + */ + public function handleResponse(stdClass $response, string $method = HttpAdapterInterface::REQUEST_GET): void + { + parent::handleResponse($response, $method); + + if (isset($response->plans)) { + $plans = []; + foreach ($response->plans as $plan) { + $instalment = new InstallmentPlan(); + $instalment->handleResponse($plan); + $plans[] = $instalment; + } + $this->setPlans($plans); + } + } +} diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index a8a11b2af..6a262241a 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -11,9 +11,11 @@ use UnzerSDK\Resources\Basket; use UnzerSDK\Resources\Customer; use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery; +use UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery; use UnzerSDK\Resources\InstalmentPlans; use UnzerSDK\Resources\Metadata; use UnzerSDK\Resources\PaylaterInstallmentPlans; +use UnzerSDK\Resources\PaylaterPlans; use UnzerSDK\Resources\Payment; use UnzerSDK\Resources\PaymentTypes\BasePaymentType; use UnzerSDK\Resources\PaymentTypes\InstallmentSecured; @@ -350,6 +352,16 @@ public function fetchPaylaterInstallmentPlans( return $this->unzer->getResourceService()->fetchResource($plans); } + /** + * {@inheritDoc} + */ + public function fetchPaylaterPlans(BasePaymentType $paymentType, PaylaterPlansQuery $query): PaylaterPlans + { + $paymentType->setParentResource($this->unzer); + $plans = (new PaylaterPlans())->setQueryParameter($query)->setParentResource($paymentType); + return $this->unzer->getResourceService()->fetchResource($plans); + } + /** * Creates the PayPage for the requested transaction method. * diff --git a/src/Unzer.php b/src/Unzer.php index d13259b55..fa36f2633 100644 --- a/src/Unzer.php +++ b/src/Unzer.php @@ -20,10 +20,12 @@ use UnzerSDK\Resources\Config; use UnzerSDK\Resources\Customer; use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery; +use UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery; use UnzerSDK\Resources\InstalmentPlans; use UnzerSDK\Resources\Keypair; use UnzerSDK\Resources\Metadata; use UnzerSDK\Resources\PaylaterInstallmentPlans; +use UnzerSDK\Resources\PaylaterPlans; use UnzerSDK\Resources\Payment; use UnzerSDK\Resources\PaymentTypes\BasePaymentType; use UnzerSDK\Resources\PaymentTypes\Paypage; @@ -60,7 +62,7 @@ class Unzer implements public const BASE_URL = 'api.unzer.com'; public const API_VERSION = ApiVersions::V1; public const SDK_TYPE = 'UnzerPHP'; - public const SDK_VERSION = '4.0.2'; + public const SDK_VERSION = '5.0.0'; /** @var string $key */ private $key; @@ -1186,6 +1188,14 @@ public function fetchPaylaterInstallmentPlans(InstallmentPlansQuery $plansReques return $this->getPaymentService()->fetchPaylaterInstallmentPlans($plansRequest); } + /** + * {@inheritDoc} + */ + public function fetchPaylaterPlans(BasePaymentType $paymentType, PaylaterPlansQuery $query): PaylaterPlans + { + return $this->getPaymentService()->fetchPaylaterPlans($paymentType, $query); + } + /** * {@inheritDoc} * diff --git a/test/Fixtures/jsonData/paylaterPlansResponseEmpty.json b/test/Fixtures/jsonData/paylaterPlansResponseEmpty.json new file mode 100644 index 000000000..2e9bdb0a1 --- /dev/null +++ b/test/Fixtures/jsonData/paylaterPlansResponseEmpty.json @@ -0,0 +1,10 @@ +{ + "id": "Tx-empty", + "amount": "99.99", + "currency": "EUR", + "plans": [], + "isSuccess": true, + "isPending": false, + "isResumed": false, + "isError": false +} diff --git a/test/Fixtures/jsonData/paylaterPlansResponseNoRates.json b/test/Fixtures/jsonData/paylaterPlansResponseNoRates.json new file mode 100644 index 000000000..93f934872 --- /dev/null +++ b/test/Fixtures/jsonData/paylaterPlansResponseNoRates.json @@ -0,0 +1,27 @@ +{ + "id": "Tx-norates", + "amount": "99.99", + "currency": "EUR", + "plans": [ + { + "numberOfRates": 3, + "totalAmount": "101.31", + "nominalInterestRate": 9.95, + "effectiveInterestRate": 10.43, + "minimumInstallmentFee": "0.00", + "secciUrl": "https://test-payment.paylater.unzer.com/payolution-payment/infoport/creditagreementdraft/Tx-norates?duration=3" + }, + { + "numberOfRates": 6, + "totalAmount": "102.60", + "nominalInterestRate": 9.95, + "effectiveInterestRate": 10.53, + "minimumInstallmentFee": "0.00", + "secciUrl": "https://test-payment.paylater.unzer.com/payolution-payment/infoport/creditagreementdraft/Tx-norates?duration=6" + } + ], + "isSuccess": true, + "isPending": false, + "isResumed": false, + "isError": false +} diff --git a/test/integration/PaymentTypes/PaylaterPlansTest.php b/test/integration/PaymentTypes/PaylaterPlansTest.php new file mode 100644 index 000000000..d7df19043 --- /dev/null +++ b/test/integration/PaymentTypes/PaylaterPlansTest.php @@ -0,0 +1,105 @@ +unzer->fetchPaylaterPlans($paymentType, $query); + + $this->assertTrue($plans->isSuccess()); + $this->assertGreaterThan(0, count($plans->getPlans())); + foreach ($plans->getPlans() as $plan) { + $this->assertNotEmpty($plan->getSecciUrl()); + } + } + + /** + * Permissive design: an unsupported payment type is passed through and rejected by PAPI. + * + * @test + */ + public function unsupportedPaymentTypeIsRejectedByApi(): void + { + // TODO: pin the concrete error code / merchant message once the endpoints are live. + $this->expectException(UnzerApiException::class); + + $query = new PaylaterPlansQuery(99.99, 'EUR', 'DE'); + $unsupportedType = new SepaDirectDebit('DE89370400440532013000'); + $this->unzer->fetchPaylaterPlans($unsupportedType, $query); + } + + /** + * Invalid input is delegated to PAPI and surfaced as an UnzerApiException. + * + * @test + * + * @dataProvider invalidQueryDataProvider + */ + public function invalidInputThrowsUnzerApiException(float $amount, string $currency, string $country): void + { + // TODO: pin the concrete error code / merchant message once the endpoints are live. + $this->expectException(UnzerApiException::class); + + $query = new PaylaterPlansQuery($amount, $currency, $country); + $this->unzer->fetchPaylaterPlans(new PaylaterInvoice(), $query); + } + + // + + public function supportedPaylaterTypeDataProvider(): array + { + return [ + 'invoice' => [new PaylaterInvoice()], + 'directDebit' => [new PaylaterDirectDebit('DE89370400440532013000', 'Peter Mustermann')], + ]; + } + + public function invalidQueryDataProvider(): array + { + return [ + 'negative amount' => [-99.99, 'EUR', 'DE'], + 'zero amount' => [0.0, 'EUR', 'DE'], + 'invalid currency' => [99.99, 'XXX', 'DE'], + 'invalid country' => [99.99, 'EUR', 'ZZ'], + ]; + } + + // +} diff --git a/test/unit/Resources/PaylaterPlansTest.php b/test/unit/Resources/PaylaterPlansTest.php new file mode 100644 index 000000000..072d8744a --- /dev/null +++ b/test/unit/Resources/PaylaterPlansTest.php @@ -0,0 +1,204 @@ +assertNull($plans->getAmount()); + $this->assertNull($plans->getCurrency()); + $this->assertNull($plans->getCountry()); + $this->assertNull($plans->getCustomerType()); + + $plans->setAmount(2.345) + ->setCurrency('USD') + ->setCountry('DE') + ->setCustomerType(CustomerTypes::B2C); + + $this->assertEquals(2.345, $plans->getAmount()); + $this->assertEquals('USD', $plans->getCurrency()); + $this->assertEquals('DE', $plans->getCountry()); + $this->assertEquals(CustomerTypes::B2C, $plans->getCustomerType()); + } + + /** + * Verify the query string is assembled from the query parameter. + * + * @test + * + * @dataProvider queryStringDataProvider + */ + public function resourcePathContainsQueryString(float $amount, string $currency, string $country, string $customerType): void + { + $query = new PaylaterPlansQuery($amount, $currency, $country, $customerType); + $plans = (new PaylaterPlans())->setQueryParameter($query); + $this->assertEquals("plans?amount={$amount}&country={$country}¤cy={$currency}&customerType={$customerType}", $plans->getResourcePath()); + } + + /** + * The deprecated InstallmentPlansQuery is still accepted as a query parameter. + * + * @test + */ + public function deprecatedQueryIsAcceptedAsQueryParameter(): void + { + $query = new InstallmentPlansQuery(100, 'EUR', 'DE'); + $plans = (new PaylaterPlans())->setQueryParameter($query); + + $this->assertSame($query, $plans->getQueryParameter()); + $this->assertEquals('plans?amount=100&country=DE¤cy=EUR&customerType=B2C', $plans->getResourcePath()); + } + + /** + * The default customer type is B2C when none is provided. + * + * @test + */ + public function defaultCustomerTypeIsB2c(): void + { + $query = new PaylaterPlansQuery(100, 'EUR', 'DE'); + $this->assertEquals(CustomerTypes::B2C, $query->getCustomerType()); + } + + /** + * Verify the Json response gets mapped properly for the supported paylater types. + * + * @test + * + * @dataProvider responseFixtureDataProvider + */ + public function jsonResponseIsHandledProperly(string $fixture): void + { + $plans = new PaylaterPlans(); + $jsonResponse = json_decode(JsonProvider::getJsonFromFile($fixture)); + $plans->handleResponse($jsonResponse); + + $this->assertEquals($jsonResponse->id, $plans->getId()); + $this->assertEquals($jsonResponse->amount, $plans->getAmount()); + $this->assertEquals($jsonResponse->currency, $plans->getCurrency()); + $this->assertCount(count($jsonResponse->plans), $plans->getPlans()); + + $this->comparePlans($jsonResponse->plans, $plans->getPlans()); + } + + /** + * Plans without installmentRates map cleanly (null rates), no error. + * + * @test + */ + public function planWithoutInstallmentRatesMapsCleanly(): void + { + $plans = new PaylaterPlans(); + $plans->handleResponse(json_decode(JsonProvider::getJsonFromFile('paylaterPlansResponseNoRates.json'))); + + $this->assertNotEmpty($plans->getPlans()); + foreach ($plans->getPlans() as $plan) { + $this->assertNotNull($plan->getSecciUrl()); + $this->assertNull($plan->getInstallmentRates()); + } + } + + /** + * An empty plans array maps to an empty list. + * + * @test + */ + public function emptyPlansArrayMapsToEmptyList(): void + { + $plans = new PaylaterPlans(); + $plans->handleResponse(json_decode(JsonProvider::getJsonFromFile('paylaterPlansResponseEmpty.json'))); + + $this->assertIsArray($plans->getPlans()); + $this->assertEmpty($plans->getPlans()); + } + + /** + * The deprecated PaylaterInstallmentPlans remains a PaylaterPlans for backward compatibility. + * + * @test + */ + public function deprecatedInstallmentPlansIsInstanceOfPaylaterPlans(): void + { + $this->assertInstanceOf(PaylaterPlans::class, new PaylaterInstallmentPlans()); + } + + // + + /** + * @param object[] $expected + * @param InstallmentPlan[] $actual + */ + private function comparePlans(array $expected, array $actual): void + { + foreach ($expected as $index => $plan) { + $this->assertEquals($plan->totalAmount ?? null, $actual[$index]->getTotalAmount()); + $this->assertEquals($plan->nominalInterestRate ?? null, $actual[$index]->getNominalInterestRate()); + $this->assertEquals($plan->effectiveInterestRate ?? null, $actual[$index]->getEffectiveInterestRate()); + $this->assertNotNull($actual[$index]->getSecciUrl()); + $this->assertEquals($plan->secciUrl, $actual[$index]->getSecciUrl()); + $this->compareRates($plan->installmentRates ?? [], $actual[$index]->getInstallmentRates() ?? []); + } + } + + /** + * @param object[] $expected + * @param InstallmentRate[] $actual + */ + 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()); + } + } + + // + + // + + public function queryStringDataProvider(): array + { + return [ + [100, 'EUR', 'DE', 'B2C'], + [100, 'EUR', 'GB', 'B2B'], + [100, 'CHF', 'CHE', 'B2C'], + ]; + } + + public function responseFixtureDataProvider(): array + { + return [ + 'invoice' => ['paylaterPlansResponse.json'], + 'directDebit' => ['paylaterPlansResponseNoRates.json'], + ]; + } + + // +} diff --git a/test/unit/Services/PaymentServiceTest.php b/test/unit/Services/PaymentServiceTest.php index ea3441cc9..7fcb3c46d 100755 --- a/test/unit/Services/PaymentServiceTest.php +++ b/test/unit/Services/PaymentServiceTest.php @@ -19,10 +19,18 @@ use UnzerSDK\Interfaces\ResourceServiceInterface; use UnzerSDK\Resources\Basket; use UnzerSDK\Resources\Customer; +use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery; +use UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery; use UnzerSDK\Resources\InstalmentPlans; use UnzerSDK\Resources\Metadata; +use UnzerSDK\Resources\PaylaterInstallmentPlans; +use UnzerSDK\Resources\PaylaterPlans; use UnzerSDK\Resources\Payment; +use UnzerSDK\Resources\PaymentTypes\BasePaymentType; use UnzerSDK\Resources\PaymentTypes\InstallmentSecured; +use UnzerSDK\Resources\PaymentTypes\PaylaterDirectDebit; +use UnzerSDK\Resources\PaymentTypes\PaylaterInstallment; +use UnzerSDK\Resources\PaymentTypes\PaylaterInvoice; use UnzerSDK\Resources\PaymentTypes\Paypage; use UnzerSDK\Resources\PaymentTypes\Paypal; use UnzerSDK\Resources\PaymentTypes\SepaDirectDebit; @@ -643,6 +651,91 @@ public function fetchInstalmentPlansWillCallFetchOnResourceService(): void // + // + + /** + * Verify fetchPaylaterPlans builds the resource path and query for the given payment type. + * + * @test + * + * @dataProvider paylaterPlansTypeDataProvider + */ + public function fetchPaylaterPlansResolvesResourcePathPerType(BasePaymentType $paymentType, string $segment): void + { + $unzer = new Unzer('s-priv-1234'); + /** @var MockObject|ResourceService $resourceSrvMock */ + $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->setConstructorArgs(['unzer' => $unzer])->setMethods(['fetchResource'])->getMock(); + $unzer->setResourceService($resourceSrvMock); + + $query = new PaylaterPlansQuery(99.99, 'EUR', 'DE', 'B2B'); + + $resourceSrvMock->expects($this->once())->method('fetchResource') + ->with($this->callback(static function ($param) use ($paymentType, $segment, $query) { + return $param instanceof PaylaterPlans && + $param->getParentResource() === $paymentType && + $param->getQueryParameter() === $query && + $param->getUri() === "/types/{$segment}/plans?amount=99.99&country=DE¤cy=EUR&customerType=B2B"; + }))->willReturn(new PaylaterPlans()); + + $result = $unzer->getPaymentService()->fetchPaylaterPlans($paymentType, $query); + $this->assertInstanceOf(PaylaterPlans::class, $result); + } + + /** + * Verify the default customer type B2C is applied to the query. + * + * @test + */ + public function fetchPaylaterPlansAppliesDefaultCustomerType(): void + { + $unzer = new Unzer('s-priv-1234'); + /** @var MockObject|ResourceService $resourceSrvMock */ + $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->setConstructorArgs(['unzer' => $unzer])->setMethods(['fetchResource'])->getMock(); + $unzer->setResourceService($resourceSrvMock); + + $query = new PaylaterPlansQuery(10.0, 'EUR', 'DE'); + + $resourceSrvMock->expects($this->once())->method('fetchResource') + ->with($this->callback(static function ($param) { + $query = $param->getQueryParameter(); + return $param instanceof PaylaterPlans && + $query->getAmount() === 10.0 && + $query->getCurrency() === 'EUR' && + $query->getCountry() === 'DE' && + $query->getCustomerType() === 'B2C' && + $param->getUri() === '/types/paylater-invoice/plans?amount=10&country=DE¤cy=EUR&customerType=B2C'; + }))->willReturn(new PaylaterPlans()); + + $unzer->getPaymentService()->fetchPaylaterPlans(new PaylaterInvoice(), $query); + } + + /** + * Verify the deprecated fetchPaylaterInstallmentPlans still targets the installment endpoint and return type. + * + * @test + */ + public function fetchPaylaterInstallmentPlansRemainsBackwardCompatible(): void + { + $unzer = new Unzer('s-priv-1234'); + /** @var MockObject|ResourceService $resourceSrvMock */ + $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->setConstructorArgs(['unzer' => $unzer])->setMethods(['fetchResource'])->getMock(); + $unzer->setResourceService($resourceSrvMock); + + $query = new InstallmentPlansQuery(99.99, 'EUR', 'DE'); + + $resourceSrvMock->expects($this->once())->method('fetchResource') + ->with($this->callback(static function ($param) { + return $param instanceof PaylaterInstallmentPlans && + $param->getParentResource() instanceof PaylaterInstallment && + $param->getUri() === '/types/paylater-installment/plans?amount=99.99&country=DE¤cy=EUR&customerType=B2C'; + }))->willReturn(new PaylaterInstallmentPlans()); + + $result = $unzer->getPaymentService()->fetchPaylaterInstallmentPlans($query); + $this->assertInstanceOf(PaylaterInstallmentPlans::class, $result); + } + + // + // /** @@ -657,6 +750,18 @@ public function card3dsDataProvider(): array ]; } + /** + * @return array + */ + public function paylaterPlansTypeDataProvider(): array + { + return [ + 'installment' => [new PaylaterInstallment(), 'paylater-installment'], + 'invoice' => [new PaylaterInvoice(), 'paylater-invoice'], + 'directDebit' => [new PaylaterDirectDebit(), 'paylater-direct-debit'], + ]; + } + /** * @return array */ From 3b769bb78bc462c08c3b30b9d1f47e0390c41469 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:45:25 +0100 Subject: [PATCH 02/10] [CC-4346] Target 4.1.0 release instead of 5.0.0 Ship the paylater /plans support in the 4.1.0 release: set SDK_VERSION to 4.1.0 and move the Added/Deprecated CHANGELOG entries under a new 4.1.0 section, leaving the pending 5.0.0 (PHP 8.1 removal) content untouched. Co-Authored-By: Claude Opus 4.8 (1M context) --- CHANGELOG.md | 10 ++++++---- src/Unzer.php | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 713de6ad6..5e3127a15 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ 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) +### 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). + +## [4.1.0](https://github.com/unzerdev/php-sdk/compare/4.0.2..4.1.0) + ### Added * `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`. @@ -16,10 +22,6 @@ to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). * `\UnzerSDK\Resources\PaylaterInstallmentPlans` (use `\UnzerSDK\Resources\PaylaterPlans`) and `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery` (use `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery`). Both remain as subclasses for backward compatibility. `Unzer::fetchPaylaterInstallmentPlans()` is unchanged. -### 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). - ## [4.0.2](https://github.com/unzerdev/php-sdk/compare/4.0.1..4.0.2) ### Changed diff --git a/src/Unzer.php b/src/Unzer.php index fa36f2633..b7c783785 100644 --- a/src/Unzer.php +++ b/src/Unzer.php @@ -62,7 +62,7 @@ class Unzer implements public const BASE_URL = 'api.unzer.com'; public const API_VERSION = ApiVersions::V1; public const SDK_TYPE = 'UnzerPHP'; - public const SDK_VERSION = '5.0.0'; + public const SDK_VERSION = '4.1.0'; /** @var string $key */ private $key; From e7b26fcf53fb69b8ac69f845131103de6e87e37b Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:00:20 +0100 Subject: [PATCH 03/10] [CC-4346] Route paylater plans by type name even for identified types Address Copilot review: an already-created/fetched payment type has an id, and for GET BasePaymentType::getResourcePath() omits the type name while getUri() appends the id, so fetchPaylaterPlans() routed to types//plans instead of types//plans. Route via an identity-free clone of the supplied type so the URL is always correct; the caller's instance (and its id) is left untouched. Extend the routing test to cover identified types. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/Services/PaymentService.php | 6 ++++-- test/unit/Services/PaymentServiceTest.php | 11 +++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index 6a262241a..78eb3c543 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -357,8 +357,10 @@ public function fetchPaylaterInstallmentPlans( */ public function fetchPaylaterPlans(BasePaymentType $paymentType, PaylaterPlansQuery $query): PaylaterPlans { - $paymentType->setParentResource($this->unzer); - $plans = (new PaylaterPlans())->setQueryParameter($query)->setParentResource($paymentType); + // Route via an identity-free copy so an already-identified payment type still resolves to + // types//plans instead of types//plans. The caller's instance stays untouched. + $plansParent = (clone $paymentType)->setId(null)->setParentResource($this->unzer); + $plans = (new PaylaterPlans())->setQueryParameter($query)->setParentResource($plansParent); return $this->unzer->getResourceService()->fetchResource($plans); } diff --git a/test/unit/Services/PaymentServiceTest.php b/test/unit/Services/PaymentServiceTest.php index 7fcb3c46d..6a667a9e0 100755 --- a/test/unit/Services/PaymentServiceTest.php +++ b/test/unit/Services/PaymentServiceTest.php @@ -654,7 +654,8 @@ public function fetchInstalmentPlansWillCallFetchOnResourceService(): void // /** - * Verify fetchPaylaterPlans builds the resource path and query for the given payment type. + * Verify fetchPaylaterPlans builds the resource path and query for the given payment type, + * both for fresh types and for already-identified ones (which must still route by type name). * * @test * @@ -667,18 +668,24 @@ public function fetchPaylaterPlansResolvesResourcePathPerType(BasePaymentType $p $resourceSrvMock = $this->getMockBuilder(ResourceService::class)->setConstructorArgs(['unzer' => $unzer])->setMethods(['fetchResource'])->getMock(); $unzer->setResourceService($resourceSrvMock); + // Pre-set an id to emulate a previously created/fetched payment type. + $paymentType->setId('s-pit-identified'); $query = new PaylaterPlansQuery(99.99, 'EUR', 'DE', 'B2B'); $resourceSrvMock->expects($this->once())->method('fetchResource') ->with($this->callback(static function ($param) use ($paymentType, $segment, $query) { return $param instanceof PaylaterPlans && - $param->getParentResource() === $paymentType && + // Routing uses an identity-free copy, not the caller's instance. + $param->getParentResource() !== $paymentType && + $param->getParentResource() instanceof BasePaymentType && $param->getQueryParameter() === $query && $param->getUri() === "/types/{$segment}/plans?amount=99.99&country=DE¤cy=EUR&customerType=B2B"; }))->willReturn(new PaylaterPlans()); $result = $unzer->getPaymentService()->fetchPaylaterPlans($paymentType, $query); $this->assertInstanceOf(PaylaterPlans::class, $result); + // The caller's payment type must stay untouched (id preserved). + $this->assertEquals('s-pit-identified', $paymentType->getId()); } /** From 805da8c285e74ecba7547d1ad965a9c8291ecddd Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Mon, 23 Nov 2026 14:06:41 +0100 Subject: [PATCH 04/10] [CC-4346] Preserve PaylaterInstallmentPlans setter return type for BC Address Copilot review: override setQueryParameter() on the deprecated PaylaterInstallmentPlans alias so it keeps returning PaylaterInstallmentPlans (covariant narrowing) instead of the inherited PaylaterPlans, restoring the original fluent contract. The parameter is widened to PaylaterPlansQuery, which is backward compatible since InstallmentPlansQuery extends it. Clarify the BC boundary in the CHANGELOG. Co-Authored-By: Claude Opus 4.8 (1M context) --- CHANGELOG.md | 2 +- src/Resources/PaylaterInstallmentPlans.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e3127a15..77a235ae1 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ### Deprecated -* `\UnzerSDK\Resources\PaylaterInstallmentPlans` (use `\UnzerSDK\Resources\PaylaterPlans`) and `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery` (use `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery`). Both remain as subclasses for backward compatibility. `Unzer::fetchPaylaterInstallmentPlans()` is unchanged. +* `\UnzerSDK\Resources\PaylaterInstallmentPlans` (use `\UnzerSDK\Resources\PaylaterPlans`) and `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery` (use `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery`). Both remain as subclasses for backward compatibility. `Unzer::fetchPaylaterInstallmentPlans()` is unchanged, and `PaylaterInstallmentPlans::setQueryParameter()` keeps returning `PaylaterInstallmentPlans`. The inherited setters now accept the wider `PaylaterPlansQuery` (an `InstallmentPlansQuery` still works, as it extends it). ## [4.0.2](https://github.com/unzerdev/php-sdk/compare/4.0.1..4.0.2) diff --git a/src/Resources/PaylaterInstallmentPlans.php b/src/Resources/PaylaterInstallmentPlans.php index 98445ecb9..a68ff19f7 100644 --- a/src/Resources/PaylaterInstallmentPlans.php +++ b/src/Resources/PaylaterInstallmentPlans.php @@ -2,6 +2,8 @@ namespace UnzerSDK\Resources; +use UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery; + /** * Resource used to fetch instalment plans for the Paylater Installment payment method specified as parent resource. * Please use Unzer methods to fetch the list of instalment plans (e.g. Unzer::fetchPaylaterInstallmentPlans(...)). @@ -13,4 +15,16 @@ */ class PaylaterInstallmentPlans extends PaylaterPlans { + /** + * Keeps the original fluent return type (PaylaterInstallmentPlans) for backward compatibility. + * + * @param PaylaterPlansQuery $queryParameter + * + * @return PaylaterInstallmentPlans + */ + public function setQueryParameter(PaylaterPlansQuery $queryParameter): PaylaterInstallmentPlans + { + parent::setQueryParameter($queryParameter); + return $this; + } } From c5dd0c6f157f8fcd18c03e01012f4ddf9efe5bca Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:46:44 +0100 Subject: [PATCH 05/10] [CC-4346] Decouple legacy paylater plan classes from the generalized ones Resolve the backward-compatibility regression Copilot raised: making InstallmentPlansQuery/PaylaterInstallmentPlans extend the new generalized classes silently widened their inherited method signatures (return types, and the setQueryParameter parameter), breaking strict callers and any third-party subclass override. Restore both legacy classes to their original standalone definitions (now only marked @deprecated) with no inheritance from PaylaterPlans/PaylaterPlansQuery - verified byte-for-byte against origin/main (only the @deprecated docblock differs). Drop the obsolete covariant setQueryParameter override. The new PaylaterPlans/PaylaterPlansQuery stay independent; no new code relies on the legacy types being instances of the new ones. Add reflection-based signature-pin tests plus a fluent-chaining test for the legacy classes, and remove the two unit tests that depended on the old inheritance. Update the CHANGELOG to describe the legacy classes as unchanged standalone deprecated aliases. Co-Authored-By: Claude Opus 4.8 (1M context) --- CHANGELOG.md | 2 +- .../Paylater/InstallmentPlansQuery.php | 99 ++++++++- src/Resources/PaylaterInstallmentPlans.php | 193 +++++++++++++++++- .../PaylaterInstallmentPlansTest.php | 69 +++++++ test/unit/Resources/PaylaterPlansTest.php | 26 --- 5 files changed, 353 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77a235ae1..812161c89 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ### Deprecated -* `\UnzerSDK\Resources\PaylaterInstallmentPlans` (use `\UnzerSDK\Resources\PaylaterPlans`) and `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery` (use `\UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery`). Both remain as subclasses for backward compatibility. `Unzer::fetchPaylaterInstallmentPlans()` is unchanged, and `PaylaterInstallmentPlans::setQueryParameter()` keeps returning `PaylaterInstallmentPlans`. The inherited setters now accept the wider `PaylaterPlansQuery` (an `InstallmentPlansQuery` still works, as it extends it). +* `\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. ## [4.0.2](https://github.com/unzerdev/php-sdk/compare/4.0.1..4.0.2) diff --git a/src/Resources/EmbeddedResources/Paylater/InstallmentPlansQuery.php b/src/Resources/EmbeddedResources/Paylater/InstallmentPlansQuery.php index ba5e58635..c34cf1664 100644 --- a/src/Resources/EmbeddedResources/Paylater/InstallmentPlansQuery.php +++ b/src/Resources/EmbeddedResources/Paylater/InstallmentPlansQuery.php @@ -2,6 +2,9 @@ namespace UnzerSDK\Resources\EmbeddedResources\Paylater; +use UnzerSDK\Constants\CustomerTypes; +use UnzerSDK\Resources\AbstractUnzerResource; + /** * This class contains the query properties which are used to fetch paylater installment plans. * @@ -10,6 +13,100 @@ * @link https://docs.unzer.com/ * */ -class InstallmentPlansQuery extends PaylaterPlansQuery +class InstallmentPlansQuery extends AbstractUnzerResource { + protected float $amount; + protected string $currency; + protected string $country; + protected string $customerType; + + /** + * @param float $amount + * @param string $currency + * @param string $country + * @param string $customerType + */ + public function __construct(float $amount, string $currency, string $country, string $customerType = CustomerTypes::B2C) + { + $this->amount = $amount; + $this->currency = $currency; + $this->country = $country; + $this->customerType = $customerType; + } + + /** + * @return float + */ + public function getAmount(): float + { + return $this->amount; + } + + /** + * @param float $amount + * + * @return InstallmentPlansQuery + */ + public function setAmount(float $amount): InstallmentPlansQuery + { + $this->amount = $amount; + return $this; + } + + /** + * @return string + */ + public function getCurrency(): string + { + return $this->currency; + } + + /** + * @param string $currency + * + * @return InstallmentPlansQuery + */ + public function setCurrency(string $currency): InstallmentPlansQuery + { + $this->currency = $currency; + return $this; + } + + /** + * @return string + */ + public function getCountry(): string + { + return $this->country; + } + + /** + * @param string $country + * + * @return InstallmentPlansQuery + */ + public function setCountry(string $country): InstallmentPlansQuery + { + $this->country = $country; + return $this; + } + + /** + * @return string + */ + public function getCustomerType(): string + { + return $this->customerType; + } + + /** + * @param string $customerType + * + * @return InstallmentPlansQuery + */ + public function setCustomerType(string $customerType): InstallmentPlansQuery + { + $this->customerType = $customerType; + return $this; + } } diff --git a/src/Resources/PaylaterInstallmentPlans.php b/src/Resources/PaylaterInstallmentPlans.php index a68ff19f7..6f559f8f7 100644 --- a/src/Resources/PaylaterInstallmentPlans.php +++ b/src/Resources/PaylaterInstallmentPlans.php @@ -2,29 +2,206 @@ namespace UnzerSDK\Resources; -use UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery; +use UnzerSDK\Adapter\HttpAdapterInterface; +use stdClass; +use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery; +use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan; +use UnzerSDK\Traits\HasStates; /** - * Resource used to fetch instalment plans for the Paylater Installment payment method specified as parent resource. - * Please use Unzer methods to fetch the list of instalment plans (e.g. Unzer::fetchPaylaterInstallmentPlans(...)). + * Resource used to fetch instalment plans for Installment Secured payment method specified as parent resource. + * Please use Unzer methods to fetch the list of instalment plans + * (e.g. Unzer::fetchInstallmentPlans(...)). * * @deprecated since the introduction of the generalized paylater plans endpoint. Use * {@see PaylaterPlans} together with Unzer::fetchPaylaterPlans() instead. * @link https://docs.unzer.com/ * */ -class PaylaterInstallmentPlans extends PaylaterPlans +class PaylaterInstallmentPlans extends AbstractUnzerResource { + use HasStates; + + /** @var float */ + private $amount; + + /** @var string */ + private $currency; + + /** @var string */ + private $country; + + /** @var string */ + private $customerType; + + /** @var InstallmentPlan[] $plans */ + private $plans = []; + + /** @var InstallmentPlansQuery Query parameter used to fetch available installment plans. */ + private $queryParameter; + + /** + * @return float + */ + public function getAmount(): ?float + { + return $this->amount; + } + + /** + * @param float $amount + * + * @return PaylaterInstallmentPlans + */ + public function setAmount(float $amount): PaylaterInstallmentPlans + { + $this->amount = $amount; + return $this; + } + + /** + * @return string + */ + public function getCurrency(): ?string + { + return $this->currency; + } + + /** + * @param string $currency + * + * @return InstalmentPlans + */ + public function setCurrency(string $currency): PaylaterInstallmentPlans + { + $this->currency = $currency; + return $this; + } + + /** + * @return string + */ + public function getCountry(): ?string + { + return $this->country; + } + + /** + * @param string $country + * + * @return PaylaterInstallmentPlans + */ + public function setCountry(string $country): PaylaterInstallmentPlans + { + $this->country = $country; + return $this; + } + + /** + * @return string + */ + public function getCustomerType(): ?string + { + return $this->customerType; + } + /** - * Keeps the original fluent return type (PaylaterInstallmentPlans) for backward compatibility. + * @param string $customerType * - * @param PaylaterPlansQuery $queryParameter + * @return PaylaterInstallmentPlans + */ + public function setCustomerType(string $customerType): PaylaterInstallmentPlans + { + $this->customerType = $customerType; + return $this; + } + + /** + * @return InstallmentPlan[] + */ + public function getPlans(): array + { + return $this->plans; + } + + /** + * @param stdClass[] $plans + * + * @return InstalmentPlans + */ + protected function setPlans(array $plans): PaylaterInstallmentPlans + { + $this->plans = $plans; + return $this; + } + + /** + * {@inheritDoc} + */ + public function getResourcePath(string $httpMethod = HttpAdapterInterface::REQUEST_GET): string + { + return 'plans' . $this->getQueryString(); + } + + /** + * Returns the query string for this resource. + * + * @return string + */ + protected function getQueryString(): string + { + return '?' . http_build_query($this->getQueryArray()); + } + + /** + * Returns the parameter array containing the values for the query string. + * + * @return array + */ + protected function getQueryArray(): array + { + $parameters = []; + if ($this->queryParameter === null) { + return $parameters; + } + + return $this->getQueryParameter()->expose(); + } + + /** + * @return InstallmentPlansQuery + */ + public function getQueryParameter(): InstallmentPlansQuery + { + return $this->queryParameter; + } + + /** + * @param InstallmentPlansQuery $queryParameter * * @return PaylaterInstallmentPlans */ - public function setQueryParameter(PaylaterPlansQuery $queryParameter): PaylaterInstallmentPlans + public function setQueryParameter(InstallmentPlansQuery $queryParameter): PaylaterInstallmentPlans { - parent::setQueryParameter($queryParameter); + $this->queryParameter = $queryParameter; return $this; } + + /** + * {@inheritDoc} + */ + public function handleResponse(stdClass $response, string $method = HttpAdapterInterface::REQUEST_GET): void + { + parent::handleResponse($response, $method); + + if (isset($response->plans)) { + $plans = []; + foreach ($response->plans as $plan) { + $instalment = new InstallmentPlan(); + $instalment->handleResponse($plan); + $plans[] = $instalment; + } + $this->setPlans($plans); + } + } } diff --git a/test/unit/Resources/PaylaterInstallmentPlansTest.php b/test/unit/Resources/PaylaterInstallmentPlansTest.php index 607189c56..b52f34c51 100644 --- a/test/unit/Resources/PaylaterInstallmentPlansTest.php +++ b/test/unit/Resources/PaylaterInstallmentPlansTest.php @@ -11,6 +11,7 @@ namespace UnzerSDK\test\unit\Resources; +use ReflectionMethod; use UnzerSDK\Constants\CustomerTypes; use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery; use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentRate; @@ -21,6 +22,50 @@ class PaylaterInstallmentPlansTest extends BasePaymentTest { + /** + * These deprecated classes are standalone aliases and must keep their original public + * signatures (no inheritance from the generalized PaylaterPlans/PaylaterPlansQuery). + * + * @test + * + * @dataProvider legacySignatureDataProvider + * + * @param class-string $class + */ + public function legacyPublicSignaturesAreUnchanged(string $class, string $method, ?string $expectedParamType, string $expectedReturnType): void + { + $reflection = new ReflectionMethod($class, $method); + + $returnType = $reflection->getReturnType(); + $this->assertNotNull($returnType); + $this->assertEquals($expectedReturnType, $returnType->getName()); + + if ($expectedParamType !== null) { + $params = $reflection->getParameters(); + $this->assertNotEmpty($params); + $this->assertEquals($expectedParamType, $params[0]->getType()->getName()); + } + } + + /** + * Verify the legacy fluent setters keep returning their own type for chaining. + * + * @test + */ + public function legacyFluentSettersReturnOwnType(): void + { + $query = (new InstallmentPlansQuery(100, 'EUR', 'DE')) + ->setAmount(1.0) + ->setCurrency('USD') + ->setCountry('CH') + ->setCustomerType(CustomerTypes::B2B); + $this->assertInstanceOf(InstallmentPlansQuery::class, $query); + + $plans = (new PaylaterInstallmentPlans())->setQueryParameter($query); + $this->assertInstanceOf(PaylaterInstallmentPlans::class, $plans); + $this->assertInstanceOf(InstallmentPlansQuery::class, $plans->getQueryParameter()); + } + /** * Verify getters and setters. * @@ -144,5 +189,29 @@ public function verifyQueryStringDP(): array [100, 'CHF', 'CHE', 'B2C'], ]; } + + /** + * Pins the original (pre-generalization) public signatures of the deprecated legacy classes. + * + * @return array + */ + public function legacySignatureDataProvider(): array + { + $query = InstallmentPlansQuery::class; + $plans = PaylaterInstallmentPlans::class; + + return [ + 'query setAmount' => [$query, 'setAmount', 'float', $query], + 'query setCurrency' => [$query, 'setCurrency', 'string', $query], + 'query setCountry' => [$query, 'setCountry', 'string', $query], + 'query setCustomerType' => [$query, 'setCustomerType', 'string', $query], + 'plans setAmount' => [$plans, 'setAmount', 'float', $plans], + 'plans setCurrency' => [$plans, 'setCurrency', 'string', $plans], + 'plans setCountry' => [$plans, 'setCountry', 'string', $plans], + 'plans setCustomerType' => [$plans, 'setCustomerType', 'string', $plans], + 'plans getQueryParameter' => [$plans, 'getQueryParameter', null, $query], + 'plans setQueryParameter' => [$plans, 'setQueryParameter', $query, $plans], + ]; + } // } diff --git a/test/unit/Resources/PaylaterPlansTest.php b/test/unit/Resources/PaylaterPlansTest.php index 072d8744a..394e73c5a 100644 --- a/test/unit/Resources/PaylaterPlansTest.php +++ b/test/unit/Resources/PaylaterPlansTest.php @@ -13,10 +13,8 @@ use UnzerSDK\Constants\CustomerTypes; use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan; -use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery; use UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentRate; use UnzerSDK\Resources\EmbeddedResources\Paylater\PaylaterPlansQuery; -use UnzerSDK\Resources\PaylaterInstallmentPlans; use UnzerSDK\Resources\PaylaterPlans; use UnzerSDK\test\BasePaymentTest; use UnzerSDK\test\Fixtures\JsonProvider; @@ -62,20 +60,6 @@ public function resourcePathContainsQueryString(float $amount, string $currency, $this->assertEquals("plans?amount={$amount}&country={$country}¤cy={$currency}&customerType={$customerType}", $plans->getResourcePath()); } - /** - * The deprecated InstallmentPlansQuery is still accepted as a query parameter. - * - * @test - */ - public function deprecatedQueryIsAcceptedAsQueryParameter(): void - { - $query = new InstallmentPlansQuery(100, 'EUR', 'DE'); - $plans = (new PaylaterPlans())->setQueryParameter($query); - - $this->assertSame($query, $plans->getQueryParameter()); - $this->assertEquals('plans?amount=100&country=DE¤cy=EUR&customerType=B2C', $plans->getResourcePath()); - } - /** * The default customer type is B2C when none is provided. * @@ -139,16 +123,6 @@ public function emptyPlansArrayMapsToEmptyList(): void $this->assertEmpty($plans->getPlans()); } - /** - * The deprecated PaylaterInstallmentPlans remains a PaylaterPlans for backward compatibility. - * - * @test - */ - public function deprecatedInstallmentPlansIsInstanceOfPaylaterPlans(): void - { - $this->assertInstanceOf(PaylaterPlans::class, new PaylaterInstallmentPlans()); - } - // /** From 3a6f99bf704ec152c02a50282a0d7ad3cf9ba757 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Mon, 23 Nov 2026 15:56:01 +0100 Subject: [PATCH 06/10] [CC-4346] Add end-to-end fetch+map tests for legacy and generic plan flows Stub the HTTP layer (types/paylater-/plans) and assert mapping incl. non-null secciUrl: - Legacy fetchPaylaterInstallmentPlans(InstallmentPlansQuery) returns a PaylaterInstallmentPlans with mapped plans (original-flow regression proof). - Generic fetchPaylaterPlans() exercised for all three plan-supporting types (PaylaterInstallment, PaylaterInvoice, PaylaterDirectDebit), each hitting its own types/paylater-/plans URL and mapping plans with secciUrl. Pre-existing installment plan tests are left untouched and still pass. Co-Authored-By: Claude Opus 4.8 (1M context) --- test/unit/Services/PaymentServiceTest.php | 68 +++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/test/unit/Services/PaymentServiceTest.php b/test/unit/Services/PaymentServiceTest.php index 6a667a9e0..816e96bec 100755 --- a/test/unit/Services/PaymentServiceTest.php +++ b/test/unit/Services/PaymentServiceTest.php @@ -42,9 +42,11 @@ use UnzerSDK\Resources\TransactionTypes\Sca; use UnzerSDK\Resources\TransactionTypes\Shipment; use UnzerSDK\Services\CancelService; +use UnzerSDK\Services\HttpService; use UnzerSDK\Services\PaymentService; use UnzerSDK\Services\ResourceService; use UnzerSDK\test\BasePaymentTest; +use UnzerSDK\test\Fixtures\JsonProvider; use PHPUnit\Framework\MockObject\MockObject; use function in_array; @@ -741,6 +743,72 @@ public function fetchPaylaterInstallmentPlansRemainsBackwardCompatible(): void $this->assertInstanceOf(PaylaterInstallmentPlans::class, $result); } + /** + * End-to-end: the generic fetchPaylaterPlans() hits types/paylater-/plans and maps the + * response (incl. a non-null secciUrl per plan) for all three plan-supporting payment types. + * + * @test + * + * @dataProvider paylaterPlansTypeDataProvider + */ + public function fetchPaylaterPlansFetchesAndMapsPlansPerType(BasePaymentType $paymentType, string $segment): void + { + $unzer = new Unzer('s-priv-1234'); + $unzer->setHttpService($this->stubPlansHttpService("types/{$segment}/plans")); + + $query = new PaylaterPlansQuery(99.99, 'EUR', 'DE'); + $plans = $unzer->fetchPaylaterPlans($paymentType, $query); + + $this->assertInstanceOf(PaylaterPlans::class, $plans); + $this->assertNotEmpty($plans->getPlans()); + foreach ($plans->getPlans() as $plan) { + $this->assertNotNull($plan->getSecciUrl()); + } + } + + /** + * End-to-end regression: the legacy fetchPaylaterInstallmentPlans() still hits + * types/paylater-installment/plans and maps to a PaylaterInstallmentPlans with secciUrl. + * + * @test + */ + public function fetchPaylaterInstallmentPlansFetchesAndMapsPlansEndToEnd(): void + { + $unzer = new Unzer('s-priv-1234'); + $unzer->setHttpService($this->stubPlansHttpService('types/paylater-installment/plans')); + + $plans = $unzer->fetchPaylaterInstallmentPlans(new InstallmentPlansQuery(99.99, 'EUR', 'DE')); + + $this->assertInstanceOf(PaylaterInstallmentPlans::class, $plans); + $this->assertNotEmpty($plans->getPlans()); + foreach ($plans->getPlans() as $plan) { + $this->assertNotNull($plan->getSecciUrl()); + } + } + + // + + // + + /** + * Builds an HttpService stub that asserts the plans endpoint URL and returns the shared plans fixture. + * + * @param string $expectedUriPart The expected types/paylater-/plans path fragment. + * + * @return MockObject|HttpService + */ + private function stubPlansHttpService(string $expectedUriPart): HttpService + { + $httpServiceMock = $this->getMockBuilder(HttpService::class) + ->disableOriginalConstructor()->onlyMethods(['send'])->getMock(); + $httpServiceMock->expects($this->once())->method('send') + ->with($this->callback(static function ($uri) use ($expectedUriPart) { + return is_string($uri) && str_contains($uri, $expectedUriPart); + })) + ->willReturn(JsonProvider::getJsonFromFile('paylaterPlansResponse.json')); + return $httpServiceMock; + } + // // From ef56a8b120122eeda58f723f5091d91cfcdab622 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:11:38 +0100 Subject: [PATCH 07/10] [CC-4346] Un-gate paylater plans integration tests (endpoints live) The invoice/direct-debit /plans endpoints are live, so remove the @group skip from test/integration/PaymentTypes/PaylaterPlansTest.php; the tests now run against the sandbox via the repo's standard integration credentials, like the existing installment integration test. Sandbox credentials are not available in the dev environment (no UNZER_PAPI_TEST_PRIVATE_KEY_DEFAULT), so the concrete UnzerApiException codes could not be observed here. Kept the exception-type assertions and replaced the TODO placeholders with notes to confirm and pin the exact getCode()/message from the first CI run. No codes were guessed. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../PaymentTypes/PaylaterPlansTest.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/test/integration/PaymentTypes/PaylaterPlansTest.php b/test/integration/PaymentTypes/PaylaterPlansTest.php index d7df19043..257a32d9d 100644 --- a/test/integration/PaymentTypes/PaylaterPlansTest.php +++ b/test/integration/PaymentTypes/PaylaterPlansTest.php @@ -6,11 +6,10 @@ * This class defines integration tests to verify the generalized paylater /plans endpoint * (Unzer::fetchPaylaterPlans) for Paylater Invoice and Paylater Direct Debit (CCD2). * - * These tests require the PAPI `types/paylater-invoice/plans` and `types/paylater-direct-debit/plans` - * endpoints (CC-4014) to be live, plus sandbox credentials. They are therefore excluded from the - * default run via `@group skip`. Remove the group once the endpoints leave WIP. - * - * @group skip + * The PAPI `types/paylater-invoice/plans` and `types/paylater-direct-debit/plans` endpoints (CC-4014) + * are now live; these tests run against the sandbox using the repository's standard integration + * credentials (UNZER_PAPI_TEST_PRIVATE_KEY_DEFAULT), exactly like the existing installment integration + * test. They are no longer gated. * * @link https://docs.unzer.com/ * @@ -57,7 +56,9 @@ public function plansAreFetchableWithSecciUrl(BasePaymentType $paymentType): voi */ public function unsupportedPaymentTypeIsRejectedByApi(): void { - // TODO: pin the concrete error code / merchant message once the endpoints are live. + // NOTE: the concrete getCode()/merchant message could not be observed in the dev environment + // (no sandbox credentials). Confirm the exact code from the first CI run and tighten this + // assertion (e.g. ->expectExceptionCode(...)) with the observed value. $this->expectException(UnzerApiException::class); $query = new PaylaterPlansQuery(99.99, 'EUR', 'DE'); @@ -74,7 +75,9 @@ public function unsupportedPaymentTypeIsRejectedByApi(): void */ public function invalidInputThrowsUnzerApiException(float $amount, string $currency, string $country): void { - // TODO: pin the concrete error code / merchant message once the endpoints are live. + // NOTE: the concrete getCode()/merchant message per case could not be observed in the dev + // environment (no sandbox credentials). Confirm the exact code(s) from the first CI run and + // tighten this assertion (e.g. ->expectExceptionCode(...)) with the observed value(s). $this->expectException(UnzerApiException::class); $query = new PaylaterPlansQuery($amount, $currency, $country); From a1394cac7fa1d5ea8f8be3c7fadfff84dad800b6 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:19:19 +0100 Subject: [PATCH 08/10] [CC-4346] Assert populated error generically in plans integration tests Per review decision, do not pin specific PAPI error codes (too brittle). For the unsupported-type and invalid-input cases, assert UnzerApiException with a non-empty getMerchantMessage() instead of a specific getCode(). Keep an illustrative (non-asserted) comment documenting the observed sandbox behaviour for an unsupported type. Happy-path assertions unchanged; tests stay un-gated. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../PaymentTypes/PaylaterPlansTest.php | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/test/integration/PaymentTypes/PaylaterPlansTest.php b/test/integration/PaymentTypes/PaylaterPlansTest.php index 257a32d9d..5d3e32de1 100644 --- a/test/integration/PaymentTypes/PaylaterPlansTest.php +++ b/test/integration/PaymentTypes/PaylaterPlansTest.php @@ -56,14 +56,18 @@ public function plansAreFetchableWithSecciUrl(BasePaymentType $paymentType): voi */ public function unsupportedPaymentTypeIsRejectedByApi(): void { - // NOTE: the concrete getCode()/merchant message could not be observed in the dev environment - // (no sandbox credentials). Confirm the exact code from the first CI run and tighten this - // assertion (e.g. ->expectExceptionCode(...)) with the observed value. - $this->expectException(UnzerApiException::class); - $query = new PaylaterPlansQuery(99.99, 'EUR', 'DE'); $unsupportedType = new SepaDirectDebit('DE89370400440532013000'); - $this->unzer->fetchPaylaterPlans($unsupportedType, $query); + + // Example observed sandbox behaviour (illustrative only, not asserted - codes/messages may change): + // code API.720.100.001, merchantMessage "The given payment method plans is not found.", + // customerMessage "Invalid payment method. Please contact us for more information." + try { + $this->unzer->fetchPaylaterPlans($unsupportedType, $query); + $this->fail('Expected ' . UnzerApiException::class . ' was not thrown.'); + } catch (UnzerApiException $e) { + $this->assertNotEmpty($e->getMerchantMessage()); + } } /** @@ -75,13 +79,14 @@ public function unsupportedPaymentTypeIsRejectedByApi(): void */ public function invalidInputThrowsUnzerApiException(float $amount, string $currency, string $country): void { - // NOTE: the concrete getCode()/merchant message per case could not be observed in the dev - // environment (no sandbox credentials). Confirm the exact code(s) from the first CI run and - // tighten this assertion (e.g. ->expectExceptionCode(...)) with the observed value(s). - $this->expectException(UnzerApiException::class); - $query = new PaylaterPlansQuery($amount, $currency, $country); - $this->unzer->fetchPaylaterPlans(new PaylaterInvoice(), $query); + + try { + $this->unzer->fetchPaylaterPlans(new PaylaterInvoice(), $query); + $this->fail('Expected ' . UnzerApiException::class . ' was not thrown.'); + } catch (UnzerApiException $e) { + $this->assertNotEmpty($e->getMerchantMessage()); + } } // From 538150b447cc452156726f67a05bb85fa06b4f2a Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Mon, 23 Nov 2026 17:08:40 +0100 Subject: [PATCH 09/10] [CC-4346] Expose minimumInstallmentFee on InstallmentPlan The API sends minimumInstallmentFee (decimal string, e.g. "0.00") on each plan, but InstallmentPlan had no property for it so updateValues() dropped it. Add a $minimumInstallmentFee field with getMinimumInstallmentFee()/setMinimumInstallmentFee() mirroring the untyped totalAmount style. Purely additive, so it is exposed for both fetchPaylaterInstallmentPlans and fetchPaylaterPlans with no BC impact. Set a non-zero fee on a fixture plan and assert getMinimumInstallmentFee() maps for both the new and legacy plan flows. Document the addition in the CHANGELOG. Co-Authored-By: Claude Opus 4.8 (1M context) --- CHANGELOG.md | 1 + .../Paylater/InstallmentPlan.php | 21 +++++++++++++++++++ .../jsonData/paylaterPlansResponse.json | 2 +- .../PaylaterInstallmentPlansTest.php | 1 + test/unit/Resources/PaylaterPlansTest.php | 14 +++++++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3bb5120f..eafaa9342 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ 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). ### Deprecated diff --git a/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php b/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php index 344a935c5..a025805fe 100644 --- a/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php +++ b/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php @@ -19,6 +19,8 @@ class InstallmentPlan extends AbstractUnzerResource private $totalAmount; + private $minimumInstallmentFee; + private $nominalInterestRate; /** @var float $effectiveInterestRate */ @@ -87,6 +89,25 @@ public function setTotalAmount($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 */ diff --git a/test/Fixtures/jsonData/paylaterPlansResponse.json b/test/Fixtures/jsonData/paylaterPlansResponse.json index 15f99b5f3..d586eefdc 100644 --- a/test/Fixtures/jsonData/paylaterPlansResponse.json +++ b/test/Fixtures/jsonData/paylaterPlansResponse.json @@ -8,7 +8,7 @@ "totalAmount": "101.31", "nominalInterestRate": 9.95, "effectiveInterestRate": 10.43, - "minimumInstallmentFee": "0.00", + "minimumInstallmentFee": "2.50", "secciUrl": "https://test-payment.paylater.unzer.com/payolution-payment/infoport/creditagreementdraft/Tx-xyz?duration=3", "installmentRates": [ { diff --git a/test/unit/Resources/PaylaterInstallmentPlansTest.php b/test/unit/Resources/PaylaterInstallmentPlansTest.php index b52f34c51..634dfd5e5 100644 --- a/test/unit/Resources/PaylaterInstallmentPlansTest.php +++ b/test/unit/Resources/PaylaterInstallmentPlansTest.php @@ -153,6 +153,7 @@ protected function comparePlans(array $expected, array $actual): void foreach ($expected as $index => $plan) { $this->assertEquals($plan->totalAmount ?? null, $actual[$index]->getTotalAmount()); + $this->assertEquals($plan->minimumInstallmentFee ?? null, $actual[$index]->getMinimumInstallmentFee()); $this->assertEquals($plan->nominalInterestRate ?? null, $actual[$index]->getNominalInterestRate()); $this->assertEquals($plan->effectiveInterestRate ?? null, $actual[$index]->getEffectiveInterestRate()); $this->compareRates($plan->installmentRates ?? null, $actual[$index]->getInstallmentRates()); diff --git a/test/unit/Resources/PaylaterPlansTest.php b/test/unit/Resources/PaylaterPlansTest.php index 394e73c5a..12675ad00 100644 --- a/test/unit/Resources/PaylaterPlansTest.php +++ b/test/unit/Resources/PaylaterPlansTest.php @@ -123,6 +123,19 @@ public function emptyPlansArrayMapsToEmptyList(): void $this->assertEmpty($plans->getPlans()); } + /** + * The minimumInstallmentFee sent by the API is exposed on each plan. + * + * @test + */ + public function minimumInstallmentFeeIsMapped(): void + { + $plans = new PaylaterPlans(); + $plans->handleResponse(json_decode(JsonProvider::getJsonFromFile('paylaterPlansResponse.json'))); + + $this->assertEquals('2.50', $plans->getPlans()[0]->getMinimumInstallmentFee()); + } + // /** @@ -133,6 +146,7 @@ private function comparePlans(array $expected, array $actual): void { foreach ($expected as $index => $plan) { $this->assertEquals($plan->totalAmount ?? null, $actual[$index]->getTotalAmount()); + $this->assertEquals($plan->minimumInstallmentFee ?? null, $actual[$index]->getMinimumInstallmentFee()); $this->assertEquals($plan->nominalInterestRate ?? null, $actual[$index]->getNominalInterestRate()); $this->assertEquals($plan->effectiveInterestRate ?? null, $actual[$index]->getEffectiveInterestRate()); $this->assertNotNull($actual[$index]->getSecciUrl()); From 1381340418801ccb43df9d4c6a0caaff27404f53 Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Tue, 24 Nov 2026 10:34:53 +0100 Subject: [PATCH 10/10] [CC-4346] Fix zero-amount integration case and guard date-less rate Live sandbox run showed amount=0 is ACCEPTED by the API (HTTP 200 with a degenerate plan), so remove the "zero amount" row from the invalid-input data provider; keep the cases that genuinely error (negative amount, invalid currency, invalid country) with the generic exception-type + populated merchant-message assertions. The amount=0 response includes an installmentRate without a date field, which raised an "Undefined property: stdClass::$date" warning in InstallmentPlan::handleResponse(). Guard with $rate->date ?? null (and $rate->rate ?? null); InstallmentRate already accepts nulls. Benefits both the legacy and new plan flows. Add a unit test for a date-less rate. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../Paylater/InstallmentPlan.php | 2 +- .../PaymentTypes/PaylaterPlansTest.php | 2 +- test/unit/Resources/PaylaterPlansTest.php | 27 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php b/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php index a025805fe..810ee52a1 100644 --- a/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php +++ b/src/Resources/EmbeddedResources/Paylater/InstallmentPlan.php @@ -175,7 +175,7 @@ public function handleResponse(stdClass $response, string $method = HttpAdapterI if (isset($response->installmentRates)) { $rates = []; foreach ($response->installmentRates as $rate) { - $rates[] = new InstallmentRate($rate->date, $rate->rate); + $rates[] = new InstallmentRate($rate->date ?? null, $rate->rate ?? null); } $this->setInstallmentRates($rates); } diff --git a/test/integration/PaymentTypes/PaylaterPlansTest.php b/test/integration/PaymentTypes/PaylaterPlansTest.php index 5d3e32de1..ea9b9d25a 100644 --- a/test/integration/PaymentTypes/PaylaterPlansTest.php +++ b/test/integration/PaymentTypes/PaylaterPlansTest.php @@ -102,8 +102,8 @@ public function supportedPaylaterTypeDataProvider(): array public function invalidQueryDataProvider(): array { return [ + // amount=0 is NOT included: the live API accepts it (HTTP 200 with a degenerate plan). 'negative amount' => [-99.99, 'EUR', 'DE'], - 'zero amount' => [0.0, 'EUR', 'DE'], 'invalid currency' => [99.99, 'XXX', 'DE'], 'invalid country' => [99.99, 'EUR', 'ZZ'], ]; diff --git a/test/unit/Resources/PaylaterPlansTest.php b/test/unit/Resources/PaylaterPlansTest.php index 12675ad00..5748ed122 100644 --- a/test/unit/Resources/PaylaterPlansTest.php +++ b/test/unit/Resources/PaylaterPlansTest.php @@ -136,6 +136,33 @@ public function minimumInstallmentFeeIsMapped(): void $this->assertEquals('2.50', $plans->getPlans()[0]->getMinimumInstallmentFee()); } + /** + * An installment rate without a date (as returned by the amount=0 edge case) maps without a warning. + * + * @test + */ + public function installmentRateWithoutDateMapsWithoutWarning(): void + { + $response = json_decode(json_encode([ + 'id' => 'Tx-zero', + 'amount' => '0.00', + 'currency' => 'EUR', + 'plans' => [[ + 'numberOfRates' => 1, + 'totalAmount' => '0.00', + 'secciUrl' => 'https://example.test/secci', + 'installmentRates' => [['rate' => '0.00']], + ]], + ])); + + $plans = new PaylaterPlans(); + $plans->handleResponse($response); + + $rate = $plans->getPlans()[0]->getInstallmentRates()[0]; + $this->assertNull($rate->getDate()); + $this->assertEquals('0.00', $rate->getRate()); + } + // /**