-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
592 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace tpaycom\magento2basic\Model\Config\Source; | ||
|
||
use Magento\Framework\App\CacheInterface; | ||
use Magento\Framework\Data\OptionSourceInterface; | ||
use tpaycom\magento2basic\Api\TpayInterface; | ||
use tpaycom\magento2basic\Model\ApiFacade\Transaction\TransactionApiFacade; | ||
|
||
class OnsiteChannels implements OptionSourceInterface | ||
{ | ||
|
||
/** @var TransactionApiFacade */ | ||
private $transactions; | ||
|
||
public function __construct(TpayInterface $tpay, CacheInterface $cache) | ||
{ | ||
$this->transactions = new TransactionApiFacade($tpay, $cache); | ||
} | ||
|
||
public function getLabelFromValue(int $value): ?string | ||
{ | ||
foreach ($this->toOptionArray() as $option) { | ||
if ($option['value'] === $value) { | ||
return $option['label']; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
* | ||
* @return array{array{value: int, label: string}} | ||
*/ | ||
public function toOptionArray(): array | ||
{ | ||
return array_map(function (array $channel) { | ||
return ['value' => (int) $channel['id'], 'label' => $channel['fullName']]; | ||
}, $this->transactions->channels()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?php | ||
|
||
namespace tpaycom\magento2basic\Model; | ||
|
||
use Magento\Checkout\Model\ConfigProviderInterface; | ||
use Magento\Framework\App\CacheInterface; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\View\Asset\Repository; | ||
use Magento\Payment\Helper\Data as PaymentHelper; | ||
use Magento\Payment\Model\MethodInterface; | ||
use Magento\Payment\Model\MethodList; | ||
use Magento\Store\Model\ScopeInterface; | ||
use tpaycom\magento2basic\Api\TpayInterface; | ||
use tpaycom\magento2basic\Model\ApiFacade\Transaction\TransactionApiFacade; | ||
|
||
#[\AllowDynamicProperties] | ||
class GenericOnSiteConfigProvider implements ConfigProviderInterface | ||
{ | ||
protected $paymentMethod; | ||
|
||
public function __construct( | ||
PaymentHelper $paymentHelper, | ||
Repository $assetRepository, | ||
MethodList $methods, | ||
ScopeConfigInterface $scopeConfig, | ||
TransactionApiFacade $transactionApiFacade | ||
) { | ||
$this->paymentHelper = $paymentHelper; | ||
$this->assetRepository = $assetRepository; | ||
$this->methodList = $methods; | ||
$this->scopeConfig = $scopeConfig; | ||
$this->transactionApiFacade = $transactionApiFacade; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
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' => TransactionModel::BLIK_CHANNEL, | ||
'isInstallmentsAmountValid' => $this->getPaymentMethodInstance()->getInstallmentsAmountValid(), | ||
], | ||
], | ||
]; | ||
|
||
$channels = $this->transactionApiFacade->channels(); | ||
|
||
foreach ($channels as $channel) { | ||
$config['generic'][$channel['id']] = [ | ||
'id' => $channel['id'], | ||
'name' => $channel['fullName'], | ||
'logoUrl' => $channel['image']['url'], | ||
]; | ||
} | ||
|
||
|
||
return $config; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* | ||
* @return string | ||
*/ | ||
public function generateURL($name) | ||
{ | ||
return $this->assetRepository->createAsset($name)->getUrl(); | ||
} | ||
|
||
/** @return null|string */ | ||
public function showChannels() | ||
{ | ||
$script = 'tpaycom_magento2basic::js/render_channels.js'; | ||
|
||
return $this->createScript($script); | ||
} | ||
|
||
/** | ||
* @param string $script | ||
* | ||
* @return string | ||
*/ | ||
public function createScript($script) | ||
{ | ||
return " | ||
<script type=\"text/javascript\"> | ||
require(['jquery'], function ($) { | ||
$.getScript('{$this->generateURL($script)}'); | ||
}); | ||
</script>"; | ||
} | ||
|
||
/** @return null|string */ | ||
public function getTerms() | ||
{ | ||
return $this->getPaymentMethodInstance()->getTermsURL(); | ||
} | ||
|
||
/** | ||
* @param string $css | ||
* | ||
* @return string | ||
*/ | ||
public function createCSS($css) | ||
{ | ||
return "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$this->generateURL($css)}\">"; | ||
} | ||
|
||
/** @return MethodInterface|TpayInterface */ | ||
protected function getPaymentMethodInstance() | ||
{ | ||
if (null === $this->paymentMethod) { | ||
$this->paymentMethod = $this->paymentHelper->getMethodInstance(TpayInterface::CODE); | ||
} | ||
|
||
return $this->paymentMethod; | ||
} | ||
} |
Oops, something went wrong.