From 833020ab35d9241cbf4565e8dd3bb203ea5c8191 Mon Sep 17 00:00:00 2001 From: SimonZanta Date: Thu, 16 Apr 2026 12:36:41 +0200 Subject: [PATCH 1/5] - three state boolean for some params --- src/Entity/Payment.php | 12 ++++++------ src/Entity/Request/PaymentCreateRequest.php | 9 +++++++-- .../Entity/Request/PaymentCreateRequestCest.php | 8 ++++---- tests/Unit/Entity/PaymentCest.php | 4 ++-- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Entity/Payment.php b/src/Entity/Payment.php index 9a96cb3..97ff200 100644 --- a/src/Entity/Payment.php +++ b/src/Entity/Payment.php @@ -44,8 +44,8 @@ class Payment 'url_paid' => '', 'url_cancelled' => '', 'url_pending' => '', - 'chargeUnregulatedCardFees' => false, - 'enableApplePayGooglePay' => true, + 'chargeUnregulatedCardFees' => null, + 'enableApplePayGooglePay' => null, 'prepareOnly' => true, 'embedded' => false, 'allowedMethods' => [], @@ -634,9 +634,9 @@ public function setUrlPendingRedirect(string $urlPending): self return $this; } - public function getChargeUnregulatedCardFees(): bool + public function getChargeUnregulatedCardFees(): ?bool { - return $this->getParam('chargeUnregulatedCardFees'); + return $this->params['chargeUnregulatedCardFees'] ?? null; } public function setChargeUnregulatedCardFees(bool $chargeUnregulatedCardFees): self @@ -650,9 +650,9 @@ public function setChargeUnregulatedCardFees(bool $chargeUnregulatedCardFees): s * Vrací true/false/null hodnotu zapnutého Google/Apple pay. * @return null|bool */ - public function getEnableApplePayGooglePay() + public function getEnableApplePayGooglePay(): ?bool { - return $this->getParam('enableApplePayGooglePay'); + return $this->params['enableApplePayGooglePay'] ?? null; } /** diff --git a/src/Entity/Request/PaymentCreateRequest.php b/src/Entity/Request/PaymentCreateRequest.php index a5f7c3b..bb4a110 100644 --- a/src/Entity/Request/PaymentCreateRequest.php +++ b/src/Entity/Request/PaymentCreateRequest.php @@ -72,8 +72,13 @@ public function toArray(): array $output['url_paid'] = $this->payment->getUrlPaidRedirect() ?? ''; $output['url_cancelled'] = $this->payment->getUrlCancelledRedirect() ?? ''; $output['url_pending'] = $this->payment->getUrlPendingRedirect() ?? ''; - $output['chargeUnregulatedCardFees'] = $this->payment->getChargeUnregulatedCardFees() ? 'true' : 'false'; - $output['enableApplePayGooglePay'] = $this->payment->getEnableApplePayGooglePay() ? 'true' : 'false'; + if($this->payment->getChargeUnregulatedCardFees() !== null) { + $output['chargeUnregulatedCardFees'] = $this->payment->getChargeUnregulatedCardFees() ? 'true' : 'false'; + } + + if($this->payment->getEnableApplePayGooglePay() !== null) { + $output['enableApplePayGooglePay'] = $this->payment->getEnableApplePayGooglePay() ? 'true' : 'false'; + } $output['embedded'] = $this->payment->isEmbedded() ? 'true' : 'false'; return $output; diff --git a/tests/Integration/Entity/Request/PaymentCreateRequestCest.php b/tests/Integration/Entity/Request/PaymentCreateRequestCest.php index d2c0f85..295cd96 100644 --- a/tests/Integration/Entity/Request/PaymentCreateRequestCest.php +++ b/tests/Integration/Entity/Request/PaymentCreateRequestCest.php @@ -60,8 +60,8 @@ protected function getPaymentScenarios(){ 'url_paid' => '', 'url_cancelled' => '', 'url_pending' => '', - 'chargeUnregulatedCardFees' => 'false', - 'enableApplePayGooglePay' => 'true', + 'chargeUnregulatedCardFees' => null, + 'enableApplePayGooglePay' => null, 'initRecurringId' => '', ], @@ -113,8 +113,8 @@ protected function getPaymentScenarios(){ 'url_paid' => '', 'url_cancelled' => '', 'url_pending' => '', - 'chargeUnregulatedCardFees' => 'false', - 'enableApplePayGooglePay' => 'true', + 'chargeUnregulatedCardFees' => null, + 'enableApplePayGooglePay' => null, 'country' => '', 'curr' => '', 'label' => '', diff --git a/tests/Unit/Entity/PaymentCest.php b/tests/Unit/Entity/PaymentCest.php index b4ff48e..275efbb 100644 --- a/tests/Unit/Entity/PaymentCest.php +++ b/tests/Unit/Entity/PaymentCest.php @@ -70,8 +70,8 @@ public function getParamsTest(UnitTester $I) 'url_paid' => '', 'url_cancelled' => '', 'url_pending' => '', - 'chargeUnregulatedCardFees' => false, - 'enableApplePayGooglePay' => true, + 'chargeUnregulatedCardFees' => null, + 'enableApplePayGooglePay' => null, 'initRecurringId' => '', ], $paymentParams); From 3cf7f11beaa2a9db28b9a673b88bb1348ec3c7f7 Mon Sep 17 00:00:00 2001 From: SimonZanta Date: Thu, 16 Apr 2026 12:44:22 +0200 Subject: [PATCH 2/5] unset variable --- src/Entity/Request/PaymentCreateRequest.php | 6 ++++++ .../Entity/Request/PaymentCreateRequestCest.php | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Entity/Request/PaymentCreateRequest.php b/src/Entity/Request/PaymentCreateRequest.php index bb4a110..58250ef 100644 --- a/src/Entity/Request/PaymentCreateRequest.php +++ b/src/Entity/Request/PaymentCreateRequest.php @@ -72,13 +72,19 @@ public function toArray(): array $output['url_paid'] = $this->payment->getUrlPaidRedirect() ?? ''; $output['url_cancelled'] = $this->payment->getUrlCancelledRedirect() ?? ''; $output['url_pending'] = $this->payment->getUrlPendingRedirect() ?? ''; + if($this->payment->getChargeUnregulatedCardFees() !== null) { $output['chargeUnregulatedCardFees'] = $this->payment->getChargeUnregulatedCardFees() ? 'true' : 'false'; + } else { + unset($output['chargeUnregulatedCardFees']); } if($this->payment->getEnableApplePayGooglePay() !== null) { $output['enableApplePayGooglePay'] = $this->payment->getEnableApplePayGooglePay() ? 'true' : 'false'; + } else { + unset($output['enableApplePayGooglePay']); } + $output['embedded'] = $this->payment->isEmbedded() ? 'true' : 'false'; return $output; diff --git a/tests/Integration/Entity/Request/PaymentCreateRequestCest.php b/tests/Integration/Entity/Request/PaymentCreateRequestCest.php index 295cd96..5b690c1 100644 --- a/tests/Integration/Entity/Request/PaymentCreateRequestCest.php +++ b/tests/Integration/Entity/Request/PaymentCreateRequestCest.php @@ -60,8 +60,6 @@ protected function getPaymentScenarios(){ 'url_paid' => '', 'url_cancelled' => '', 'url_pending' => '', - 'chargeUnregulatedCardFees' => null, - 'enableApplePayGooglePay' => null, 'initRecurringId' => '', ], @@ -81,6 +79,8 @@ protected function getPaymentScenarios(){ ->setUrlPaid('https://example.com/paid') ->setUrlPending('https://example.com/pending') ->setUrlCancelled('https://example.com/cancelled') + ->setEnableApplePayGooglePay(true) + ->setChargeUnregulatedCardFees(true) , 'result' => [ 'initRecurring' => 'true', @@ -113,8 +113,8 @@ protected function getPaymentScenarios(){ 'url_paid' => '', 'url_cancelled' => '', 'url_pending' => '', - 'chargeUnregulatedCardFees' => null, - 'enableApplePayGooglePay' => null, + 'chargeUnregulatedCardFees' => true, + 'enableApplePayGooglePay' => true, 'country' => '', 'curr' => '', 'label' => '', From 528dc3b28e21a0e4d0ed67e762422e4f33acb35c Mon Sep 17 00:00:00 2001 From: SimonZanta Date: Thu, 16 Apr 2026 12:47:30 +0200 Subject: [PATCH 3/5] fix: correct test expectations for boolean params to use string 'true'/'false' chargeUnregulatedCardFees and enableApplePayGooglePay are serialized as strings 'true'/'false' in toArray(), not PHP booleans. Update test expectations to match actual output type. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/Integration/Entity/Request/PaymentCreateRequestCest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Integration/Entity/Request/PaymentCreateRequestCest.php b/tests/Integration/Entity/Request/PaymentCreateRequestCest.php index 5b690c1..31b3ac9 100644 --- a/tests/Integration/Entity/Request/PaymentCreateRequestCest.php +++ b/tests/Integration/Entity/Request/PaymentCreateRequestCest.php @@ -113,8 +113,8 @@ protected function getPaymentScenarios(){ 'url_paid' => '', 'url_cancelled' => '', 'url_pending' => '', - 'chargeUnregulatedCardFees' => true, - 'enableApplePayGooglePay' => true, + 'chargeUnregulatedCardFees' => 'true', + 'enableApplePayGooglePay' => 'true', 'country' => '', 'curr' => '', 'label' => '', From 88652156f3207c4da258d79a2bdf5bfd3e8e79a0 Mon Sep 17 00:00:00 2001 From: SimonZanta Date: Fri, 17 Apr 2026 08:59:04 +0200 Subject: [PATCH 4/5] Enable empty string as a valid value --- src/Entity/Payment.php | 18 +++- .../Request/PaymentCreateRequestCest.php | 88 +++++++++++++++++++ 2 files changed, 102 insertions(+), 4 deletions(-) diff --git a/src/Entity/Payment.php b/src/Entity/Payment.php index 97ff200..bfd9ec2 100644 --- a/src/Entity/Payment.php +++ b/src/Entity/Payment.php @@ -636,10 +636,15 @@ public function setUrlPendingRedirect(string $urlPending): self public function getChargeUnregulatedCardFees(): ?bool { - return $this->params['chargeUnregulatedCardFees'] ?? null; + if ($this->params['chargeUnregulatedCardFees'] === '' || $this->params['chargeUnregulatedCardFees'] === null) { + return null; + } + + // aby se mi vracelo true a false jako boolean + return filter_var($this->params['chargeUnregulatedCardFees'],FILTER_VALIDATE_BOOLEAN); } - public function setChargeUnregulatedCardFees(bool $chargeUnregulatedCardFees): self + public function setChargeUnregulatedCardFees($chargeUnregulatedCardFees): self { $this->setParam('chargeUnregulatedCardFees', $chargeUnregulatedCardFees); @@ -652,13 +657,18 @@ public function setChargeUnregulatedCardFees(bool $chargeUnregulatedCardFees): s */ public function getEnableApplePayGooglePay(): ?bool { - return $this->params['enableApplePayGooglePay'] ?? null; + if ($this->params['enableApplePayGooglePay'] === '' || $this->params['enableApplePayGooglePay'] === null) { + return null; + } + + // aby se mi vracelo true a false jako boolean + return filter_var($this->params['enableApplePayGooglePay'],FILTER_VALIDATE_BOOLEAN); } /** * Explicitně umožňuje povolení Apple Pay a Google Pay na platbách s přirážkami za neregulovanou kartu. Případně pro přímé zakázání pro konkrétní platbu * - * @param null|bool $enableApplePayGooglePay + * @param null|bool|string $enableApplePayGooglePay * @return Payment */ // Použit komentář místo parametrového typu kvůli nekompatibilitě s null hodnotou. diff --git a/tests/Integration/Entity/Request/PaymentCreateRequestCest.php b/tests/Integration/Entity/Request/PaymentCreateRequestCest.php index 31b3ac9..25a426b 100644 --- a/tests/Integration/Entity/Request/PaymentCreateRequestCest.php +++ b/tests/Integration/Entity/Request/PaymentCreateRequestCest.php @@ -124,6 +124,94 @@ protected function getPaymentScenarios(){ 'initRecurringId' => '', ], ], + '3 state bool empty str' => [ + 'payment' => (new Payment()) + ->setPrice(Money::ofInt(123)) + ->setEnableApplePayGooglePay('') + ->setChargeUnregulatedCardFees('') + , + 'result' => [ + 'test' => 'false', + 'prepareOnly' => 'true', + 'preauth' => 'false', + 'verification' => 'false', + 'embedded' => 'false', + 'method' => '', + 'initRecurring' => 'false', + 'account' => '', + 'name' => '', + 'price' => 12300, + 'dynamicExpiration' => 'false', + 'country' => '', + 'curr' => '', + 'label' => '', + 'refId' => '', + 'email' => '', + 'phone' => '', + 'fullName' => '', + 'billingAddrCity' => '', + 'billingAddrStreet' => '', + 'billingAddrPostalCode' => '', + 'billingAddrCountry' => '', + 'delivery' => '', + 'homeDeliveryCity' => '', + 'homeDeliveryStreet' => '', + 'homeDeliveryPostalCode' => '', + 'homeDeliveryCountry' => '', + 'category' => '', + 'lang' => '', + 'expirationTime' => '', + 'url_paid' => '', + 'url_cancelled' => '', + 'url_pending' => '', + 'initRecurringId' => '', + ], + ], + '3 state bool true false' => [ + 'payment' => (new Payment()) + ->setPrice(Money::ofInt(123)) + ->setEnableApplePayGooglePay('true') + ->setChargeUnregulatedCardFees('false') + , + 'result' => [ + 'test' => 'false', + 'prepareOnly' => 'true', + 'preauth' => 'false', + 'verification' => 'false', + 'embedded' => 'false', + 'method' => '', + 'initRecurring' => 'false', + 'account' => '', + 'name' => '', + 'price' => 12300, + 'dynamicExpiration' => 'false', + 'country' => '', + 'curr' => '', + 'label' => '', + 'refId' => '', + 'email' => '', + 'phone' => '', + 'fullName' => '', + 'billingAddrCity' => '', + 'billingAddrStreet' => '', + 'billingAddrPostalCode' => '', + 'billingAddrCountry' => '', + 'delivery' => '', + 'homeDeliveryCity' => '', + 'homeDeliveryStreet' => '', + 'homeDeliveryPostalCode' => '', + 'homeDeliveryCountry' => '', + 'category' => '', + 'lang' => '', + 'expirationTime' => '', + 'url_paid' => '', + 'url_cancelled' => '', + 'url_pending' => '', + 'initRecurringId' => '', + 'chargeUnregulatedCardFees' => 'false', + 'enableApplePayGooglePay' => 'true', + ], + ], ]; } } From 836c7ee86eb1c4cce3df78b24737099c34990ba9 Mon Sep 17 00:00:00 2001 From: SimonZanta Date: Fri, 17 Apr 2026 09:17:24 +0200 Subject: [PATCH 5/5] phpstan --- src/Entity/Payment.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Entity/Payment.php b/src/Entity/Payment.php index bfd9ec2..850d9b8 100644 --- a/src/Entity/Payment.php +++ b/src/Entity/Payment.php @@ -10,7 +10,7 @@ class Payment /** * Payment parameters. * - * @var array> + * @var array|null> */ protected $params = [ 'test' => false, @@ -636,7 +636,7 @@ public function setUrlPendingRedirect(string $urlPending): self public function getChargeUnregulatedCardFees(): ?bool { - if ($this->params['chargeUnregulatedCardFees'] === '' || $this->params['chargeUnregulatedCardFees'] === null) { + if ($this->params['chargeUnregulatedCardFees'] === null || $this->params['chargeUnregulatedCardFees'] === '') { return null; } @@ -644,6 +644,12 @@ public function getChargeUnregulatedCardFees(): ?bool return filter_var($this->params['chargeUnregulatedCardFees'],FILTER_VALIDATE_BOOLEAN); } + /** + * Explicitně umožňuje přidat přirážku za neregulovanou kartu na platby s Apple Pay a Google Pay. Případně pro přímé zakázání pro konkrétní platbu + * + * @param null|bool|string $chargeUnregulatedCardFees + * @return Payment + */ public function setChargeUnregulatedCardFees($chargeUnregulatedCardFees): self { $this->setParam('chargeUnregulatedCardFees', $chargeUnregulatedCardFees); @@ -657,7 +663,7 @@ public function setChargeUnregulatedCardFees($chargeUnregulatedCardFees): self */ public function getEnableApplePayGooglePay(): ?bool { - if ($this->params['enableApplePayGooglePay'] === '' || $this->params['enableApplePayGooglePay'] === null) { + if ($this->params['enableApplePayGooglePay'] === null || $this->params['enableApplePayGooglePay'] === '') { return null; }