Skip to content

Commit

Permalink
Added bank payment view selection
Browse files Browse the repository at this point in the history
  • Loading branch information
krzGablo committed May 16, 2024
1 parent 0936782 commit 245c2b8
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 37 deletions.
2 changes: 2 additions & 0 deletions Api/TpayConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ public function getMaxOrderTotal(): int;
public function getMagentoVersion(): string;

public function buildMagentoInfo(): string;

public function getPaymentCurrency(): string;
}
9 changes: 2 additions & 7 deletions Model/ApiFacade/CardTransaction/CardApiFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;

Expand Down
13 changes: 4 additions & 9 deletions Model/ApiFacade/TpayConfig/CardConfigFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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);
}
}

Expand All @@ -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;

Expand Down
15 changes: 5 additions & 10 deletions Model/ApiFacade/TpayConfig/ConfigFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
}
}

Expand All @@ -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;

Expand Down
8 changes: 1 addition & 7 deletions Model/MethodListPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,9 +29,6 @@ class MethodListPlugin
/** @var OnsiteChannels */
private $onsiteChannels;

/** @var StoreManagerInterface */
private $storeManager;

/** @var TpayPayment */
private $tpay;

Expand All @@ -52,7 +48,6 @@ public function __construct(
Data $data,
ScopeConfigInterface $scopeConfig,
OnsiteChannels $onsiteChannels,
StoreManagerInterface $storeManager,
TpayPayment $tpay,
TpayConfigInterface $tpayConfig,
Session $checkoutSession,
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions Model/TpayConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,15 +31,14 @@ class TpayConfigProvider implements ConfigProviderInterface
public function __construct(
PaymentHelper $paymentHelper,
Repository $assetRepository,
StoreManagerInterface $storeManager,
TpayTokensService $tokensService,
TransactionApiFacade $transactionApiFacade,
TpayService $tpayService,
TpayConfigInterface $tpayConfig
) {
$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
Expand Down
12 changes: 11 additions & 1 deletion Provider/ConfigurationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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';
Expand Down
5 changes: 5 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@
<comment>Leave empty for no limit</comment>
<validate>validate-number</validate>
</field>
<field id="bank_payments_view" translate="label" type="select" sortOrder="18" showInDefault="1" showInWebsite="1" showInStore="1">
<label>View bank payments</label>
<comment>If you use other currencies visible on the website and pay in PLN, turn it on/off</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</group>
</section>
Expand Down
2 changes: 2 additions & 0 deletions i18n/pl_PL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 245c2b8

Please sign in to comment.