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`. + */