Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +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.
* `minimumInstallmentFee` is now exposed on `\UnzerSDK\Resources\EmbeddedResources\Paylater\InstallmentPlan` via `getMinimumInstallmentFee()` (previously present in the API response but dropped by the SDK).
* `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\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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
/**
* 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 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/
*
*/
Expand Down
206 changes: 206 additions & 0 deletions src/Resources/EmbeddedResources/Paylater/PaylaterPlan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
<?php

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.
*
* 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 `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/
*
*/
class PaylaterPlan extends AbstractUnzerResource
{
private ?int $numberOfRates = null;

private ?string $totalAmount = null;

private ?string $interestAmount = null;

private ?string $minimumInstallmentFee = null;

private ?float $nominalInterestRate = null;

private ?float $effectiveInterestRate = null;

private ?string $secciUrl = null;

/** @var InstallmentRate[]|null */
private ?array $installmentRates = null;

/**
* @return string|null
*/
public function getSecciUrl(): ?string
{
return $this->secciUrl;
}

/**
* @param string|null $secciUrl
*
* @return PaylaterPlan
*/
public function setSecciUrl(?string $secciUrl): PaylaterPlan
{
$this->secciUrl = $secciUrl;
return $this;
}

/**
* @return int|null
*/
public function getNumberOfRates(): ?int
{
return $this->numberOfRates;
}

/**
* @param int|null $numberOfRates
*
* @return PaylaterPlan
*/
public function setNumberOfRates(?int $numberOfRates): PaylaterPlan
{
$this->numberOfRates = $numberOfRates;
return $this;
}

/**
* @return string|null
*/
public function getTotalAmount(): ?string
{
return $this->totalAmount;
}

/**
* @param string|null $totalAmount
*
* @return PaylaterPlan
*/
public function setTotalAmount(?string $totalAmount): PaylaterPlan
{
$this->totalAmount = $totalAmount;
return $this;
}

/**
* @return string|null
*/
public function getInterestAmount(): ?string
{
return $this->interestAmount;
}

/**
* @param string|null $interestAmount
*
* @return PaylaterPlan
*/
public function setInterestAmount(?string $interestAmount): PaylaterPlan
{
$this->interestAmount = $interestAmount;
return $this;
}

/**
* @return string|null
*/
public function getMinimumInstallmentFee(): ?string
{
return $this->minimumInstallmentFee;
}

/**
* @param string|null $minimumInstallmentFee
*
* @return PaylaterPlan
*/
public function setMinimumInstallmentFee(?string $minimumInstallmentFee): PaylaterPlan
{
$this->minimumInstallmentFee = $minimumInstallmentFee;
return $this;
}

/**
* @return float|null
*/
public function getNominalInterestRate(): ?float
{
return $this->nominalInterestRate;
}

/**
* @param float|null $nominalInterestRate
*
* @return PaylaterPlan
*/
public function setNominalInterestRate(?float $nominalInterestRate): PaylaterPlan
{
$this->nominalInterestRate = $nominalInterestRate;
return $this;
}

/**
* @return float|null
*/
public function getEffectiveInterestRate(): ?float
{
return $this->effectiveInterestRate;
}

/**
* @param float|null $effectiveInterestRate
*
* @return PaylaterPlan
*/
public function setEffectiveInterestRate(?float $effectiveInterestRate): PaylaterPlan
{
$this->effectiveInterestRate = $effectiveInterestRate;
return $this;
}

/**
* @return InstallmentRate[]|null
*/
public function getInstallmentRates(): ?array
{
return $this->installmentRates;
}

/**
* @param InstallmentRate[]|null $installmentRates
*
* @return PaylaterPlan
*/
protected function setInstallmentRates(?array $installmentRates): PaylaterPlan
{
$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);
}
}
}
Loading
Loading