diff --git a/Api/TpayInterface.php b/Api/TpayInterface.php
index f0bc35e..21cb7ec 100644
--- a/Api/TpayInterface.php
+++ b/Api/TpayInterface.php
@@ -10,7 +10,8 @@
interface TpayInterface
{
public const CODE = 'tpaycom_magento2basic';
- public const CHANNEL = 'group';
+ public const GROUP = 'group';
+ public const CHANNEL = 'channel';
public const BLIK_CODE = 'blik_code';
public const TERMS_ACCEPT = 'accept_tos';
public const CARDDATA = 'card_data';
diff --git a/Controller/tpay/Create.php b/Controller/tpay/Create.php
index 3507169..3e5963b 100644
--- a/Controller/tpay/Create.php
+++ b/Controller/tpay/Create.php
@@ -79,7 +79,7 @@ public function execute()
$paymentData['additional_information']['transaction_url'] = $transactionUrl;
$payment->setData($paymentData)->save();
- if (6 === strlen($additionalPaymentInformation['blik_code']) && $this->tpay->checkBlikLevel0Settings()) {
+ if (6 === strlen($additionalPaymentInformation['blik_code'] ?? '') && $this->tpay->checkBlikLevel0Settings()) {
if (true === $this->transaction->isOpenApiUse()) {
return $this->_redirect('magento2basic/tpay/success');
}
@@ -119,11 +119,11 @@ private function prepareTransaction($orderId, array $additionalPaymentInformatio
{
$data = $this->tpay->getTpayFormData($orderId);
- if (6 === strlen($additionalPaymentInformation['blik_code'])) {
+ if (6 === strlen($additionalPaymentInformation['blik_code'] ?? '')) {
$data['group'] = TransactionOriginApi::BLIK_CHANNEL;
$this->handleBlikData($data, $additionalPaymentInformation['blik_code']);
} else {
- $data['group'] = (int) $additionalPaymentInformation['group'];
+ $data['group'] = (int) ($additionalPaymentInformation['group'] ?? null);
$data['channel'] = (int) ($additionalPaymentInformation['channel'] ?? null);
if ($this->tpay->redirectToChannel()) {
diff --git a/Controller/tpay/Redirect.php b/Controller/tpay/Redirect.php
index 36c6871..d1f3ba4 100644
--- a/Controller/tpay/Redirect.php
+++ b/Controller/tpay/Redirect.php
@@ -30,9 +30,11 @@ public function execute()
{
$uid = $this->getRequest()->getParam('uid');
$orderId = $this->checkoutSession->getLastRealOrderId();
+
if (!$orderId || !$uid) {
return $this->_redirect('checkout/cart');
}
+
$payment = $this->tpayService->getPayment($orderId);
$paymentData = $payment->getData();
$additionalPaymentInfo = $paymentData['additional_information'];
@@ -41,7 +43,9 @@ public function execute()
return $this->_redirect('magento2basic/tpay/CardPayment');
}
- if ((!array_key_exists(TpayInterface::CHANNEL, $additionalPaymentInfo) || (int) $additionalPaymentInfo[TpayInterface::CHANNEL] < 1) && (!array_key_exists(TpayInterface::BLIK_CODE, $additionalPaymentInfo) || 6 !== strlen($additionalPaymentInfo[TpayInterface::BLIK_CODE]))) {
+
+
+ if (empty(array_intersect(array_keys($additionalPaymentInfo), [TpayInterface::GROUP, TpayInterface::CHANNEL])) && (!array_key_exists(TpayInterface::BLIK_CODE, $additionalPaymentInfo) || 6 !== strlen($additionalPaymentInfo[TpayInterface::BLIK_CODE]))) {
return $this->_redirect('checkout/cart');
}
$this->tpayService->setOrderStatePendingPayment($orderId, true);
diff --git a/Model/ApiFacade/OpenApi.php b/Model/ApiFacade/OpenApi.php
index 48b2884..db42742 100755
--- a/Model/ApiFacade/OpenApi.php
+++ b/Model/ApiFacade/OpenApi.php
@@ -62,11 +62,11 @@ private function handleDataStructure(array $data): array
];
}
- if (isset($data['group'])) {
+ if ($data['group']) {
$paymentData['pay'] = ['groupId' => $data['group']];
}
- if (isset($data['channel'])) {
+ if ($data['channel']) {
$paymentData['pay'] = ['channelId' => $data['channel']];
}
diff --git a/Model/ApiFacade/TpayConfig/ConfigFacade.php b/Model/ApiFacade/TpayConfig/ConfigFacade.php
index 686cf9e..b92d5a9 100755
--- a/Model/ApiFacade/TpayConfig/ConfigFacade.php
+++ b/Model/ApiFacade/TpayConfig/ConfigFacade.php
@@ -17,6 +17,10 @@ class ConfigFacade
/** @var bool */
private $useOpenApi;
+ /**
+ * @var TpayInterface
+ */
+ private $tpay;
public function __construct(TpayInterface $tpay, Repository $assetRepository, TpayTokensService $tokensService)
{
diff --git a/Model/ApiFacade/TpayConfig/ConfigOpen.php b/Model/ApiFacade/TpayConfig/ConfigOpen.php
index 68e0c88..155fd34 100755
--- a/Model/ApiFacade/TpayConfig/ConfigOpen.php
+++ b/Model/ApiFacade/TpayConfig/ConfigOpen.php
@@ -47,7 +47,7 @@ public function getConfig(): array
];
$config = array_merge($config, $this->getCardConfig());
- return $this->tpay->isAvailable() ? $config : [];
+ return $config;
}
public function generateURL(string $name): string
diff --git a/Model/ApiFacade/Transaction/TransactionApiFacade.php b/Model/ApiFacade/Transaction/TransactionApiFacade.php
index 4aac618..5c3114b 100755
--- a/Model/ApiFacade/Transaction/TransactionApiFacade.php
+++ b/Model/ApiFacade/Transaction/TransactionApiFacade.php
@@ -4,6 +4,7 @@
use Exception;
use Magento\Framework\App\CacheInterface;
+use Tpay\OpenApi\Utilities\TpayException;
use tpaycom\magento2basic\Api\TpayInterface;
use tpaycom\magento2basic\Model\ApiFacade\OpenApi;
diff --git a/Model/GenericOnSiteConfigProvider.php b/Model/GenericOnSiteConfigProvider.php
index 4c2bef0..89bae51 100644
--- a/Model/GenericOnSiteConfigProvider.php
+++ b/Model/GenericOnSiteConfigProvider.php
@@ -23,13 +23,15 @@ public function __construct(
Repository $assetRepository,
MethodList $methods,
ScopeConfigInterface $scopeConfig,
- TransactionApiFacade $transactionApiFacade
+ TransactionApiFacade $transactionApiFacade,
+ TpayConfigProvider $tpayConfigProvider
) {
$this->paymentHelper = $paymentHelper;
$this->assetRepository = $assetRepository;
$this->methodList = $methods;
$this->scopeConfig = $scopeConfig;
$this->transactionApiFacade = $transactionApiFacade;
+ $this->tpayConfigProvider = $tpayConfigProvider;
}
/**
@@ -40,22 +42,7 @@ public function getConfig()
$tpay = $this->getPaymentMethodInstance();
$onsites = explode(',', $this->scopeConfig->getValue('payment/tpaycom_magento2basic/onsite_channels', ScopeInterface::SCOPE_STORE));
- $config = [
- 'tpay' => [
- 'payment' => [
- 'redirectUrl' => $tpay->getPaymentRedirectUrl(),
- 'tpayLogoUrl' => $this->generateURL('tpaycom_magento2basic::images/logo_tpay.png'),
- 'merchantId' => $tpay->getMerchantId(),
- 'showPaymentChannels' => $this->showChannels(),
- 'getTerms' => $this->getTerms(),
- 'addCSS' => $this->createCSS('tpaycom_magento2basic::css/tpay.css'),
- 'blikStatus' => $this->getPaymentMethodInstance()->checkBlikLevel0Settings(),
- 'onlyOnlineChannels' => $this->getPaymentMethodInstance()->onlyOnlineChannels(),
- 'getBlikChannelID' => TransactionOriginApi::BLIK_CHANNEL,
- 'isInstallmentsAmountValid' => $this->getPaymentMethodInstance()->getInstallmentsAmountValid(),
- ],
- ],
- ];
+ $config = $this->tpayConfigProvider->getConfig();
$channels = $this->transactionApiFacade->channels();
diff --git a/Model/Tpay.php b/Model/Tpay.php
index 7687ac7..4af2d7e 100755
--- a/Model/Tpay.php
+++ b/Model/Tpay.php
@@ -271,7 +271,7 @@ public function assignData(DataObject $data)
$additionalData = $data->getData('additional_data');
$info = $this->getInfoInstance();
- $info->setAdditionalInformation(static::CHANNEL, array_key_exists(static::CHANNEL, $additionalData) ? $additionalData[static::CHANNEL] : '');
+ $info->setAdditionalInformation(static::GROUP, array_key_exists(static::GROUP, $additionalData) ? $additionalData[static::GROUP] : '');
$info->setAdditionalInformation(static::BLIK_CODE, array_key_exists(static::BLIK_CODE, $additionalData) ? $additionalData[static::BLIK_CODE] : '');
diff --git a/etc/payment.xml b/etc/payment.xml
index 701b0d0..d0d4023 100644
--- a/etc/payment.xml
+++ b/etc/payment.xml
@@ -13,6 +13,9 @@