From e965f347daea1cea43a65fca2b17b9fdaddd9343 Mon Sep 17 00:00:00 2001 From: kGablo Date: Fri, 19 Jan 2024 08:59:48 +0100 Subject: [PATCH] Form fix --- Api/TpayInterface.php | 5 ++++- Model/ConstraintValidator.php | 5 +++++ Model/MethodListPlugin.php | 15 ++++++++++++++- Model/Tpay.php | 12 ++++++++++-- Service/TpayService.php | 1 - .../web/template/payment/card-tpay-form.html | 3 ++- view/frontend/web/template/payment/tpay-form.html | 2 +- 7 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Api/TpayInterface.php b/Api/TpayInterface.php index 8f2c0ca..f9576a6 100644 --- a/Api/TpayInterface.php +++ b/Api/TpayInterface.php @@ -71,7 +71,6 @@ public function useSandboxMode(): bool; /** Check if checkout amount is in range of installments payment channel */ public function getInstallmentsAmountValid(): bool; - // KARTY public function getCardApiKey(): ?string; public function getCardApiPassword(): ?string; @@ -88,6 +87,10 @@ public function getHashType(): ?string; public function getVerificationCode(): ?string; + public function isAllowSpecific(): bool; + + public function getSpecificCountry(): array; + /** @param string $orderId */ public function getCustomerId($orderId); diff --git a/Model/ConstraintValidator.php b/Model/ConstraintValidator.php index d0a4949..9046b0c 100644 --- a/Model/ConstraintValidator.php +++ b/Model/ConstraintValidator.php @@ -40,6 +40,11 @@ public function validate(array $constraints): bool return true; } + public function isClientCountryValid(bool $isAllowed, string $clientCountry, array $specificCountry): bool + { + return $isAllowed && !in_array($clientCountry, $specificCountry); + } + private function validateMinimalTotal(float $minimal): bool { return $this->checkoutSession->getQuote()->getGrandTotal() > $minimal; diff --git a/Model/MethodListPlugin.php b/Model/MethodListPlugin.php index f4439b5..38d0a63 100644 --- a/Model/MethodListPlugin.php +++ b/Model/MethodListPlugin.php @@ -67,6 +67,10 @@ public function afterGetAvailableMethods(MethodList $compiled, $result) $channelList = $onsiteChannels ? explode(',', $onsiteChannels) : []; $channels = $this->transactions->channels(); + if ($this->constraintValidator->isClientCountryValid($this->tpay->isAllowSpecific(), $this->checkoutSession->getQuote()->getBillingAddress()->getCountryId(), $this->tpay->getSpecificCountry())) { + return []; + } + if (!$this->tpay->isCartValid($this->checkoutSession->getQuote()->getGrandTotal())) { return $result; } @@ -74,6 +78,10 @@ public function afterGetAvailableMethods(MethodList $compiled, $result) $result = $this->addCardMethod($result); $result = $this->filterResult($result); + if (!$this->transactions->isOpenApiUse() || !$this->isPlnPayment()) { + return $result; + } + foreach ($channelList as $onsiteChannel) { $channel = $channels[$onsiteChannel]; @@ -111,7 +119,7 @@ private function addCardMethod(array $result): array private function filterResult(array $result): array { - if ('PLN' === $this->storeManager->getStore()->getCurrentCurrencyCode()) { + if ($this->isPlnPayment()) { return $result; } @@ -119,4 +127,9 @@ private function filterResult(array $result): array return 'tpaycom_magento2basic' !== $method->getCode(); }); } + + private function isPlnPayment(): bool + { + return 'PLN' === $this->storeManager->getStore()->getCurrentCurrencyCode(); + } } diff --git a/Model/Tpay.php b/Model/Tpay.php index 1e235a4..bfdca5a 100755 --- a/Model/Tpay.php +++ b/Model/Tpay.php @@ -317,7 +317,6 @@ public function assignData(DataObject $data) $info->setAdditionalInformation(static::TERMS_ACCEPT, isset($additionalData[static::TERMS_ACCEPT]) ? '1' === $additionalData[static::TERMS_ACCEPT] : false); - // KARTY $info->setAdditionalInformation(static::CARDDATA, $additionalData[static::CARDDATA] ?? ''); $info->setAdditionalInformation(static::CARD_VENDOR, isset($additionalData[static::CARD_VENDOR]) && in_array($additionalData[static::CARD_VENDOR], $this->supportedVendors) ? $additionalData[static::CARD_VENDOR] : 'undefined'); $info->setAdditionalInformation(static::CARD_SAVE, isset($additionalData[static::CARD_SAVE]) ? '1' === $additionalData[static::CARD_SAVE] : false); @@ -381,7 +380,6 @@ public function getConfigData($field, $storeId = null) return parent::getConfigData($field, $storeId); } - // KARTY public function getCardSaveEnabled(): bool { return (bool) $this->getConfigData('cardpayment_settings/card_save_enabled'); @@ -422,6 +420,16 @@ public function getVerificationCode(): string return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/verification_code'); } + public function isAllowSpecific(): bool + { + return (bool) $this->getConfigData('sale_settings/allowspecific') ?? false; + } + + public function getSpecificCountry(): array + { + return $this->getConfigData('sale_settings/specificcountry') ? explode(',', $this->getConfigData('sale_settings/specificcountry')) : []; + } + /** * @param string $orderId * diff --git a/Service/TpayService.php b/Service/TpayService.php index 3810ecd..327d219 100644 --- a/Service/TpayService.php +++ b/Service/TpayService.php @@ -145,7 +145,6 @@ public function getOrderById(string $orderId): OrderInterface return $this->orderRepository->getByIncrementId($orderId); } - // KARTY public function setCardOrderStatus($orderId, array $validParams, $tpayModel) { /** @var Order $order */ diff --git a/view/frontend/web/template/payment/card-tpay-form.html b/view/frontend/web/template/payment/card-tpay-form.html index 46f78a7..de4fa4e 100644 --- a/view/frontend/web/template/payment/card-tpay-form.html +++ b/view/frontend/web/template/payment/card-tpay-form.html @@ -75,7 +75,7 @@ +