From dd7e542153659829df774e1ccaffcdbd5897cbcc Mon Sep 17 00:00:00 2001 From: kGablo Date: Tue, 16 Jan 2024 14:18:19 +0100 Subject: [PATCH] Add card group --- Api/TpayInterface.php | 12 +++ .../CardTransaction/CardApiFacade.php | 8 +- Model/ApiFacade/TpayConfig/ConfigFacade.php | 8 +- .../Transaction/TransactionApiFacade.php | 13 +++ Model/MethodListPlugin.php | 11 +- Model/Tpay.php | 35 +++++- etc/adminhtml/system.xml | 101 +++++++++++------- 7 files changed, 144 insertions(+), 44 deletions(-) diff --git a/Api/TpayInterface.php b/Api/TpayInterface.php index d8a7983..8f2c0ca 100644 --- a/Api/TpayInterface.php +++ b/Api/TpayInterface.php @@ -26,8 +26,20 @@ public function getRedirectURL(): string; /** Return data for form */ public function getTpayFormData(?string $orderId = null): array; + public function getCardTitle(): ?string; + + public function isOriginApiEnabled(): bool; + + public function isOpenApiEnabled(): bool; + + public function isCardEnabled(): bool; + + public function isOriginApiCardUse(): bool; + public function getApiPassword(): ?string; + public function getOpenApiPassword(): ?string; + public function getApiKey(): ?string; public function getSecurityCode(): ?string; diff --git a/Model/ApiFacade/CardTransaction/CardApiFacade.php b/Model/ApiFacade/CardTransaction/CardApiFacade.php index 4124d5f..20c0382 100755 --- a/Model/ApiFacade/CardTransaction/CardApiFacade.php +++ b/Model/ApiFacade/CardTransaction/CardApiFacade.php @@ -41,6 +41,12 @@ private function getCurrent() private function createCardOriginApiInstance(TpayInterface $tpay, TpayTokensService $tokensService, TpayService $tpayService) { + if (!$tpay->isOriginApiEnabled()()){ + $this->cardOrigin = null; + + return; + } + try { $this->cardOrigin = new CardOrigin($tpay, $tokensService, $tpayService); } catch (Exception $exception) { @@ -50,7 +56,7 @@ private function createCardOriginApiInstance(TpayInterface $tpay, TpayTokensServ private function createOpenApiInstance(TpayInterface $tpay, TpayTokensService $tokensService, TpayService $tpayService) { - if ('PLN' !== $this->storeManager->getStore()->getCurrentCurrencyCode()) { + if ('PLN' !== $this->storeManager->getStore()->getCurrentCurrencyCode() && !$tpay->isOpenApiEnabled()) { $this->cardOpen = null; $this->useOpenCard = false; diff --git a/Model/ApiFacade/TpayConfig/ConfigFacade.php b/Model/ApiFacade/TpayConfig/ConfigFacade.php index 06d1d6c..57380b3 100755 --- a/Model/ApiFacade/TpayConfig/ConfigFacade.php +++ b/Model/ApiFacade/TpayConfig/ConfigFacade.php @@ -37,6 +37,12 @@ private function getCurrentApi() private function createOriginApiInstance(TpayInterface $tpay, Repository $assetRepository, TpayTokensService $tokensService) { + if (!$tpay->isOriginApiEnabled()){ + $this->originApi = null; + + return; + } + try { $this->originApi = new ConfigOrigin($tpay, $assetRepository, $tokensService); } catch (Exception $exception) { @@ -46,7 +52,7 @@ private function createOriginApiInstance(TpayInterface $tpay, Repository $assetR private function createOpenApiInstance(TpayInterface $tpay, Repository $assetRepository, TpayTokensService $tokensService, StoreManagerInterface $storeManager) { - if ('PLN' !== $storeManager->getStore()->getCurrentCurrencyCode()) { + if ('PLN' !== $storeManager->getStore()->getCurrentCurrencyCode() && !$tpay->isOpenApiEnabled()) { $this->openApi = null; $this->useOpenApi = false; diff --git a/Model/ApiFacade/Transaction/TransactionApiFacade.php b/Model/ApiFacade/Transaction/TransactionApiFacade.php index 377cae1..beda31b 100755 --- a/Model/ApiFacade/Transaction/TransactionApiFacade.php +++ b/Model/ApiFacade/Transaction/TransactionApiFacade.php @@ -86,6 +86,12 @@ private function getCurrentApi() private function createOriginApiInstance(TpayInterface $tpay) { + if (!$tpay->isOriginApiEnabled()){ + $this->originApi = null; + + return; + } + try { $this->originApi = new TransactionOriginApi($tpay->getApiPassword(), $tpay->getApiKey(), $tpay->getMerchantId(), $tpay->getSecurityCode(), !$tpay->useSandboxMode()); } catch (Exception $exception) { @@ -95,6 +101,13 @@ private function createOriginApiInstance(TpayInterface $tpay) private function createOpenApiInstance(TpayInterface $tpay) { + if (!$tpay->isOpenApiEnabled()) { + $this->openApi = null; + $this->useOpenApi = false; + + return; + } + try { $this->openApi = new OpenApi($tpay->getOpenApiClientId(), $tpay->getOpenApiPassword(), !$tpay->useSandboxMode()); $this->openApi->authorization(); diff --git a/Model/MethodListPlugin.php b/Model/MethodListPlugin.php index d191164..f4439b5 100644 --- a/Model/MethodListPlugin.php +++ b/Model/MethodListPlugin.php @@ -71,7 +71,7 @@ public function afterGetAvailableMethods(MethodList $compiled, $result) return $result; } - $result[] = $this->getMethodInstance('tpay.com - Płatność kartą', 'tpaycom_magento2basic_cards'); + $result = $this->addCardMethod($result); $result = $this->filterResult($result); foreach ($channelList as $onsiteChannel) { @@ -100,6 +100,15 @@ public function getMethodInstance(string $title, string $code): MethodInterface return $method; } + private function addCardMethod(array $result): array + { + if ($this->tpay->isCardEnabled()) { + $result[] = $this->getMethodInstance($this->tpay->getCardTitle(), 'tpaycom_magento2basic_cards'); + } + + return $result; + } + private function filterResult(array $result): array { if ('PLN' === $this->storeManager->getStore()->getCurrentCurrencyCode()) { diff --git a/Model/Tpay.php b/Model/Tpay.php index 4a073b7..79e8938 100755 --- a/Model/Tpay.php +++ b/Model/Tpay.php @@ -152,7 +152,7 @@ public function getApiKey(): ?string public function getCardApiKey(): ?string { - return $this->getConfigData('originapi_settings/card_api_key_tpay'); + return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/card_api_key_tpay'); } public function getApiPassword(): ?string @@ -162,7 +162,7 @@ public function getApiPassword(): ?string public function getCardApiPassword(): ?string { - return $this->getConfigData('originapi_settings/card_api_password'); + return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/card_api_password'); } public function getInvoiceSendMail(): string @@ -175,7 +175,7 @@ public function getTermsURL(): string return $this->termsURL; } - public function getOpenApiPassword() + public function getOpenApiPassword(): ?string { return $this->getConfigData('openapi_settings/open_api_password'); } @@ -249,6 +249,31 @@ public function getTitle(): string return $this->_title ?? $this->getConfigData('general_settings/title'); } + public function getCardTitle(): ?string + { + return $this->getConfigData('cardpayment_settings/card_title') ?? ''; + } + + public function isOriginApiEnabled(): bool + { + return (bool) $this->getConfigData('originapi_settings/origin_api_active'); + } + + public function isOpenApiEnabled(): bool + { + return (bool) $this->getConfigData('openapi_settings/open_api_active'); + } + + public function isCardEnabled(): bool + { + return (bool) $this->getConfigData('cardpayment_settings/cardpayment_api_active'); + } + + public function isOriginApiCardUse(): bool + { + return (bool) $this->getConfigData('cardpayment_settings/cardpayment_origin_api_use'); + } + public function useSandboxMode(): bool { return (bool) $this->getConfigData('general_settings/use_sandbox'); @@ -391,12 +416,12 @@ public function isCustomerLoggedIn(): bool public function getHashType(): string { - return $this->getConfigData('cardpayment_settings/hash_type'); + return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/hash_type'); } public function getVerificationCode(): string { - return $this->getConfigData('cardpayment_settings/verification_code'); + return $this->getConfigData('cardpayment_settings/cardpayment_originapi_settings/verification_code'); } /** diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index f24590d..bbfe61e 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -18,11 +18,12 @@ Magento\Config\Model\Config\Source\Yesno - - - 1 - + + + 1 + + validate-no-empty @@ -32,73 +33,101 @@ validate-length maximum-length-32 - - - Magento\Config\Model\Config\Source\Yesno - - - - Magento\Config\Model\Config\Source\Yesno - - - - Magento\Config\Model\Config\Source\Yesno - - - - Magento\Config\Model\Config\Source\Yesno - - + + + Magento\Config\Model\Config\Source\Yesno + + + + Magento\Config\Model\Config\Source\Yesno + + + + Magento\Config\Model\Config\Source\Yesno + + + + Magento\Config\Model\Config\Source\Yesno + + + + + Magento\Config\Model\Config\Source\Yesno + validate-length maximum-length-64 + 1 validate-length maximum-length-64 + 1 1 tpaycom\magento2basic\Model\Config\Source\OnsiteChannels + 1 + + + Magento\Config\Model\Config\Source\Yesno + no-whitespace validate-length maximum-length-126 + 1 no-whitespace validate-length maximum-length-40 - - - - no-whitespace validate-length maximum-length-126 - - - - no-whitespace validate-length maximum-length-40 + 1 + + + Magento\Config\Model\Config\Source\Yesno + + + + 1 + + + tpaycom\magento2basic\Model\Config\Source\HashTypes + + + + + + + no-whitespace validate-length maximum-length-126 + + + + no-whitespace validate-length maximum-length-40 + + + + + validate-no-empty + 1 + - - - + 1 Magento\Config\Model\Config\Source\Yesno - - - - tpaycom\magento2basic\Model\Config\Source\HashTypes + 1