-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInstructionsConfigProvider.php
75 lines (67 loc) · 2.08 KB
/
InstructionsConfigProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* @copyright Copyright © Avarda. All rights reserved.
* @package Avarda_Checkout3
*/
namespace Avarda\Checkout3\Model;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Escaper;
use Magento\Framework\Url;
use Magento\Payment\Helper\Data as PaymentHelper;
use Magento\Payment\Model\MethodInterface;
use Magento\Store\Model\ScopeInterface;
class InstructionsConfigProvider implements ConfigProviderInterface
{
protected Escaper $escaper;
protected ScopeConfigInterface $scopeConfig;
protected Url $url;
protected string $methodCode;
protected ?MethodInterface $methodInstance = null;
public function __construct(
PaymentHelper $paymentHelper,
Escaper $escaper,
ScopeConfigInterface $scopeConfig,
Url $url,
$methodCode = ''
) {
$this->escaper = $escaper;
$this->scopeConfig = $scopeConfig;
$this->url = $url;
$this->methodCode = $methodCode;
$this->methodInstance = $paymentHelper->getMethodInstance($this->methodCode);
}
/**
* {@inheritdoc}
*/
public function getConfig()
{
$config = [];
if ($this->methodInstance->isAvailable()) {
$config['payment']['instructions'][$this->methodCode] = [
'instructions' => $this->getInstructions($this->methodCode),
];
}
return $config;
}
/**
* Get instructions text from config
*
* @param string $code
* @return string
*/
protected function getInstructions($code)
{
return nl2br($this->escaper->escapeHtml($this->scopeConfig->getValue('payment/' . $code . '/instructions', ScopeInterface::SCOPE_STORE)));
}
/**
* Get instructions text from config
*
* @param string $code
* @return string
*/
protected function getConfigValue($code, $conf)
{
return nl2br($this->escaper->escapeHtml($this->scopeConfig->getValue('payment/' . $code . '/' . $conf, ScopeInterface::SCOPE_STORE)));
}
}