From 3325e92c0778fd044ead88125a5cc85e88f6899d Mon Sep 17 00:00:00 2001 From: David Owusu <33735090+Ryouzanpaku@users.noreply.github.com> Date: Thu, 26 Nov 2026 12:37:20 +0100 Subject: [PATCH] [CC-4346] Add fetchPaylaterPlans() SECCI plans usage example (docs: UDOCS-1670) Documents the generalized Paylater plans API (php-sdk 4.1.0) as a runnable example, per UDOCS-1670. examples/PaylaterPlans/FetchPlans.php shows: - fetchPaylaterPlans(BasePaymentType, PaylaterPlansQuery) for Paylater Invoice, Direct Debit and Installment, - reading secciUrl (the CCD2 SECCI PDF link) from each plan, - controlling the SECCI PDF language via Unzer::setLocale() (Accept-Language), - a migration note from the deprecated fetchPaylaterInstallmentPlans(). The repo documents features via examples/ (README links to docs.unzer.com); this follows that convention. All referenced classes/methods verified against main. Co-Authored-By: Claude Opus 4.8 (1M context) --- examples/PaylaterPlans/FetchPlans.php | 86 +++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 examples/PaylaterPlans/FetchPlans.php diff --git a/examples/PaylaterPlans/FetchPlans.php b/examples/PaylaterPlans/FetchPlans.php new file mode 100644 index 00000000..fe245867 --- /dev/null +++ b/examples/PaylaterPlans/FetchPlans.php @@ -0,0 +1,86 @@ +setDebugMode(true)->setDebugHandler(new ExampleDebugHandler()); + +// The SECCI PDF is rendered in the client locale: the language follows the locale set here, which the +// SDK sends as the `Accept-Language` header. Omit to use the account default. +$unzer->setLocale('de-DE'); + +// Query parameters: amount, currency, country and customerType. customerType defaults to B2C. +$query = new PaylaterPlansQuery(119.00, 'EUR', 'DE', CustomerTypes::B2C); + +// `fetchPaylaterPlans()` works for every paylater type — pass the payment type you offer. +$paymentTypes = [ + 'Paylater Invoice' => new PaylaterInvoice(), + 'Paylater Direct Debit' => new PaylaterDirectDebit(), + 'Paylater Installment' => new PaylaterInstallment(), +]; + +foreach ($paymentTypes as $label => $paymentType) { + echo "== {$label} ==" . PHP_EOL; + + try { + $plans = $unzer->fetchPaylaterPlans($paymentType, $query); + + foreach ($plans->getPlans() as $plan) { + // `secciUrl` links to the Standard European Consumer Credit Information (SECCI) PDF that a + // CCD2 checkout must offer for download before payment confirmation. + echo ' ' . $plan->getNumberOfRates() . ' rate(s), total ' . $plan->getTotalAmount() + . ' — SECCI: ' . $plan->getSecciUrl() . PHP_EOL; + } + } catch (UnzerApiException $e) { + // The SDK does not validate the payment type or the query values; PAPI rejects an unsupported + // type or an invalid value and the SDK surfaces it as an UnzerApiException. + echo ' ' . $e->getMerchantMessage() . PHP_EOL; + } +} + +/* + * Migration — the installment-only flow is deprecated since 4.1.0: + * + * // Deprecated: Unzer::fetchPaylaterInstallmentPlans(InstallmentPlansQuery): PaylaterInstallmentPlans + * $plans = $unzer->fetchPaylaterInstallmentPlans( + * new UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlansQuery(119.00, 'EUR', 'DE') + * ); + * + * // Replacement: same query fields, but pass the payment type to the generalized method. + * $plans = $unzer->fetchPaylaterPlans( + * new PaylaterInstallment(), + * new PaylaterPlansQuery(119.00, 'EUR', 'DE') + * ); + * + * The legacy `PaylaterInstallmentPlans` / `InstallmentPlansQuery` classes keep their original public + * signatures and still work, but should be replaced with `PaylaterPlans` / `PaylaterPlansQuery`. + */