diff --git a/Api/TpayConfigInterface.php b/Api/TpayConfigInterface.php index aa329cf..b9208c4 100644 --- a/Api/TpayConfigInterface.php +++ b/Api/TpayConfigInterface.php @@ -70,4 +70,6 @@ public function getMaxOrderTotal(): int; public function getMagentoVersion(): string; public function buildMagentoInfo(): string; + + public function getPaymentCurrency(): string; } diff --git a/Model/ApiFacade/CardTransaction/CardApiFacade.php b/Model/ApiFacade/CardTransaction/CardApiFacade.php index 7450859..ae72d72 100755 --- a/Model/ApiFacade/CardTransaction/CardApiFacade.php +++ b/Model/ApiFacade/CardTransaction/CardApiFacade.php @@ -3,7 +3,6 @@ namespace Tpay\Magento2\Model\ApiFacade\CardTransaction; use Exception; -use Magento\Store\Model\StoreManagerInterface; use Tpay\Magento2\Api\TpayConfigInterface; use Tpay\Magento2\Api\TpayInterface; use Tpay\Magento2\Service\TpayService; @@ -29,19 +28,15 @@ class CardApiFacade /** @var TpayService */ private $tpayService; - /** @var StoreManagerInterface */ - private $storeManager; - /** @var bool */ private $useOpenCard; - public function __construct(TpayInterface $tpay, TpayConfigInterface $tpayConfig, TpayTokensService $tokensService, TpayService $tpayService, StoreManagerInterface $storeManager) + public function __construct(TpayInterface $tpay, TpayConfigInterface $tpayConfig, TpayTokensService $tokensService, TpayService $tpayService) { $this->tpay = $tpay; $this->tpayConfig = $tpayConfig; $this->tokensService = $tokensService; $this->tpayService = $tpayService; - $this->storeManager = $storeManager; } public function makeCardTransaction(string $orderId, ?array $customerToken = null): string @@ -95,7 +90,7 @@ private function createCardOriginApiInstance(TpayInterface $tpay, TpayConfigInte private function createOpenApiInstance(TpayInterface $tpay, TpayConfigInterface $tpayConfig, TpayTokensService $tokensService, TpayService $tpayService) { - if ('PLN' !== $this->storeManager->getStore()->getBaseCurrencyCode() || !$tpayConfig->isCardEnabled()) { + if ('PLN' !== $tpayConfig->getPaymentCurrency() || !$tpayConfig->isCardEnabled()) { $this->cardOpen = null; $this->useOpenCard = false; diff --git a/Model/ApiFacade/TpayConfig/CardConfigFacade.php b/Model/ApiFacade/TpayConfig/CardConfigFacade.php index 9d64768..a74bff7 100755 --- a/Model/ApiFacade/TpayConfig/CardConfigFacade.php +++ b/Model/ApiFacade/TpayConfig/CardConfigFacade.php @@ -4,7 +4,6 @@ use Exception; use Magento\Framework\View\Asset\Repository; -use Magento\Store\Model\StoreManagerInterface; use Tpay\Magento2\Api\TpayConfigInterface; use Tpay\Magento2\Api\TpayInterface; use Tpay\Magento2\Model\ApiFacade\CardTransaction\CardOrigin; @@ -31,22 +30,18 @@ class CardConfigFacade /** @var TpayTokensService */ private $tokensService; - /** @var StoreManagerInterface */ - private $storeManager; - /** @var TpayService */ private $tpayService; /** @var bool */ private $useOpenApi; - public function __construct(TpayInterface $tpay, TpayConfigInterface $tpayConfig, Repository $assetRepository, TpayTokensService $tokensService, StoreManagerInterface $storeManager, TpayService $tpayService) + public function __construct(TpayInterface $tpay, TpayConfigInterface $tpayConfig, Repository $assetRepository, TpayTokensService $tokensService, TpayService $tpayService) { $this->tpay = $tpay; $this->tpayConfig = $tpayConfig; $this->assetRepository = $assetRepository; $this->tokensService = $tokensService; - $this->storeManager = $storeManager; $this->tpayService = $tpayService; } @@ -66,7 +61,7 @@ private function connectApi() { if (null == $this->openApi && null === $this->originApi) { $this->createOriginApiInstance($this->tpay, $this->tpayConfig, $this->assetRepository, $this->tokensService, $this->tpayService); - $this->createOpenApiInstance($this->tpay, $this->tpayConfig, $this->assetRepository, $this->tokensService, $this->storeManager); + $this->createOpenApiInstance($this->tpay, $this->tpayConfig, $this->assetRepository, $this->tokensService); } } @@ -86,9 +81,9 @@ private function createOriginApiInstance(TpayInterface $tpay, TpayConfigInterfac } } - private function createOpenApiInstance(TpayInterface $tpay, TpayConfigInterface $tpayConfig, Repository $assetRepository, TpayTokensService $tokensService, StoreManagerInterface $storeManager) + private function createOpenApiInstance(TpayInterface $tpay, TpayConfigInterface $tpayConfig, Repository $assetRepository, TpayTokensService $tokensService) { - if ('PLN' !== $storeManager->getStore()->getBaseCurrencyCode()) { + if ('PLN' !== $tpayConfig->getPaymentCurrency()) { $this->openApi = null; $this->useOpenApi = false; diff --git a/Model/ApiFacade/TpayConfig/ConfigFacade.php b/Model/ApiFacade/TpayConfig/ConfigFacade.php index cb212db..af410c2 100755 --- a/Model/ApiFacade/TpayConfig/ConfigFacade.php +++ b/Model/ApiFacade/TpayConfig/ConfigFacade.php @@ -4,7 +4,6 @@ use Exception; use Magento\Framework\View\Asset\Repository; -use Magento\Store\Model\StoreManagerInterface; use Tpay\Magento2\Api\TpayConfigInterface; use Tpay\Magento2\Api\TpayInterface; use Tpay\Magento2\Model\ApiFacade\Transaction\TransactionOriginApi; @@ -34,22 +33,18 @@ class ConfigFacade /** @var TpayTokensService */ private $tokensService; - /** @var StoreManagerInterface */ - private $storeManager; - /** @var TpayService */ private $tpayService; /** @var bool */ private $useOpenApi; - public function __construct(TpayInterface $tpay, TpayConfigInterface $tpayConfig, Repository $assetRepository, TpayTokensService $tokensService, StoreManagerInterface $storeManager, TpayService $tpayService) + public function __construct(TpayInterface $tpay, TpayConfigInterface $tpayConfig, Repository $assetRepository, TpayTokensService $tokensService, TpayService $tpayService) { $this->tpay = $tpay; $this->tpayConfig = $tpayConfig; $this->assetRepository = $assetRepository; $this->tokensService = $tokensService; - $this->storeManager = $storeManager; $this->tpayService = $tpayService; } @@ -69,8 +64,8 @@ private function connectApi() { if (null == $this->openApi && null === $this->originConfig) { $this->createOriginApiInstance($this->tpay, $this->tpayConfig, $this->assetRepository, $this->tokensService); - $this->createOpenApiInstance($this->tpay, $this->tpayConfig, $this->assetRepository, $this->tokensService, $this->storeManager); - $this->cardConfig = new CardConfigFacade($this->tpay, $this->tpayConfig, $this->assetRepository, $this->tokensService, $this->storeManager, $this->tpayService); + $this->createOpenApiInstance($this->tpay, $this->tpayConfig, $this->assetRepository, $this->tokensService); + $this->cardConfig = new CardConfigFacade($this->tpay, $this->tpayConfig, $this->assetRepository, $this->tokensService, $this->tpayService); } } @@ -90,9 +85,9 @@ private function createOriginApiInstance(TpayInterface $tpay, TpayConfigInterfac } } - private function createOpenApiInstance(TpayInterface $tpay, TpayConfigInterface $tpayConfig, Repository $assetRepository, TpayTokensService $tokensService, StoreManagerInterface $storeManager) + private function createOpenApiInstance(TpayInterface $tpay, TpayConfigInterface $tpayConfig, Repository $assetRepository, TpayTokensService $tokensService) { - if ('PLN' !== $storeManager->getStore()->getBaseCurrencyCode() || !$tpayConfig->isOpenApiEnabled()) { + if ('PLN' !== $tpayConfig->getPaymentCurrency() || !$tpayConfig->isOpenApiEnabled()) { $this->openApi = null; $this->useOpenApi = false; diff --git a/Model/MethodListPlugin.php b/Model/MethodListPlugin.php index d15ce6f..3a59599 100644 --- a/Model/MethodListPlugin.php +++ b/Model/MethodListPlugin.php @@ -8,7 +8,6 @@ use Magento\Payment\Model\MethodInterface; use Magento\Payment\Model\MethodList; use Magento\Store\Model\ScopeInterface; -use Magento\Store\Model\StoreManagerInterface; use Tpay\Magento2\Api\TpayConfigInterface; use Tpay\Magento2\Api\TpayInterface; use Tpay\Magento2\Model\ApiFacade\Transaction\TransactionApiFacade; @@ -30,9 +29,6 @@ class MethodListPlugin /** @var OnsiteChannels */ private $onsiteChannels; - /** @var StoreManagerInterface */ - private $storeManager; - /** @var TpayPayment */ private $tpay; @@ -52,7 +48,6 @@ public function __construct( Data $data, ScopeConfigInterface $scopeConfig, OnsiteChannels $onsiteChannels, - StoreManagerInterface $storeManager, TpayPayment $tpay, TpayConfigInterface $tpayConfig, Session $checkoutSession, @@ -63,7 +58,6 @@ public function __construct( $this->data = $data; $this->scopeConfig = $scopeConfig; $this->onsiteChannels = $onsiteChannels; - $this->storeManager = $storeManager; $this->tpay = $tpay; $this->tpayConfig = $tpayConfig; $this->checkoutSession = $checkoutSession; @@ -148,7 +142,7 @@ private function filterResult(array $result): array private function isPlnPayment(): bool { - return 'PLN' === $this->storeManager->getStore()->getBaseCurrencyCode(); + return 'PLN' === $this->tpayConfig->getPaymentCurrency(); } private function filterTransaction(array $result): array diff --git a/Model/TpayConfigProvider.php b/Model/TpayConfigProvider.php index 9fdc9e1..9f6a2d6 100644 --- a/Model/TpayConfigProvider.php +++ b/Model/TpayConfigProvider.php @@ -7,7 +7,6 @@ use Magento\Checkout\Model\ConfigProviderInterface; use Magento\Framework\View\Asset\Repository; use Magento\Payment\Helper\Data as PaymentHelper; -use Magento\Store\Model\StoreManagerInterface; use Tpay\Magento2\Api\TpayConfigInterface; use Tpay\Magento2\Api\TpayInterface; use Tpay\Magento2\Model\ApiFacade\TpayConfig\ConfigFacade; @@ -32,7 +31,6 @@ class TpayConfigProvider implements ConfigProviderInterface public function __construct( PaymentHelper $paymentHelper, Repository $assetRepository, - StoreManagerInterface $storeManager, TpayTokensService $tokensService, TransactionApiFacade $transactionApiFacade, TpayService $tpayService, @@ -40,7 +38,7 @@ public function __construct( ) { $this->paymentHelper = $paymentHelper; $this->transactionApi = $transactionApiFacade; - $this->configFacade = new ConfigFacade($this->getPaymentMethodInstance(), $tpayConfig, $assetRepository, $tokensService, $storeManager, $tpayService); + $this->configFacade = new ConfigFacade($this->getPaymentMethodInstance(), $tpayConfig, $assetRepository, $tokensService, $tpayService); } public function getConfig(): array diff --git a/Provider/ConfigurationProvider.php b/Provider/ConfigurationProvider.php index b80bb5f..7f2266f 100755 --- a/Provider/ConfigurationProvider.php +++ b/Provider/ConfigurationProvider.php @@ -7,6 +7,7 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\ProductMetadataInterface; use Magento\Store\Model\ScopeInterface; +use Magento\Store\Model\StoreManagerInterface; use Tpay\Magento2\Api\TpayConfigInterface; class ConfigurationProvider implements TpayConfigInterface @@ -21,10 +22,14 @@ class ConfigurationProvider implements TpayConfigInterface /** @var ProductMetadataInterface */ protected $productMetadataInterface; - public function __construct(ScopeConfigInterface $scopeConfig, ProductMetadataInterface $productMetadataInterface) + /** @var StoreManagerInterface */ + private $storeManager; + + public function __construct(ScopeConfigInterface $scopeConfig, ProductMetadataInterface $productMetadataInterface, StoreManagerInterface $storeManager) { $this->scopeConfig = $scopeConfig; $this->productMetadataInterface = $productMetadataInterface; + $this->storeManager = $storeManager; } public function isTpayActive(): bool @@ -214,6 +219,11 @@ public function getConfigData($field, $storeId = null) return $this->scopeConfig->getValue(self::BASE_CONFIG_PATH.$field, ScopeInterface::SCOPE_STORE, $storeId); } + public function getPaymentCurrency(): string + { + return $this->getConfigData('sale_settings/bank_payments_view') ? $this->storeManager->getStore()->getBaseCurrencyCode() : $this->storeManager->getStore()->getCurrentCurrencyCode(); + } + private function getPackagesVersions(): array { $dir = __DIR__.'/../composer.json'; diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 17a32d2..0c950be 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -173,6 +173,11 @@ Leave empty for no limit validate-number + + + If you use other currencies visible on the website and pay in PLN, turn it on/off + Magento\Config\Model\Config\Source\Yesno + diff --git a/i18n/pl_PL.csv b/i18n/pl_PL.csv index 02ac208..c33f275 100644 --- a/i18n/pl_PL.csv +++ b/i18n/pl_PL.csv @@ -29,6 +29,8 @@ "Minimal amount","Minimalna kwota" "Maximal amount for method","Maksymalna kwota" "Leave empty for no limit","Puste pole bez ograniczeń" +"View bank payments","Widok płatności bankowych" +"If you use other currencies visible on the website and pay in PLN, turn it on/off","W przypadku korzystania z innych walut widocznych na stronie i płatności w PLN należy włączyć/wyłączyć" "Type in 6 digit code and press pay to commit blik payment.", "Wpisz 6 cyfrowy kod aby powiązać transakcję blik." "Choose a payment method","Wybierz jeden ze sposobów płatności" "I accept the regulations of Tpay.","Akceptuje regulamin Tpay."