Skip to content
Draft
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
1 change: 1 addition & 0 deletions src/Constants/IdStrings.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class IdStrings
public const CHARGEBACK = 'cbk';
public const PAYOUT = 'out';
public const PREAUTHORIZE = 'preaut';
public const SCA = 'sca';
public const SHIPMENT = 'shp';

// Payment Types
Expand Down
1 change: 1 addition & 0 deletions src/Constants/TransactionTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ class TransactionTypes
public const SHIPMENT = 'shipment';
public const PAYOUT = 'payout';
public const CHARGEBACK = 'chargeback';
public const SCA = 'sca';
}
17 changes: 17 additions & 0 deletions src/Interfaces/PaymentServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use UnzerSDK\Resources\TransactionTypes\Authorization;
use UnzerSDK\Resources\TransactionTypes\Charge;
use UnzerSDK\Resources\TransactionTypes\Payout;
use UnzerSDK\Resources\TransactionTypes\Sca;
use UnzerSDK\Resources\TransactionTypes\Shipment;

interface PaymentServiceInterface
Expand Down Expand Up @@ -389,4 +390,20 @@ public function fetchInstallmentPlans(
* @return PaylaterInstallmentPlans
*/
public function fetchPaylaterInstallmentPlans(InstallmentPlansQuery $plansRequest): PaylaterInstallmentPlans;

/**
* Perform an SCA transaction.
*
* @param Sca $sca The SCA object.
* @param BasePaymentType|string $paymentType The payment type object or ID.
* @param Customer|string|null $customer The customer object or ID.
* @param Metadata|null $metadata The metadata object.
* @param Basket|null $basket The basket object.
*
* @return Sca The resulting SCA object.
*
* @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 performSca(Sca $sca, $paymentType, $customer = null, ?Metadata $metadata = null, ?Basket $basket = null): Sca;
}
26 changes: 26 additions & 0 deletions src/Interfaces/ResourceServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use UnzerSDK\Resources\TransactionTypes\Charge;
use UnzerSDK\Resources\TransactionTypes\Chargeback;
use UnzerSDK\Resources\TransactionTypes\Payout;
use UnzerSDK\Resources\TransactionTypes\Sca;
use UnzerSDK\Resources\TransactionTypes\Shipment;

interface ResourceServiceInterface
Expand Down Expand Up @@ -452,4 +453,29 @@ public function fetchShipment($payment, string $shipmentId): Shipment;
* @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK.
*/
public function fetchConfig(BasePaymentType $paymentType, ?Config $config = null): Config;

/**
* Fetches an SCA transaction.
*
* @param Sca $sca The SCA object to fetch.
*
* @return Sca The fetched SCA object.
*
* @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 fetchSca(Sca $sca): Sca;

/**
* Fetches an SCA transaction by payment ID and SCA ID.
*
* @param Payment|string $payment The payment object or payment ID.
* @param string $scaId The SCA transaction ID.
*
* @return Sca The fetched SCA object.
*
* @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 fetchScaById($payment, string $scaId): Sca;
}
54 changes: 54 additions & 0 deletions src/Resources/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use UnzerSDK\Resources\TransactionTypes\Chargeback;
use UnzerSDK\Resources\TransactionTypes\Payout;
use UnzerSDK\Resources\TransactionTypes\PreAuthorization;
use UnzerSDK\Resources\TransactionTypes\Sca;
use UnzerSDK\Resources\TransactionTypes\Shipment;
use UnzerSDK\Services\IdService;
use UnzerSDK\Traits\HasInvoiceId;
Expand Down Expand Up @@ -58,6 +59,9 @@ class Payment extends AbstractUnzerResource
/** @var Chargeback[] $chargebacks */
private $chargebacks = [];

/** @var Sca|null $sca */
private $sca;


/**
* Associative array using the ID of the cancellations as the key.
Expand Down Expand Up @@ -337,6 +341,32 @@ public function getChargeByIndex(int $index, bool $lazy = false)
return $resource;
}

/**
* Returns the SCA transaction of this Payment.
*/
public function getSca(bool $lazy = false): ?Sca
{
$sca = $this->sca;
if (!$lazy && $sca !== null) {
return $this->getResource($sca);
}
return $sca;
}

/**
* Adds an SCA object to this Payment.
*
* @param Sca $sca
*
* @return $this
*/
public function setSca(Sca $sca): self
{
$sca->setPayment($this);
$this->sca = $sca;
return $this;
}

/**
* Reference this payment object to the passed Customer resource.
* The Customer resource can be passed as Customer object or the Id of a Customer resource.
Expand Down Expand Up @@ -924,6 +954,9 @@ private function updateResponseTransactions(array $transactions = []): void
case TransactionTypes::CHARGEBACK:
$this->updateChargebackTransaction($transaction);
break;
case TransactionTypes::SCA:
$this->updateScaTransaction($transaction);
break;
default:
// skip
break;
Expand Down Expand Up @@ -1191,4 +1224,25 @@ private function updateChargebackTransaction(stdClass $transaction): void

$chargeback->handleResponse($transaction);
}

/**
* This updates the local SCA object referenced by this Payment with the given SCA transaction
* from the Payment response.
*
* @param stdClass $transaction The transaction from the Payment response containing the SCA data.
*
* @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.
*/
private function updateScaTransaction(stdClass $transaction): void
{
$transactionId = IdService::getResourceIdFromUrl($transaction->url, IdStrings::SCA);
$sca = $this->sca;
if (!$sca instanceof Sca) {
$sca = (new Sca())->setPayment($this)->setId($transactionId);
$this->setSca($sca);
}

$sca->handleResponse($transaction);
}
}
22 changes: 22 additions & 0 deletions src/Resources/TransactionTypes/AbstractTransactionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ abstract class AbstractTransactionType extends AbstractUnzerResource
use HasAdditionalTransactionData;
use HasDate;

/** @var float $amount */
protected $amount;


/** @var Payment $payment */
private $payment;
Expand Down Expand Up @@ -242,4 +245,23 @@ protected function handleWeroTransactionData(stdClass $additionalTransactionData
$this->setWeroTransactionData($weroTransactionData);
}
}

/**
* @param float|null $amount
*
* @return Charge
*/
public function setAmount(?float $amount): self
{
$this->amount = $amount !== null ? round($amount, 4) : null;
return $this;
}

/**
* @return float|null
*/
public function getAmount(): ?float
{
return $this->amount;
}
}
19 changes: 0 additions & 19 deletions src/Resources/TransactionTypes/Authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,6 @@ public function __construct(?float $amount = null, ?string $currency = null, ?st
$this->setReturnUrl($returnUrl);
}

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

/**
* @param float|null $amount
*
* @return self
*/
public function setAmount(?float $amount): self
{
$this->amount = $amount !== null ? round($amount, 4) : null;
return $this;
}

/**
* @return float|null
*/
Expand Down
30 changes: 0 additions & 30 deletions src/Resources/TransactionTypes/Cancellation.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
*/
class Cancellation extends AbstractTransactionType
{
/**
* The cancellation amount will be transferred as grossAmount in case of Installment Secured payment type.
*
* @var float $amount
*/
protected $amount;

/** @var string $reasonCode */
protected $reasonCode;

Expand Down Expand Up @@ -53,29 +46,6 @@ public function __construct(?float $amount = null)
$this->setAmount($amount);
}

/**
* Returns the cancellationAmount (equals grossAmount in case of Installment Secured).
*
* @return float|null
*/
public function getAmount(): ?float
{
return $this->amount;
}

/**
* Sets the cancellationAmount (equals grossAmount in case of Installment Secured).
*
* @param float|null $amount
*
* @return Cancellation
*/
public function setAmount(?float $amount): self
{
$this->amount = $amount !== null ? round($amount, 4) : null;
return $this;
}

/**
* Returns the reason code of the cancellation if set.
*
Expand Down
22 changes: 0 additions & 22 deletions src/Resources/TransactionTypes/Charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ class Charge extends AbstractTransactionType
use HasDescriptor;
use HasChargebacks;

/** @var float $amount */
protected $amount;

/** @var string $currency */
protected $currency;

Expand All @@ -54,25 +51,6 @@ public function __construct(?float $amount = null, ?string $currency = null, ?st
$this->setReturnUrl($returnUrl);
}

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

/**
* @param float|null $amount
*
* @return self
*/
public function setAmount(?float $amount): self
{
$this->amount = $amount !== null ? round($amount, 4) : null;
return $this;
}

/**
* @return float|null
*/
Expand Down
24 changes: 0 additions & 24 deletions src/Resources/TransactionTypes/Chargeback.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
*/
class Chargeback extends AbstractTransactionType
{
/** @var float $amount */
protected $amount;

/** @var string $currency */
protected $currency;

Expand All @@ -29,27 +26,6 @@ public function __construct(?float $amount = null)
$this->setAmount($amount);
}

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

/**
* Sets the cancellationAmount (equals grossAmount in case of Installment Secured).
*
* @param float|null $amount
*
* @return Cancellation
*/
public function setAmount(?float $amount): self
{
$this->amount = $amount !== null ? round($amount, 4) : null;
return $this;
}

/**
* @return string
*/
Expand Down
22 changes: 0 additions & 22 deletions src/Resources/TransactionTypes/Payout.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
*/
class Payout extends AbstractTransactionType
{
/** @var float|null $amount */
protected $amount;

/** @var string|null $currency */
protected $currency;

Expand All @@ -31,25 +28,6 @@ public function __construct(?float $amount = null, ?string $currency = null, $re
$this->setReturnUrl($returnUrl);
}

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

/**
* @param float|null $amount
*
* @return self
*/
public function setAmount(?float $amount): self
{
$this->amount = $amount !== null ? round($amount, 4) : null;
return $this;
}

/**
* @return string|null
*/
Expand Down
Loading