Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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/ApiResponseCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ApiResponseCodes
public const API_ERROR_CUSTOMER_DOES_NOT_EXIST = 'API.410.100.100';
public const API_ERROR_CUSTOMER_ID_ALREADY_EXISTS = 'API.410.200.010';
public const API_ERROR_ADDRESS_NAME_TO_LONG = 'API.410.200.031';
public const API_CANNOT_CHARGE_UNSUCCESSFUL_SCA_TRANSACTION = 'API.500.100.060';
public const API_ERROR_CUSTOMER_CAN_NOT_BE_FOUND = 'API.500.100.100';
public const API_ERROR_REQUEST_DATA_IS_INVALID = 'API.500.300.999';
public const API_ERROR_RECURRING_PAYMENT_NOT_SUPPORTED = 'API.500.550.004';
Expand Down
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 = 'strong_customer_authentication';
}
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;
}
55 changes: 55 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,33 @@ 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;
Comment thread
Ryouzanpaku marked this conversation as resolved.
if (!$lazy && $sca !== null) {
/** @var Sca */
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 +955,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 +1225,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 self
*/
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