From a4829d629dbd61d44fa00abe0ccd1c0ece41bfc4 Mon Sep 17 00:00:00 2001 From: "david.owusu" Date: Tue, 8 Jul 2025 15:05:56 +0200 Subject: [PATCH 1/5] [CC-1903] explicitly set nullable string parameter. --- src/Adapter/ApplepayAdapter.php | 2 +- src/Adapter/CurlAdapter.php | 9 ++++---- src/Adapter/HttpAdapterInterface.php | 2 +- src/Exceptions/UnzerApiException.php | 2 +- src/Interfaces/CancelServiceInterface.php | 12 +++++----- src/Interfaces/PaymentServiceInterface.php | 12 +++++----- src/Interfaces/ResourceServiceInterface.php | 2 +- .../GooglePay/SignedMessage.php | 2 +- src/Resources/InstalmentPlan.php | 4 ++-- src/Resources/Payment.php | 2 +- src/Resources/PaymentTypes/Card.php | 6 ++--- .../PaymentTypes/PaylaterDirectDebit.php | 2 +- .../TransactionTypes/Authorization.php | 4 ++-- src/Resources/TransactionTypes/Charge.php | 8 +++---- src/Resources/TransactionTypes/Payout.php | 2 +- src/Services/CancelService.php | 11 +++++----- src/Services/HttpService.php | 2 +- src/Services/PaymentService.php | 12 +++++----- src/Services/ResourceService.php | 6 ++--- src/Traits/CanPayout.php | 8 +++---- src/Traits/CanPayoutWithCustomer.php | 4 ++-- src/Unzer.php | 22 +++++++++---------- test/unit/Services/DummyAdapter.php | 2 +- 23 files changed, 68 insertions(+), 70 deletions(-) diff --git a/src/Adapter/ApplepayAdapter.php b/src/Adapter/ApplepayAdapter.php index 824650a5e..b23a46366 100644 --- a/src/Adapter/ApplepayAdapter.php +++ b/src/Adapter/ApplepayAdapter.php @@ -67,7 +67,7 @@ public function validMerchantValidationDomain(string $merchantValidationURL): bo * This is necessary if the ssl cert file doesn't contain key already. * @param string|null $caCert Path to CA certificate. */ - public function init(string $sslCert, string $sslKey = null, string $caCert = null): void + public function init(string $sslCert, ?string $sslKey = null, ?string $caCert = null): void { $timeout = EnvironmentService::getTimeout(); $curlVerbose = EnvironmentService::isCurlVerbose(); diff --git a/src/Adapter/CurlAdapter.php b/src/Adapter/CurlAdapter.php index e3ddd2b98..5535eb40e 100755 --- a/src/Adapter/CurlAdapter.php +++ b/src/Adapter/CurlAdapter.php @@ -10,11 +10,10 @@ namespace UnzerSDK\Adapter; -use UnzerSDK\Unzer; -use UnzerSDK\Services\EnvironmentService; -use UnzerSDK\Exceptions\UnzerApiException; use RuntimeException; - +use UnzerSDK\Exceptions\UnzerApiException; +use UnzerSDK\Services\EnvironmentService; +use UnzerSDK\Unzer; use function extension_loaded; use function in_array; @@ -37,7 +36,7 @@ public function __construct() /** * {@inheritDoc} */ - public function init(string $url, string $payload = null, string $httpMethod = HttpAdapterInterface::REQUEST_GET): void + public function init(string $url, ?string $payload = null, string $httpMethod = HttpAdapterInterface::REQUEST_GET): void { $timeout = EnvironmentService::getTimeout(); $curlVerbose = EnvironmentService::isCurlVerbose(); diff --git a/src/Adapter/HttpAdapterInterface.php b/src/Adapter/HttpAdapterInterface.php index 4e238b87d..2e2bd0a6a 100755 --- a/src/Adapter/HttpAdapterInterface.php +++ b/src/Adapter/HttpAdapterInterface.php @@ -25,7 +25,7 @@ interface HttpAdapterInterface * @param string|null $payload Json encoded payload string. * @param string $httpMethod The Http method to perform. */ - public function init(string $url, string $payload = null, string $httpMethod = HttpAdapterInterface::REQUEST_GET): void; + public function init(string $url, ?string $payload = null, string $httpMethod = HttpAdapterInterface::REQUEST_GET): void; /** * Executes the request and returns the response. diff --git a/src/Exceptions/UnzerApiException.php b/src/Exceptions/UnzerApiException.php index 39d209288..7a1d389b9 100644 --- a/src/Exceptions/UnzerApiException.php +++ b/src/Exceptions/UnzerApiException.php @@ -29,7 +29,7 @@ class UnzerApiException extends Exception * @param string $code * @param string|null $errorId */ - public function __construct($merchantMessage = '', $clientMessage = '', $code = null, string $errorId = null) + public function __construct($merchantMessage = '', $clientMessage = '', $code = null, ?string $errorId = null) { $merchantMessage = empty($merchantMessage) ? static::MESSAGE : $merchantMessage; $this->clientMessage = empty($clientMessage) ? static::CLIENT_MESSAGE : $clientMessage; diff --git a/src/Interfaces/CancelServiceInterface.php b/src/Interfaces/CancelServiceInterface.php index efa5314e9..5d000e523 100644 --- a/src/Interfaces/CancelServiceInterface.php +++ b/src/Interfaces/CancelServiceInterface.php @@ -8,13 +8,13 @@ namespace UnzerSDK\Interfaces; +use RuntimeException; use UnzerSDK\Constants\CancelReasonCodes; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\Payment; use UnzerSDK\Resources\TransactionTypes\Authorization; use UnzerSDK\Resources\TransactionTypes\Cancellation; use UnzerSDK\Resources\TransactionTypes\Charge; -use RuntimeException; interface CancelServiceInterface { @@ -68,8 +68,8 @@ public function cancelChargeById( $payment, string $chargeId, float $amount = null, - string $reasonCode = null, - string $referenceText = null, + ?string $reasonCode = null, + ?string $referenceText = null, float $amountNet = null, float $amountVat = null ): Cancellation; @@ -94,8 +94,8 @@ public function cancelChargeById( public function cancelCharge( Charge $charge, float $amount = null, - string $reasonCode = null, - string $referenceText = null, + ?string $reasonCode = null, + ?string $referenceText = null, float $amountNet = null, float $amountVat = null ): Cancellation; @@ -121,7 +121,7 @@ public function cancelPayment( $payment, float $amount = null, ?string $reasonCode = CancelReasonCodes::REASON_CODE_CANCEL, - string $referenceText = null, + ?string $referenceText = null, float $amountNet = null, float $amountVat = null ): array; diff --git a/src/Interfaces/PaymentServiceInterface.php b/src/Interfaces/PaymentServiceInterface.php index 477e03ead..3377b6915 100644 --- a/src/Interfaces/PaymentServiceInterface.php +++ b/src/Interfaces/PaymentServiceInterface.php @@ -9,6 +9,7 @@ namespace UnzerSDK\Interfaces; use DateTime; +use RuntimeException; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\AbstractUnzerResource; use UnzerSDK\Resources\Basket; @@ -24,7 +25,6 @@ use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\Resources\TransactionTypes\Payout; use UnzerSDK\Resources\TransactionTypes\Shipment; -use RuntimeException; interface PaymentServiceInterface { @@ -230,8 +230,8 @@ public function performChargeOnPayment( public function chargeAuthorization( $payment, float $amount = null, - string $orderId = null, - string $invoiceId = null + ?string $orderId = null, + ?string $invoiceId = null ): Charge; /** @@ -253,8 +253,8 @@ public function chargeAuthorization( public function chargePayment( $payment, float $amount = null, - string $orderId = null, - string $invoiceId = null + ?string $orderId = null, + ?string $invoiceId = null ): Charge; /** @@ -303,7 +303,7 @@ public function payout( * @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 ship($payment, string $invoiceId = null, string $orderId = null): Shipment; + public function ship($payment, ?string $invoiceId = null, ?string $orderId = null): Shipment; /** * Initializes a PayPage for charge transaction and returns the PayPage resource. diff --git a/src/Interfaces/ResourceServiceInterface.php b/src/Interfaces/ResourceServiceInterface.php index 531470dd8..6f26b0ad1 100644 --- a/src/Interfaces/ResourceServiceInterface.php +++ b/src/Interfaces/ResourceServiceInterface.php @@ -57,7 +57,7 @@ public function fetchPayout($payment): Payout; * @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 activateRecurringPayment($paymentType, string $returnUrl, string $recurrenceType = null): Recurring; + public function activateRecurringPayment($paymentType, string $returnUrl, ?string $recurrenceType = null): Recurring; /** * Fetch and return payment by given payment id or payment object. diff --git a/src/Resources/EmbeddedResources/GooglePay/SignedMessage.php b/src/Resources/EmbeddedResources/GooglePay/SignedMessage.php index 647474da1..2f73d06e9 100644 --- a/src/Resources/EmbeddedResources/GooglePay/SignedMessage.php +++ b/src/Resources/EmbeddedResources/GooglePay/SignedMessage.php @@ -20,7 +20,7 @@ class SignedMessage extends AbstractUnzerResource * @param string $ephemeralPublicKey * @param string $encryptedMessage */ - public function __construct(string $tag = null, string $ephemeralPublicKey = null, string $encryptedMessage = null) + public function __construct(string $tag = null, ?string $ephemeralPublicKey = null, ?string $encryptedMessage = null) { $this->tag = $tag; $this->ephemeralPublicKey = $ephemeralPublicKey; diff --git a/src/Resources/InstalmentPlan.php b/src/Resources/InstalmentPlan.php index bcdcf8591..7336c6744 100644 --- a/src/Resources/InstalmentPlan.php +++ b/src/Resources/InstalmentPlan.php @@ -3,10 +3,10 @@ namespace UnzerSDK\Resources; use DateTime; +use stdClass; use UnzerSDK\Adapter\HttpAdapterInterface; use UnzerSDK\Resources\PaymentTypes\BasePaymentType; use UnzerSDK\Traits\CanAuthorizeWithCustomer; -use stdClass; /** * Resource representing the installment plan for Installment Secured. @@ -78,7 +78,7 @@ class InstalmentPlan extends BasePaymentType */ public function __construct( int $numberOfRates = null, - string $dayOfPurchase = null, + ?string $dayOfPurchase = null, float $totalPurchaseAmount = null, float $totalInterestAmount = null, float $totalAmount = null, diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index 20f956d32..871ec10fd 100755 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -881,7 +881,7 @@ public function charge(float $amount = null): Charge * @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 ship(string $invoiceId = null, string $orderId = null) + public function ship(string $invoiceId = null, ?string $orderId = null) { return $this->getUnzerObject()->ship($this, $invoiceId, $orderId); } diff --git a/src/Resources/PaymentTypes/Card.php b/src/Resources/PaymentTypes/Card.php index 3a6888838..3ada8c562 100755 --- a/src/Resources/PaymentTypes/Card.php +++ b/src/Resources/PaymentTypes/Card.php @@ -2,6 +2,8 @@ namespace UnzerSDK\Resources\PaymentTypes; +use RuntimeException; +use stdClass; use UnzerSDK\Adapter\HttpAdapterInterface; use UnzerSDK\Resources\EmbeddedResources\CardDetails; use UnzerSDK\Traits\CanAuthorize; @@ -9,8 +11,6 @@ use UnzerSDK\Traits\CanPayout; use UnzerSDK\Traits\CanRecur; use UnzerSDK\Validators\ExpiryDateValidator; -use RuntimeException; -use stdClass; /** * This represents the card payment type which supports credit card as well as debit card payments. @@ -56,7 +56,7 @@ class Card extends BasePaymentType * @param string|null $expiryDate * @param string|null $email */ - public function __construct(?string $number, ?string $expiryDate, string $email = null) + public function __construct(?string $number, ?string $expiryDate, ?string $email = null) { $this->setNumber($number); $this->setExpiryDate($expiryDate); diff --git a/src/Resources/PaymentTypes/PaylaterDirectDebit.php b/src/Resources/PaymentTypes/PaylaterDirectDebit.php index fb7c3a179..bfa8d4836 100644 --- a/src/Resources/PaymentTypes/PaylaterDirectDebit.php +++ b/src/Resources/PaymentTypes/PaylaterDirectDebit.php @@ -12,7 +12,7 @@ class PaylaterDirectDebit extends BasePaymentType /** @var string $holder */ protected $holder; - public function __construct(string $iban = null, string $holder = null) + public function __construct(string $iban = null, ?string $holder = null) { $this->iban = $iban; $this->holder = $holder; diff --git a/src/Resources/TransactionTypes/Authorization.php b/src/Resources/TransactionTypes/Authorization.php index b37ac71d2..5ae9787c3 100755 --- a/src/Resources/TransactionTypes/Authorization.php +++ b/src/Resources/TransactionTypes/Authorization.php @@ -2,6 +2,7 @@ namespace UnzerSDK\Resources\TransactionTypes; +use RuntimeException; use UnzerSDK\Adapter\HttpAdapterInterface; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\Payment; @@ -9,7 +10,6 @@ use UnzerSDK\Traits\HasCancellations; use UnzerSDK\Traits\HasDescriptor; use UnzerSDK\Traits\HasRecurrenceType; -use RuntimeException; /** * This represents the authorization transaction. @@ -55,7 +55,7 @@ class Authorization extends AbstractTransactionType * @param string|null $currency * @param string|null $returnUrl */ - public function __construct(float $amount = null, string $currency = null, string $returnUrl = null) + public function __construct(float $amount = null, ?string $currency = null, ?string $returnUrl = null) { $this->setAmount($amount); $this->setCurrency($currency); diff --git a/src/Resources/TransactionTypes/Charge.php b/src/Resources/TransactionTypes/Charge.php index d7f16858a..125604390 100755 --- a/src/Resources/TransactionTypes/Charge.php +++ b/src/Resources/TransactionTypes/Charge.php @@ -2,6 +2,7 @@ namespace UnzerSDK\Resources\TransactionTypes; +use RuntimeException; use UnzerSDK\Adapter\HttpAdapterInterface; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Traits\HasAccountInformation; @@ -9,7 +10,6 @@ use UnzerSDK\Traits\HasChargebacks; use UnzerSDK\Traits\HasDescriptor; use UnzerSDK\Traits\HasRecurrenceType; -use RuntimeException; /** * This represents the charge transaction. @@ -47,7 +47,7 @@ class Charge extends AbstractTransactionType * @param string|null $currency * @param string|null $returnUrl */ - public function __construct(float $amount = null, string $currency = null, string $returnUrl = null) + public function __construct(float $amount = null, ?string $currency = null, ?string $returnUrl = null) { $this->setAmount($amount); $this->setCurrency($currency); @@ -200,8 +200,8 @@ protected function getResourcePath(string $httpMethod = HttpAdapterInterface::RE */ public function cancel( float $amount = null, - string $reasonCode = null, - string $paymentReference = null, + ?string $reasonCode = null, + ?string $paymentReference = null, float $amountNet = null, float $amountVat = null ): Cancellation { diff --git a/src/Resources/TransactionTypes/Payout.php b/src/Resources/TransactionTypes/Payout.php index 39f6a93de..4c8c7398d 100644 --- a/src/Resources/TransactionTypes/Payout.php +++ b/src/Resources/TransactionTypes/Payout.php @@ -31,7 +31,7 @@ class Payout extends AbstractTransactionType * @param string|null $currency * @param null $returnUrl */ - public function __construct(float $amount = null, string $currency = null, $returnUrl = null) + public function __construct(float $amount = null, ?string $currency = null, $returnUrl = null) { $this->setAmount($amount); $this->setCurrency($currency); diff --git a/src/Services/CancelService.php b/src/Services/CancelService.php index 354cb9011..bc9b00df5 100644 --- a/src/Services/CancelService.php +++ b/src/Services/CancelService.php @@ -12,7 +12,6 @@ use UnzerSDK\Resources\TransactionTypes\Cancellation; use UnzerSDK\Resources\TransactionTypes\Charge; use UnzerSDK\Unzer; - use function in_array; use function is_string; @@ -93,8 +92,8 @@ public function cancelChargeById( $payment, string $chargeId, float $amount = null, - string $reasonCode = null, - string $referenceText = null, + ?string $reasonCode = null, + ?string $referenceText = null, float $amountNet = null, float $amountVat = null ): Cancellation { @@ -108,8 +107,8 @@ public function cancelChargeById( public function cancelCharge( Charge $charge, float $amount = null, - string $reasonCode = null, - string $referenceText = null, + ?string $reasonCode = null, + ?string $referenceText = null, float $amountNet = null, float $amountVat = null ): Cancellation { @@ -133,7 +132,7 @@ public function cancelPayment( $payment, float $amount = null, ?string $reasonCode = CancelReasonCodes::REASON_CODE_CANCEL, - string $referenceText = null, + ?string $referenceText = null, float $amountNet = null, float $amountVat = null ): array { diff --git a/src/Services/HttpService.php b/src/Services/HttpService.php index 4e4fb0604..33fcc392d 100755 --- a/src/Services/HttpService.php +++ b/src/Services/HttpService.php @@ -100,7 +100,7 @@ public function send( ?string $uri = null, ?AbstractUnzerResource $resource = null, string $httpMethod = HttpAdapterInterface::REQUEST_GET, - string $apiVersion = null + ?string $apiVersion = null ): string { if (!$resource instanceof AbstractUnzerResource) { throw new RuntimeException('Transfer object is empty!'); diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index c59cd819d..fd34fdf69 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -215,8 +215,8 @@ public function charge( public function chargeAuthorization( $payment, float $amount = null, - string $orderId = null, - string $invoiceId = null + ?string $orderId = null, + ?string $invoiceId = null ): Charge { return $this->chargePayment($payment, $amount, $orderId, $invoiceId); } @@ -227,8 +227,8 @@ public function chargeAuthorization( public function chargePayment( $payment, float $amount = null, - string $orderId = null, - string $invoiceId = null + ?string $orderId = null, + ?string $invoiceId = null ): Charge { $charge = new Charge($amount); @@ -267,7 +267,7 @@ public function payout( Metadata $metadata = null, Basket $basket = null, string $invoiceId = null, - string $referenceText = null + ?string $referenceText = null ): Payout { $payment = $this->createPayment($paymentType); $payout = (new Payout($amount, $currency, $returnUrl)) @@ -283,7 +283,7 @@ public function payout( /** * {@inheritDoc} */ - public function ship($payment, string $invoiceId = null, string $orderId = null): Shipment + public function ship($payment, ?string $invoiceId = null, ?string $orderId = null): Shipment { $shipment = new Shipment(); $shipment->setInvoiceId($invoiceId)->setOrderId($orderId); diff --git a/src/Services/ResourceService.php b/src/Services/ResourceService.php index 7436fb564..7658c672a 100755 --- a/src/Services/ResourceService.php +++ b/src/Services/ResourceService.php @@ -120,7 +120,7 @@ public function setUnzer(Unzer $unzer): ResourceServiceInterface public function send( AbstractUnzerResource $resource, string $httpMethod = HttpAdapterInterface::REQUEST_GET, - string $apiVersion = null + ?string $apiVersion = null ): stdClass { $apiConfig = $resource->getApiConfig(); @@ -346,7 +346,7 @@ public function deleteResource(AbstractUnzerResource &$resource): ?AbstractUnzer * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. * @throws Exception */ - public function fetchResource(AbstractUnzerResource $resource, string $apiVersion = null): AbstractUnzerResource + public function fetchResource(AbstractUnzerResource $resource, ?string $apiVersion = null): AbstractUnzerResource { $method = HttpAdapterInterface::REQUEST_GET; $response = $this->send($resource, $method, $apiVersion); @@ -379,7 +379,7 @@ public function fetchPayout($payment): Payout /** * {@inheritDoc} */ - public function activateRecurringPayment($paymentType, string $returnUrl, string $recurrenceType = null): Recurring + public function activateRecurringPayment($paymentType, string $returnUrl, ?string $recurrenceType = null): Recurring { $paymentTypeObject = $paymentType; if (is_string($paymentType)) { diff --git a/src/Traits/CanPayout.php b/src/Traits/CanPayout.php index 4458e68d2..a4f319f47 100644 --- a/src/Traits/CanPayout.php +++ b/src/Traits/CanPayout.php @@ -8,13 +8,13 @@ namespace UnzerSDK\Traits; +use RuntimeException; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Interfaces\UnzerParentInterface; use UnzerSDK\Resources\Basket; use UnzerSDK\Resources\Customer; use UnzerSDK\Resources\Metadata; use UnzerSDK\Resources\TransactionTypes\Payout; -use RuntimeException; trait CanPayout { @@ -44,11 +44,11 @@ public function payout( string $currency, string $returnUrl, $customer = null, - string $orderId = null, + ?string $orderId = null, $metadata = null, Basket $basket = null, - string $invoiceId = null, - string $paymentReference = null + ?string $invoiceId = null, + ?string $paymentReference = null ): Payout { if ($this instanceof UnzerParentInterface) { return $this->getUnzerObject()->payout( diff --git a/src/Traits/CanPayoutWithCustomer.php b/src/Traits/CanPayoutWithCustomer.php index 389a4bf06..9e597e0b2 100644 --- a/src/Traits/CanPayoutWithCustomer.php +++ b/src/Traits/CanPayoutWithCustomer.php @@ -8,13 +8,13 @@ namespace UnzerSDK\Traits; +use RuntimeException; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Interfaces\UnzerParentInterface; use UnzerSDK\Resources\Basket; use UnzerSDK\Resources\Customer; use UnzerSDK\Resources\Metadata; use UnzerSDK\Resources\TransactionTypes\Payout; -use RuntimeException; trait CanPayoutWithCustomer { @@ -42,7 +42,7 @@ public function payout( string $currency, string $returnUrl, $customer, - string $orderId = null, + ?string $orderId = null, $metadata = null, Basket $basket = null ): Payout { diff --git a/src/Unzer.php b/src/Unzer.php index bc3d88b35..076887aef 100644 --- a/src/Unzer.php +++ b/src/Unzer.php @@ -358,7 +358,7 @@ public function getUri(bool $appendId = true, string $httpMethod = HttpAdapterIn /** * {@inheritDoc} */ - public function activateRecurringPayment($paymentType, string $returnUrl, string $recurrenceType = null): Recurring + public function activateRecurringPayment($paymentType, string $returnUrl, ?string $recurrenceType = null): Recurring { return $this->resourceService->activateRecurringPayment($paymentType, $returnUrl, $recurrenceType); } @@ -787,8 +787,8 @@ public function charge( public function chargeAuthorization( $payment, float $amount = null, - string $orderId = null, - string $invoiceId = null + ?string $orderId = null, + ?string $invoiceId = null ): Charge { return $this->paymentService->chargeAuthorization($payment, $amount, $orderId, $invoiceId); @@ -800,8 +800,8 @@ public function chargeAuthorization( public function chargePayment( $payment, float $amount = null, - string $orderId = null, - string $invoiceId = null + ?string $orderId = null, + ?string $invoiceId = null ): Charge { return $this->paymentService->chargePayment($payment, $amount, $orderId, $invoiceId); @@ -835,7 +835,7 @@ public function cancelPayment( $payment, float $amount = null, ?string $reasonCode = CancelReasonCodes::REASON_CODE_CANCEL, - string $referenceText = null, + ?string $referenceText = null, float $amountNet = null, float $amountVat = null ): array @@ -859,8 +859,8 @@ public function cancelChargeById( $payment, string $chargeId, float $amount = null, - string $reasonCode = null, - string $referenceText = null, + ?string $reasonCode = null, + ?string $referenceText = null, float $amountNet = null, float $amountVat = null ): Cancellation @@ -875,8 +875,8 @@ public function cancelChargeById( public function cancelCharge( Charge $charge, float $amount = null, - string $reasonCode = null, - string $referenceText = null, + ?string $reasonCode = null, + ?string $referenceText = null, float $amountNet = null, float $amountVat = null ): Cancellation @@ -917,7 +917,7 @@ public function createAuthToken(): Token /** * {@inheritDoc} */ - public function ship($payment, string $invoiceId = null, string $orderId = null): Shipment + public function ship($payment, ?string $invoiceId = null, ?string $orderId = null): Shipment { return $this->paymentService->ship($payment, $invoiceId, $orderId); } diff --git a/test/unit/Services/DummyAdapter.php b/test/unit/Services/DummyAdapter.php index 399d50cd8..a37787088 100755 --- a/test/unit/Services/DummyAdapter.php +++ b/test/unit/Services/DummyAdapter.php @@ -18,7 +18,7 @@ class DummyAdapter implements HttpAdapterInterface /** * {@inheritDoc} */ - public function init(string $url, string $payload = null, string $httpMethod = HttpAdapterInterface::REQUEST_GET): void + public function init(string $url, ?string $payload = null, string $httpMethod = HttpAdapterInterface::REQUEST_GET): void { // do nothing } From f01ce63793d89011b1d145f6e761c60424f7be4f Mon Sep 17 00:00:00 2001 From: "david.owusu" Date: Tue, 8 Jul 2025 16:29:59 +0200 Subject: [PATCH 2/5] [CC-1903 remove-php-8-4] explicitly set nullable parameter. --- src/Interfaces/CancelServiceInterface.php | 24 +++---- src/Interfaces/PaymentServiceInterface.php | 36 +++++------ src/Interfaces/WebhookServiceInterface.php | 4 +- .../GooglePay/SignedMessage.php | 2 +- src/Resources/InstalmentPlan.php | 20 +++--- src/Resources/Payment.php | 14 ++-- .../PaymentTypes/InstallmentSecured.php | 2 +- src/Resources/PaymentTypes/OpenbankingPis.php | 2 +- .../PaymentTypes/PaylaterDirectDebit.php | 2 +- .../TransactionTypes/Authorization.php | 6 +- .../TransactionTypes/Cancellation.php | 3 +- src/Resources/TransactionTypes/Charge.php | 8 +-- src/Resources/TransactionTypes/Chargeback.php | 2 +- src/Resources/TransactionTypes/Payout.php | 2 +- src/Services/CancelService.php | 24 +++---- src/Services/PaymentService.php | 38 +++++------ src/Services/ResourceService.php | 2 +- src/Services/WebhookService.php | 7 +- src/Traits/CanPayout.php | 2 +- src/Traits/CanPayoutWithCustomer.php | 2 +- src/Unzer.php | 64 +++++++++---------- 21 files changed, 132 insertions(+), 134 deletions(-) diff --git a/src/Interfaces/CancelServiceInterface.php b/src/Interfaces/CancelServiceInterface.php index 5d000e523..5400380ad 100644 --- a/src/Interfaces/CancelServiceInterface.php +++ b/src/Interfaces/CancelServiceInterface.php @@ -30,7 +30,7 @@ interface CancelServiceInterface * @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 cancelAuthorization(Authorization $authorization, float $amount = null): Cancellation; + public function cancelAuthorization(Authorization $authorization, ?float $amount = null): Cancellation; /** * Performs a Cancellation transaction for the Authorization of the given Payment object. @@ -44,7 +44,7 @@ public function cancelAuthorization(Authorization $authorization, float $amount * @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 cancelAuthorizationByPayment($payment, float $amount = null): Cancellation; + public function cancelAuthorizationByPayment($payment, ?float $amount = null): Cancellation; /** * Performs a Cancellation transaction for the given Charge and returns the resulting Cancellation object. @@ -67,11 +67,11 @@ public function cancelAuthorizationByPayment($payment, float $amount = null): Ca public function cancelChargeById( $payment, string $chargeId, - float $amount = null, + ?float $amount = null, ?string $reasonCode = null, ?string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?float $amountNet = null, + ?float $amountVat = null ): Cancellation; /** @@ -93,11 +93,11 @@ public function cancelChargeById( */ public function cancelCharge( Charge $charge, - float $amount = null, + ?float $amount = null, ?string $reasonCode = null, ?string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?float $amountNet = null, + ?float $amountVat = null ): Cancellation; /** @@ -119,11 +119,11 @@ public function cancelCharge( */ public function cancelPayment( $payment, - float $amount = null, + ?float $amount = null, ?string $reasonCode = CancelReasonCodes::REASON_CODE_CANCEL, ?string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?float $amountNet = null, + ?float $amountVat = null ): array; /** @@ -167,5 +167,5 @@ public function cancelChargedPayment($payment, ?Cancellation $cancellation = nul * @throws UnzerApiException An UnzerApiException is thrown if there is an error returned on API-request. * @throws RuntimeException A RuntimeException is thrown when there is a error while using the SDK. */ - public function cancelPaymentAuthorization($payment, float $amount = null): ?Cancellation; + public function cancelPaymentAuthorization($payment, ?float $amount = null): ?Cancellation; } diff --git a/src/Interfaces/PaymentServiceInterface.php b/src/Interfaces/PaymentServiceInterface.php index 3377b6915..d4613979e 100644 --- a/src/Interfaces/PaymentServiceInterface.php +++ b/src/Interfaces/PaymentServiceInterface.php @@ -48,8 +48,8 @@ public function performAuthorization( Authorization $authorization, $paymentType, $customer = null, - Metadata $metadata = null, - Basket $basket = null + ?Metadata $metadata = null, + ?Basket $basket = null ): Authorization; /** @@ -130,8 +130,8 @@ public function performCharge( Charge $charge, $paymentType, $customer = null, - Metadata $metadata = null, - Basket $basket = null + ?Metadata $metadata = null, + ?Basket $basket = null ): Charge; /** @@ -229,7 +229,7 @@ public function performChargeOnPayment( */ public function chargeAuthorization( $payment, - float $amount = null, + ?float $amount = null, ?string $orderId = null, ?string $invoiceId = null ): Charge; @@ -252,7 +252,7 @@ public function chargeAuthorization( */ public function chargePayment( $payment, - float $amount = null, + ?float $amount = null, ?string $orderId = null, ?string $invoiceId = null ): Charge; @@ -284,11 +284,11 @@ public function payout( $paymentType, string $returnUrl, $customer = null, - string $orderId = null, - Metadata $metadata = null, - Basket $basket = null, - string $invoiceId = null, - string $referenceText = null + ?string $orderId = null, + ?Metadata $metadata = null, + ?Basket $basket = null, + ?string $invoiceId = null, + ?string $referenceText = null ): Payout; /** @@ -328,9 +328,9 @@ public function ship($payment, ?string $invoiceId = null, ?string $orderId = nul */ public function initPayPageCharge( Paypage $paypage, - Customer $customer = null, - Basket $basket = null, - Metadata $metadata = null + ?Customer $customer = null, + ?Basket $basket = null, + ?Metadata $metadata = null ): Paypage; /** @@ -356,9 +356,9 @@ public function initPayPageCharge( */ public function initPayPageAuthorize( Paypage $paypage, - Customer $customer = null, - Basket $basket = null, - Metadata $metadata = null + ?Customer $customer = null, + ?Basket $basket = null, + ?Metadata $metadata = null ): Paypage; /** @@ -378,7 +378,7 @@ public function fetchInstallmentPlans( float $amount, string $currency, float $effectiveInterest, - DateTime $orderDate = null + ?DateTime $orderDate = null ): InstalmentPlans; /** diff --git a/src/Interfaces/WebhookServiceInterface.php b/src/Interfaces/WebhookServiceInterface.php index 48c89e2eb..8ae6b5a03 100644 --- a/src/Interfaces/WebhookServiceInterface.php +++ b/src/Interfaces/WebhookServiceInterface.php @@ -8,10 +8,10 @@ namespace UnzerSDK\Interfaces; +use RuntimeException; use UnzerSDK\Exceptions\UnzerApiException; use UnzerSDK\Resources\AbstractUnzerResource; use UnzerSDK\Resources\Webhook; -use RuntimeException; interface WebhookServiceInterface { @@ -106,5 +106,5 @@ public function registerMultipleWebhooks(string $url, array $events): array; * @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 fetchResourceFromEvent(string $eventJson = null): AbstractUnzerResource; + public function fetchResourceFromEvent(?string $eventJson = null): AbstractUnzerResource; } diff --git a/src/Resources/EmbeddedResources/GooglePay/SignedMessage.php b/src/Resources/EmbeddedResources/GooglePay/SignedMessage.php index 2f73d06e9..6f6542d22 100644 --- a/src/Resources/EmbeddedResources/GooglePay/SignedMessage.php +++ b/src/Resources/EmbeddedResources/GooglePay/SignedMessage.php @@ -20,7 +20,7 @@ class SignedMessage extends AbstractUnzerResource * @param string $ephemeralPublicKey * @param string $encryptedMessage */ - public function __construct(string $tag = null, ?string $ephemeralPublicKey = null, ?string $encryptedMessage = null) + public function __construct(?string $tag = null, ?string $ephemeralPublicKey = null, ?string $encryptedMessage = null) { $this->tag = $tag; $this->ephemeralPublicKey = $ephemeralPublicKey; diff --git a/src/Resources/InstalmentPlan.php b/src/Resources/InstalmentPlan.php index 7336c6744..3c9769548 100644 --- a/src/Resources/InstalmentPlan.php +++ b/src/Resources/InstalmentPlan.php @@ -77,17 +77,17 @@ class InstalmentPlan extends BasePaymentType * @param float|null $lastRate */ public function __construct( - int $numberOfRates = null, + ?int $numberOfRates = null, ?string $dayOfPurchase = null, - float $totalPurchaseAmount = null, - float $totalInterestAmount = null, - float $totalAmount = null, - float $effectiveInterestRate = null, - float $nominalInterestRate = null, - float $feeFirstRate = null, - float $feePerRate = null, - float $monthlyRate = null, - float $lastRate = null + ?float $totalPurchaseAmount = null, + ?float $totalInterestAmount = null, + ?float $totalAmount = null, + ?float $effectiveInterestRate = null, + ?float $nominalInterestRate = null, + ?float $feeFirstRate = null, + ?float $feePerRate = null, + ?float $monthlyRate = null, + ?float $lastRate = null ) { $this->numberOfRates = $numberOfRates; $this->dayOfPurchase = $dayOfPurchase; diff --git a/src/Resources/Payment.php b/src/Resources/Payment.php index 871ec10fd..4a75656b4 100755 --- a/src/Resources/Payment.php +++ b/src/Resources/Payment.php @@ -829,11 +829,11 @@ public function getExternalId(): ?string * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. */ public function cancelAmount( - float $amount = null, + ?float $amount = null, ?string $reasonCode = CancelReasonCodes::REASON_CODE_CANCEL, - string $paymentReference = null, - float $amountNet = null, - float $amountVat = null + ?string $paymentReference = null, + ?float $amountNet = null, + ?float $amountVat = null ): array { return $this->getUnzerObject()->cancelPayment($this, $amount, $reasonCode, $paymentReference, $amountNet, $amountVat); } @@ -850,7 +850,7 @@ public function cancelAmount( * @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 cancelAuthorizationAmount(float $amount = null): ?Cancellation + public function cancelAuthorizationAmount(?float $amount = null): ?Cancellation { return $this->getUnzerObject()->cancelPaymentAuthorization($this, $amount); } @@ -865,7 +865,7 @@ public function cancelAuthorizationAmount(float $amount = null): ?Cancellation * @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 charge(float $amount = null): Charge + public function charge(?float $amount = null): Charge { return $this->getUnzerObject()->chargePayment($this, $amount); } @@ -881,7 +881,7 @@ public function charge(float $amount = null): Charge * @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 ship(string $invoiceId = null, ?string $orderId = null) + public function ship(?string $invoiceId = null, ?string $orderId = null) { return $this->getUnzerObject()->ship($this, $invoiceId, $orderId); } diff --git a/src/Resources/PaymentTypes/InstallmentSecured.php b/src/Resources/PaymentTypes/InstallmentSecured.php index 1410d7130..15a1dd04a 100644 --- a/src/Resources/PaymentTypes/InstallmentSecured.php +++ b/src/Resources/PaymentTypes/InstallmentSecured.php @@ -34,7 +34,7 @@ class InstallmentSecured extends InstalmentPlan * @param null|DateTime|string $invoiceDate * @param null|DateTime|string $invoiceDueDate */ - public function __construct(InstalmentPlan $selectedPlan = null, $iban = null, $accountHolder = null, $orderDate = null, $bic = null, $invoiceDate = null, $invoiceDueDate = null) + public function __construct(?InstalmentPlan $selectedPlan = null, $iban = null, $accountHolder = null, $orderDate = null, $bic = null, $invoiceDate = null, $invoiceDueDate = null) { parent::__construct(); diff --git a/src/Resources/PaymentTypes/OpenbankingPis.php b/src/Resources/PaymentTypes/OpenbankingPis.php index f8e07de48..c7fa5af34 100644 --- a/src/Resources/PaymentTypes/OpenbankingPis.php +++ b/src/Resources/PaymentTypes/OpenbankingPis.php @@ -9,7 +9,7 @@ class OpenbankingPis extends BasePaymentType /** @var string|null $ibanCountry */ protected $ibanCountry; - public function __construct(string $ibanCountry = null) + public function __construct(?string $ibanCountry = null) { $this->ibanCountry = $ibanCountry; } diff --git a/src/Resources/PaymentTypes/PaylaterDirectDebit.php b/src/Resources/PaymentTypes/PaylaterDirectDebit.php index bfa8d4836..8c89b5988 100644 --- a/src/Resources/PaymentTypes/PaylaterDirectDebit.php +++ b/src/Resources/PaymentTypes/PaylaterDirectDebit.php @@ -12,7 +12,7 @@ class PaylaterDirectDebit extends BasePaymentType /** @var string $holder */ protected $holder; - public function __construct(string $iban = null, ?string $holder = null) + public function __construct(?string $iban = null, ?string $holder = null) { $this->iban = $iban; $this->holder = $holder; diff --git a/src/Resources/TransactionTypes/Authorization.php b/src/Resources/TransactionTypes/Authorization.php index 5ae9787c3..6936b8b84 100755 --- a/src/Resources/TransactionTypes/Authorization.php +++ b/src/Resources/TransactionTypes/Authorization.php @@ -55,7 +55,7 @@ class Authorization extends AbstractTransactionType * @param string|null $currency * @param string|null $returnUrl */ - public function __construct(float $amount = null, ?string $currency = null, ?string $returnUrl = null) + public function __construct(?float $amount = null, ?string $currency = null, ?string $returnUrl = null) { $this->setAmount($amount); $this->setCurrency($currency); @@ -250,7 +250,7 @@ protected function getResourcePath(string $httpMethod = HttpAdapterInterface::RE * @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 cancel(float $amount = null): Cancellation + public function cancel(?float $amount = null): Cancellation { return $this->getUnzerObject()->cancelAuthorization($this, $amount); } @@ -265,7 +265,7 @@ public function cancel(float $amount = null): Cancellation * @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 charge(float $amount = null): Charge + public function charge(?float $amount = null): Charge { $payment = $this->getPayment(); if (!$payment instanceof Payment) { diff --git a/src/Resources/TransactionTypes/Cancellation.php b/src/Resources/TransactionTypes/Cancellation.php index 26d92e851..ad41d1c22 100755 --- a/src/Resources/TransactionTypes/Cancellation.php +++ b/src/Resources/TransactionTypes/Cancellation.php @@ -6,7 +6,6 @@ use UnzerSDK\Constants\CancelReasonCodes; use UnzerSDK\Resources\Payment; use UnzerSDK\Resources\PaymentTypes\InstallmentSecured; - use function in_array; /** @@ -49,7 +48,7 @@ class Cancellation extends AbstractTransactionType * * @param float|null $amount The amount to be cancelled, is transferred as grossAmount in case of Installment Secured. */ - public function __construct(float $amount = null) + public function __construct(?float $amount = null) { $this->setAmount($amount); } diff --git a/src/Resources/TransactionTypes/Charge.php b/src/Resources/TransactionTypes/Charge.php index 125604390..278cc9c3b 100755 --- a/src/Resources/TransactionTypes/Charge.php +++ b/src/Resources/TransactionTypes/Charge.php @@ -47,7 +47,7 @@ class Charge extends AbstractTransactionType * @param string|null $currency * @param string|null $returnUrl */ - public function __construct(float $amount = null, ?string $currency = null, ?string $returnUrl = null) + public function __construct(?float $amount = null, ?string $currency = null, ?string $returnUrl = null) { $this->setAmount($amount); $this->setCurrency($currency); @@ -199,11 +199,11 @@ protected function getResourcePath(string $httpMethod = HttpAdapterInterface::RE * @throws RuntimeException A RuntimeException is thrown when there is an error while using the SDK. */ public function cancel( - float $amount = null, + ?float $amount = null, ?string $reasonCode = null, ?string $paymentReference = null, - float $amountNet = null, - float $amountVat = null + ?float $amountNet = null, + ?float $amountVat = null ): Cancellation { return $this->getUnzerObject()->cancelCharge( $this, diff --git a/src/Resources/TransactionTypes/Chargeback.php b/src/Resources/TransactionTypes/Chargeback.php index 7c0c5925a..2ef22d038 100644 --- a/src/Resources/TransactionTypes/Chargeback.php +++ b/src/Resources/TransactionTypes/Chargeback.php @@ -24,7 +24,7 @@ class Chargeback extends AbstractTransactionType /** * @param float|null $amount The amount to be cancelled, is transferred as grossAmount in case of Installment Secured. */ - public function __construct(float $amount = null) + public function __construct(?float $amount = null) { $this->setAmount($amount); } diff --git a/src/Resources/TransactionTypes/Payout.php b/src/Resources/TransactionTypes/Payout.php index 4c8c7398d..adae7eaf2 100644 --- a/src/Resources/TransactionTypes/Payout.php +++ b/src/Resources/TransactionTypes/Payout.php @@ -31,7 +31,7 @@ class Payout extends AbstractTransactionType * @param string|null $currency * @param null $returnUrl */ - public function __construct(float $amount = null, ?string $currency = null, $returnUrl = null) + public function __construct(?float $amount = null, ?string $currency = null, $returnUrl = null) { $this->setAmount($amount); $this->setCurrency($currency); diff --git a/src/Services/CancelService.php b/src/Services/CancelService.php index bc9b00df5..37106177c 100644 --- a/src/Services/CancelService.php +++ b/src/Services/CancelService.php @@ -66,7 +66,7 @@ public function getResourceService(): ResourceService /** * {@inheritDoc} */ - public function cancelAuthorization(Authorization $authorization, float $amount = null): Cancellation + public function cancelAuthorization(Authorization $authorization, ?float $amount = null): Cancellation { $cancellation = new Cancellation($amount); $cancellation->setPayment($authorization->getPayment())->setParentResource($authorization); @@ -79,7 +79,7 @@ public function cancelAuthorization(Authorization $authorization, float $amount /** * {@inheritDoc} */ - public function cancelAuthorizationByPayment($payment, float $amount = null): Cancellation + public function cancelAuthorizationByPayment($payment, ?float $amount = null): Cancellation { $authorization = $this->getResourceService()->fetchAuthorization($payment); return $this->cancelAuthorization($authorization, $amount); @@ -91,11 +91,11 @@ public function cancelAuthorizationByPayment($payment, float $amount = null): Ca public function cancelChargeById( $payment, string $chargeId, - float $amount = null, + ?float $amount = null, ?string $reasonCode = null, ?string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?float $amountNet = null, + ?float $amountVat = null ): Cancellation { $charge = $this->getResourceService()->fetchChargeById($payment, $chargeId); return $this->cancelCharge($charge, $amount, $reasonCode, $referenceText, $amountNet, $amountVat); @@ -106,11 +106,11 @@ public function cancelChargeById( */ public function cancelCharge( Charge $charge, - float $amount = null, + ?float $amount = null, ?string $reasonCode = null, ?string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?float $amountNet = null, + ?float $amountVat = null ): Cancellation { $cancellation = new Cancellation($amount); $cancellation @@ -130,11 +130,11 @@ public function cancelCharge( */ public function cancelPayment( $payment, - float $amount = null, + ?float $amount = null, ?string $reasonCode = CancelReasonCodes::REASON_CODE_CANCEL, ?string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?float $amountNet = null, + ?float $amountVat = null ): array { $paymentObject = $payment; if (is_string($payment)) { @@ -185,7 +185,7 @@ public function cancelPayment( /** * {@inheritDoc} */ - public function cancelPaymentAuthorization($payment, float $amount = null): ?Cancellation + public function cancelPaymentAuthorization($payment, ?float $amount = null): ?Cancellation { $cancellation = null; $completeCancel = $amount === null; diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index fd34fdf69..bb1e64667 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -77,8 +77,8 @@ public function performAuthorization( Authorization $authorization, $paymentType, $customer = null, - Metadata $metadata = null, - Basket $basket = null + ?Metadata $metadata = null, + ?Basket $basket = null ): Authorization { $payment = $this->createPayment($paymentType); $paymentType = $payment->getPaymentType(); @@ -144,7 +144,7 @@ public function authorize( /** * {@inheritDoc} */ - public function performCharge(Charge $charge, $paymentType, $customer = null, Metadata $metadata = null, Basket $basket = null): Charge + public function performCharge(Charge $charge, $paymentType, $customer = null, ?Metadata $metadata = null, ?Basket $basket = null): Charge { $payment = $this->createPayment($paymentType); $paymentType = $payment->getPaymentType(); @@ -214,7 +214,7 @@ public function charge( */ public function chargeAuthorization( $payment, - float $amount = null, + ?float $amount = null, ?string $orderId = null, ?string $invoiceId = null ): Charge { @@ -226,7 +226,7 @@ public function chargeAuthorization( */ public function chargePayment( $payment, - float $amount = null, + ?float $amount = null, ?string $orderId = null, ?string $invoiceId = null ): Charge { @@ -263,10 +263,10 @@ public function payout( $paymentType, string $returnUrl, $customer = null, - string $orderId = null, - Metadata $metadata = null, - Basket $basket = null, - string $invoiceId = null, + ?string $orderId = null, + ?Metadata $metadata = null, + ?Basket $basket = null, + ?string $invoiceId = null, ?string $referenceText = null ): Payout { $payment = $this->createPayment($paymentType); @@ -297,9 +297,9 @@ public function ship($payment, ?string $invoiceId = null, ?string $orderId = nul */ public function initPayPageCharge( Paypage $paypage, - Customer $customer = null, - Basket $basket = null, - Metadata $metadata = null + ?Customer $customer = null, + ?Basket $basket = null, + ?Metadata $metadata = null ): Paypage { return $this->initPayPage($paypage, TransactionTypes::CHARGE, $customer, $basket, $metadata); } @@ -309,9 +309,9 @@ public function initPayPageCharge( */ public function initPayPageAuthorize( Paypage $paypage, - Customer $customer = null, - Basket $basket = null, - Metadata $metadata = null + ?Customer $customer = null, + ?Basket $basket = null, + ?Metadata $metadata = null ): Paypage { return $this->initPayPage($paypage, TransactionTypes::AUTHORIZATION, $customer, $basket, $metadata); } @@ -323,7 +323,7 @@ public function fetchInstallmentPlans( float $amount, string $currency, float $effectiveInterest, - DateTime $orderDate = null + ?DateTime $orderDate = null ): InstalmentPlans { $ins = (new InstallmentSecured(null, null, null))->setParentResource($this->unzer); $plans = (new InstalmentPlans($amount, $currency, $effectiveInterest, $orderDate))->setParentResource($ins); @@ -365,9 +365,9 @@ public function fetchPaylaterInstallmentPlans( private function initPayPage( Paypage $paypage, string $action, - Customer $customer = null, - Basket $basket = null, - Metadata $metadata = null + ?Customer $customer = null, + ?Basket $basket = null, + ?Metadata $metadata = null ): Paypage { $paypage->setAction($action)->setParentResource($this->unzer); $payment = $this->createPayment($paypage)->setBasket($basket)->setCustomer($customer)->setMetadata($metadata)->setPayPage($paypage); diff --git a/src/Services/ResourceService.php b/src/Services/ResourceService.php index 7658c672a..b854fbbe8 100755 --- a/src/Services/ResourceService.php +++ b/src/Services/ResourceService.php @@ -566,7 +566,7 @@ public function fetchBasket($basket): Basket try { $this->fetchResource($basketObj, $basketVersion); } catch (UnzerApiException $exception) { - if ($exception->getCode() !== ApiResponseCodes::API_ERROR_BASKET_NOT_FOUND || $isV3Basket) { + if ($exception->getCode() !== ApiResponseCodes::API_ERROR_BASKET_NOT_FOUND || $basketVersion === ApiVersions::V3) { throw $exception; } $this->fetchResource($basketObj); diff --git a/src/Services/WebhookService.php b/src/Services/WebhookService.php index c8117d185..a273bb567 100755 --- a/src/Services/WebhookService.php +++ b/src/Services/WebhookService.php @@ -2,14 +2,13 @@ namespace UnzerSDK\Services; -use UnzerSDK\Unzer; +use RuntimeException; use UnzerSDK\Interfaces\ResourceServiceInterface; use UnzerSDK\Interfaces\WebhookServiceInterface; use UnzerSDK\Resources\AbstractUnzerResource; use UnzerSDK\Resources\Webhook; use UnzerSDK\Resources\Webhooks; -use RuntimeException; - +use UnzerSDK\Unzer; use function is_string; /** @@ -165,7 +164,7 @@ public function registerMultipleWebhooks(string $url, array $events): array /** * {@inheritDoc} */ - public function fetchResourceFromEvent(string $eventJson = null): AbstractUnzerResource + public function fetchResourceFromEvent(?string $eventJson = null): AbstractUnzerResource { $resourceObject = null; $eventData = json_decode($eventJson ?? $this->readInputStream(), false); diff --git a/src/Traits/CanPayout.php b/src/Traits/CanPayout.php index a4f319f47..f03042d29 100644 --- a/src/Traits/CanPayout.php +++ b/src/Traits/CanPayout.php @@ -46,7 +46,7 @@ public function payout( $customer = null, ?string $orderId = null, $metadata = null, - Basket $basket = null, + ?Basket $basket = null, ?string $invoiceId = null, ?string $paymentReference = null ): Payout { diff --git a/src/Traits/CanPayoutWithCustomer.php b/src/Traits/CanPayoutWithCustomer.php index 9e597e0b2..76c5673e3 100644 --- a/src/Traits/CanPayoutWithCustomer.php +++ b/src/Traits/CanPayoutWithCustomer.php @@ -44,7 +44,7 @@ public function payout( $customer, ?string $orderId = null, $metadata = null, - Basket $basket = null + ?Basket $basket = null ): Payout { if ($this instanceof UnzerParentInterface) { return $this->getUnzerObject()->payout( diff --git a/src/Unzer.php b/src/Unzer.php index 076887aef..50f6a6602 100644 --- a/src/Unzer.php +++ b/src/Unzer.php @@ -667,7 +667,7 @@ public function registerMultipleWebhooks(string $url, array $events): array /** * {@inheritDoc} */ - public function fetchResourceFromEvent(string $eventJson = null): AbstractUnzerResource + public function fetchResourceFromEvent(?string $eventJson = null): AbstractUnzerResource { return $this->webhookService->fetchResourceFromEvent($eventJson); } @@ -679,8 +679,8 @@ public function performAuthorization( Authorization $authorization, $paymentType, $customer = null, - Metadata $metadata = null, - Basket $basket = null + ?Metadata $metadata = null, + ?Basket $basket = null ): Authorization { return $this->paymentService->performAuthorization($authorization, $paymentType, $customer, $metadata, $basket); @@ -735,8 +735,8 @@ public function performCharge( Charge $charge, $paymentType, $customer = null, - Metadata $metadata = null, - Basket $basket = null + ?Metadata $metadata = null, + ?Basket $basket = null ): Charge { return $this->paymentService->performCharge($charge, $paymentType, $customer, $metadata, $basket); @@ -786,7 +786,7 @@ public function charge( */ public function chargeAuthorization( $payment, - float $amount = null, + ?float $amount = null, ?string $orderId = null, ?string $invoiceId = null ): Charge @@ -799,7 +799,7 @@ public function chargeAuthorization( */ public function chargePayment( $payment, - float $amount = null, + ?float $amount = null, ?string $orderId = null, ?string $invoiceId = null ): Charge @@ -815,7 +815,7 @@ public function performChargeOnPayment($payment, Charge $charge): Charge /** * {@inheritDoc} */ - public function cancelAuthorization(Authorization $authorization, float $amount = null): Cancellation + public function cancelAuthorization(Authorization $authorization, ?float $amount = null): Cancellation { return $this->cancelService->cancelAuthorization($authorization, $amount); } @@ -823,7 +823,7 @@ public function cancelAuthorization(Authorization $authorization, float $amount /** * {@inheritDoc} */ - public function cancelAuthorizationByPayment($payment, float $amount = null): Cancellation + public function cancelAuthorizationByPayment($payment, ?float $amount = null): Cancellation { return $this->cancelService->cancelAuthorizationByPayment($payment, $amount); } @@ -833,11 +833,11 @@ public function cancelAuthorizationByPayment($payment, float $amount = null): Ca */ public function cancelPayment( $payment, - float $amount = null, + ?float $amount = null, ?string $reasonCode = CancelReasonCodes::REASON_CODE_CANCEL, ?string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?float $amountNet = null, + ?float $amountVat = null ): array { return $this->cancelService @@ -847,7 +847,7 @@ public function cancelPayment( /** * {@inheritDoc} */ - public function cancelPaymentAuthorization($payment, float $amount = null): ?Cancellation + public function cancelPaymentAuthorization($payment, ?float $amount = null): ?Cancellation { return $this->cancelService->cancelPaymentAuthorization($payment, $amount); } @@ -858,11 +858,11 @@ public function cancelPaymentAuthorization($payment, float $amount = null): ?Can public function cancelChargeById( $payment, string $chargeId, - float $amount = null, + ?float $amount = null, ?string $reasonCode = null, ?string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?float $amountNet = null, + ?float $amountVat = null ): Cancellation { return $this->cancelService @@ -874,11 +874,11 @@ public function cancelChargeById( */ public function cancelCharge( Charge $charge, - float $amount = null, + ?float $amount = null, ?string $reasonCode = null, ?string $referenceText = null, - float $amountNet = null, - float $amountVat = null + ?float $amountNet = null, + ?float $amountVat = null ): Cancellation { return $this->cancelService @@ -931,11 +931,11 @@ public function payout( $paymentType, string $returnUrl, $customer = null, - string $orderId = null, - Metadata $metadata = null, - Basket $basket = null, - string $invoiceId = null, - string $referenceText = null + ?string $orderId = null, + ?Metadata $metadata = null, + ?Basket $basket = null, + ?string $invoiceId = null, + ?string $referenceText = null ): Payout { return $this->paymentService->payout( @@ -1004,9 +1004,9 @@ public function fetchPaypageV2($paypage): PaypageV2 */ public function initPayPageCharge( Paypage $paypage, - Customer $customer = null, - Basket $basket = null, - Metadata $metadata = null + ?Customer $customer = null, + ?Basket $basket = null, + ?Metadata $metadata = null ): Paypage { return $this->paymentService->initPayPageCharge($paypage, $customer, $basket, $metadata); @@ -1017,9 +1017,9 @@ public function initPayPageCharge( */ public function initPayPageAuthorize( Paypage $paypage, - Customer $customer = null, - Basket $basket = null, - Metadata $metadata = null + ?Customer $customer = null, + ?Basket $basket = null, + ?Metadata $metadata = null ): Paypage { return $this->paymentService->initPayPageAuthorize($paypage, $customer, $basket, $metadata); @@ -1032,7 +1032,7 @@ public function fetchInstallmentPlans( float $amount, string $currency, float $effectiveInterest, - DateTime $orderDate = null + ?DateTime $orderDate = null ): InstalmentPlans { return $this->paymentService @@ -1078,7 +1078,7 @@ public function debugLog($message): void * @param string|null $jwtToken If set, the given token will be used instead as long it is valid. * @throws UnzerApiException */ - public function prepareJwtToken(string $jwtToken = null): string + public function prepareJwtToken(?string $jwtToken = null): string { if ($jwtToken !== null && JwtService::validateExpiryTime($jwtToken)) { $this->jwtToken = $jwtToken; From 48610cadf15d52dfcebec7fe0aa1d5003ec9356d Mon Sep 17 00:00:00 2001 From: "david.owusu" Date: Thu, 10 Jul 2025 10:52:49 +0200 Subject: [PATCH 3/5] [CC-1903 remove-php-8-4] cleanup phpdoc comments --- src/Exceptions/UnzerApiException.php | 2 +- .../GooglePay/SignedMessage.php | 5 -- src/Resources/TransactionTypes/Payout.php | 7 -- src/Services/HttpService.php | 69 ++++++++++--------- src/Services/PaymentService.php | 3 + src/Services/ResourceService.php | 2 +- 6 files changed, 40 insertions(+), 48 deletions(-) diff --git a/src/Exceptions/UnzerApiException.php b/src/Exceptions/UnzerApiException.php index 7a1d389b9..f9e1c44dd 100644 --- a/src/Exceptions/UnzerApiException.php +++ b/src/Exceptions/UnzerApiException.php @@ -26,7 +26,7 @@ class UnzerApiException extends Exception * * @param string $merchantMessage * @param string $clientMessage - * @param string $code + * @param string|null $code * @param string|null $errorId */ public function __construct($merchantMessage = '', $clientMessage = '', $code = null, ?string $errorId = null) diff --git a/src/Resources/EmbeddedResources/GooglePay/SignedMessage.php b/src/Resources/EmbeddedResources/GooglePay/SignedMessage.php index 6f6542d22..31dfa913c 100644 --- a/src/Resources/EmbeddedResources/GooglePay/SignedMessage.php +++ b/src/Resources/EmbeddedResources/GooglePay/SignedMessage.php @@ -15,11 +15,6 @@ class SignedMessage extends AbstractUnzerResource /** @var string */ protected $encryptedMessage; - /** - * @param string $tag - * @param string $ephemeralPublicKey - * @param string $encryptedMessage - */ public function __construct(?string $tag = null, ?string $ephemeralPublicKey = null, ?string $encryptedMessage = null) { $this->tag = $tag; diff --git a/src/Resources/TransactionTypes/Payout.php b/src/Resources/TransactionTypes/Payout.php index adae7eaf2..15f0767ca 100644 --- a/src/Resources/TransactionTypes/Payout.php +++ b/src/Resources/TransactionTypes/Payout.php @@ -24,13 +24,6 @@ class Payout extends AbstractTransactionType /** @var string $paymentReference */ protected $paymentReference; - /** - * Payout constructor. - * - * @param float|null $amount - * @param string|null $currency - * @param null $returnUrl - */ public function __construct(?float $amount = null, ?string $currency = null, $returnUrl = null) { $this->setAmount($amount); diff --git a/src/Services/HttpService.php b/src/Services/HttpService.php index 33fcc392d..d27bbdd56 100755 --- a/src/Services/HttpService.php +++ b/src/Services/HttpService.php @@ -18,7 +18,6 @@ * This service provides for functionalities concerning http transactions. * * @link https://docs.unzer.com/ - * */ class HttpService { @@ -82,26 +81,26 @@ public function setEnvironmentService(EnvironmentService $environmentService): H } /** - * @deprecated use sendRequest() instead. - * * send post request to payment server * - * @param $uri string|null uri of the target system + * @param string|null $uri uri of the target system * @param ?AbstractUnzerResource $resource - * @param string $httpMethod - * @param string $apiVersion + * @param string|null $httpMethod + * @param string|null $apiVersion * * @return string * * @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. + * @deprecated use sendRequest() instead. */ public function send( ?string $uri = null, ?AbstractUnzerResource $resource = null, string $httpMethod = HttpAdapterInterface::REQUEST_GET, ?string $apiVersion = null - ): string { + ): string + { if (!$resource instanceof AbstractUnzerResource) { throw new RuntimeException('Transfer object is empty!'); } @@ -116,14 +115,14 @@ public function send( * send post request to payment server * * @param ApiRequest $request + * * @return string * * @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 sendRequest( - ApiRequest $request - ): string { + public function sendRequest(ApiRequest $request): string + { $unzerObj = $request->getResource()->getUnzerObject(); $apiConfig = $request->getResource()->getApiConfig(); @@ -137,8 +136,8 @@ public function sendRequest( $headers = $this->composeHttpHeaders($unzerObj, $apiConfig::getAuthorizationMethod()); $httpMethod = $request->getHttpMethod(); $this->initRequest($requestUrl, $payload, $httpMethod, $headers); - $httpAdapter = $this->getAdapter(); - $response = $httpAdapter->execute(); + $httpAdapter = $this->getAdapter(); + $response = $httpAdapter->execute(); $responseCode = $httpAdapter->getResponseCode(); $httpAdapter->close(); @@ -158,7 +157,7 @@ public function sendRequest( * @param string $uri * @param string $payload * @param string $httpMethod - * @param array $httpHeaders + * @param array $httpHeaders * * @throws RuntimeException */ @@ -174,7 +173,7 @@ private function initRequest(string $uri, string $payload, string $httpMethod, a * Handles error responses by throwing an UnzerApiException with the returned messages and error code. * Returns doing nothing if no error occurred. * - * @param string $responseCode + * @param string $responseCode * @param string|null $response * * @throws UnzerApiException @@ -187,15 +186,15 @@ private function handleErrors(string $responseCode, ?string $response): void $responseObject = json_decode($response, false); if (!is_numeric($responseCode) || (int)$responseCode >= 400 || isset($responseObject->errors)) { - $code = null; - $errorId = null; + $code = null; + $errorId = null; $customerMessage = $code; $merchantMessage = $customerMessage; if (isset($responseObject->errors[0])) { - $errors = $responseObject->errors[0]; + $errors = $responseObject->errors[0]; $merchantMessage = $errors->merchantMessage ?? ''; $customerMessage = $errors->customerMessage ?? ''; - $code = $errors->code ?? ''; + $code = $errors->code ?? ''; } if (isset($responseObject->id)) { $errorId = $responseObject->id; @@ -209,23 +208,24 @@ private function handleErrors(string $responseCode, ?string $response): void } /** - * @param Unzer $unzerObj - * @param string $payload - * @param mixed $headers - * @param string $responseCode - * @param string $httpMethod - * @param string $url + * @param Unzer $unzerObj + * @param string $payload + * @param mixed $headers + * @param string $responseCode + * @param string $httpMethod + * @param string $url * @param string|null $response */ public function debugLog( Unzer $unzerObj, string $payload, - $headers, - string $responseCode, + $headers, + string $responseCode, string $httpMethod, string $url, ?string $response - ): void { + ): void + { // mask auth string $authHeader = explode(' ', $headers['Authorization']); $authHeader[1] = ValueService::maskValue($authHeader[1]); @@ -275,16 +275,16 @@ private function buildRequestUrl(ApiRequest $request): string */ public function composeHttpHeaders(Unzer $unzer, string $authorizationMethod = AuthorizationMethods::BASIC): array { - $locale = $unzer->getLocale(); - $clientIp = $unzer->getClientIp(); - $key = $unzer->getKey(); + $locale = $unzer->getLocale(); + $clientIp = $unzer->getClientIp(); + $key = $unzer->getKey(); $httpHeaders = [ 'Authorization' => $this->findAuthentication($unzer, $authorizationMethod), - 'Content-Type' => 'application/json', - 'SDK-VERSION' => Unzer::SDK_VERSION, - 'SDK-TYPE' => Unzer::SDK_TYPE, - 'PHP-VERSION' => PHP_VERSION + 'Content-Type' => 'application/json', + 'SDK-VERSION' => Unzer::SDK_VERSION, + 'SDK-TYPE' => Unzer::SDK_TYPE, + 'PHP-VERSION' => PHP_VERSION ]; if (!empty($locale)) { $httpHeaders['Accept-Language'] = $locale; @@ -347,6 +347,7 @@ public function isApiConfig($className): bool /** * @param Unzer $unzer + * * @return string */ private function findAuthentication(Unzer $unzer, string $authorizationMethod = AuthorizationMethods::BASIC): string diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index bb1e64667..8eefc3597 100755 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -73,6 +73,9 @@ public function getResourceService(): ResourceService return $this->getUnzer()->getResourceService(); } + /** + * {@inheritDoc} + */ public function performAuthorization( Authorization $authorization, $paymentType, diff --git a/src/Services/ResourceService.php b/src/Services/ResourceService.php index b854fbbe8..5fe229705 100755 --- a/src/Services/ResourceService.php +++ b/src/Services/ResourceService.php @@ -338,7 +338,7 @@ public function deleteResource(AbstractUnzerResource &$resource): ?AbstractUnzer * Updates the given local resource object (id must be set) * * @param AbstractUnzerResource $resource The local resource object to update. - * @param string $apiVersion + * @param string|null $apiVersion * * @return AbstractUnzerResource The updated resource object. * From dc0afb8b8815345cf822e8e9adfd862b1f23026e Mon Sep 17 00:00:00 2001 From: "david.owusu" Date: Thu, 10 Jul 2025 11:13:06 +0200 Subject: [PATCH 4/5] [CC-1903 remove-php-8-4] cleanup phpdoc comments --- src/Services/HttpService.php | 8 ++------ src/Services/ResourceService.php | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Services/HttpService.php b/src/Services/HttpService.php index d27bbdd56..cce644cb5 100755 --- a/src/Services/HttpService.php +++ b/src/Services/HttpService.php @@ -84,8 +84,8 @@ public function setEnvironmentService(EnvironmentService $environmentService): H * send post request to payment server * * @param string|null $uri uri of the target system - * @param ?AbstractUnzerResource $resource - * @param string|null $httpMethod + * @param AbstractUnzerResource|null $resource + * @param string $httpMethod * @param string|null $apiVersion * * @return string @@ -114,10 +114,6 @@ public function send( /** * send post request to payment server * - * @param ApiRequest $request - * - * @return string - * * @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. */ diff --git a/src/Services/ResourceService.php b/src/Services/ResourceService.php index 5fe229705..2b2d1c922 100755 --- a/src/Services/ResourceService.php +++ b/src/Services/ResourceService.php @@ -110,7 +110,7 @@ public function setUnzer(Unzer $unzer): ResourceServiceInterface * * @param AbstractUnzerResource $resource * @param string $httpMethod - * @param string $apiVersion + * @param string|null $apiVersion * * @return stdClass * From 13e46667089ccb8d58c17351d9f77472fcd31efa Mon Sep 17 00:00:00 2001 From: "david.owusu" Date: Thu, 10 Jul 2025 11:20:46 +0200 Subject: [PATCH 5/5] [CC-1903 remove-php-8-4] cleanup phpdoc comments --- src/Unzer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Unzer.php b/src/Unzer.php index 50f6a6602..b86d9fb8a 100644 --- a/src/Unzer.php +++ b/src/Unzer.php @@ -95,7 +95,7 @@ class Unzer implements * Construct a new Unzer object. * * @param string $key The private key your received from your Unzer contact person. - * @param ?string $locale The locale of the customer defining defining the translation (e.g. 'en-GB' or 'de-DE'). + * @param string|null $locale The locale of the customer defining defining the translation (e.g. 'en-GB' or 'de-DE'). * * @throws RuntimeException A RuntimeException will be thrown if the key is not of type private. *