1
|
|
|
<?php |
2
|
|
|
namespace Pagantis\Pagantis\Controller\Payment; |
3
|
|
|
|
4
|
|
|
use Magento\Framework\App\Action\Action; |
5
|
|
|
use Magento\Framework\App\ResourceConnection; |
6
|
|
|
use Magento\Framework\App\CsrfAwareActionInterface; |
7
|
|
|
use Magento\Framework\App\RequestInterface; |
8
|
|
|
use Magento\Framework\App\Request\InvalidRequestException; |
9
|
|
|
|
10
|
|
|
class ConfigV2 extends Action implements CsrfAwareActionInterface |
11
|
|
|
{ |
12
|
|
|
/** Config tablename */ |
13
|
|
|
const CONFIG_TABLE = 'Pagantis_config'; |
14
|
|
|
|
15
|
|
|
/** @var ResourceConnection $dbObject */ |
16
|
|
|
protected $dbObject; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Variable which contains extra configuration. |
20
|
|
|
* @var array $defaultConfigs |
21
|
|
|
*/ |
22
|
|
|
public $defaultConfigs = array('PAGANTIS_TITLE'=>'Instant Financing', |
23
|
|
|
'PAGANTIS_SIMULATOR_DISPLAY_TYPE'=>'pmtSDK.simulator.types.SIMPLE', |
24
|
|
|
'PAGANTIS_SIMULATOR_DISPLAY_SKIN'=>'pmtSDK.simulator.skins.BLUE', |
25
|
|
|
'PAGANTIS_SIMULATOR_DISPLAY_POSITION'=>'hookDisplayProductButtons', |
26
|
|
|
'PAGANTIS_SIMULATOR_START_INSTALLMENTS'=>3, |
27
|
|
|
'PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'=>12, |
28
|
|
|
'PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR'=>'default', |
29
|
|
|
'PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'=>'pmtSDK.simulator.positions.INNER', |
30
|
|
|
'PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR'=>'default', |
31
|
|
|
'PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR'=>'default', |
32
|
|
|
'PAGANTIS_FORM_DISPLAY_TYPE'=>0, |
33
|
|
|
'PAGANTIS_DISPLAY_MIN_AMOUNT'=>1, |
34
|
|
|
'PAGANTIS_URL_OK'=>'', |
35
|
|
|
'PAGANTIS_URL_KO'=>'', |
36
|
|
|
'PAGANTIS_TITLE_EXTRA' => 'Pay up to 12 comfortable installments with Pagantis. Completely online and sympathetic request, and the answer is immediate!' |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Log constructor. |
41
|
|
|
* |
42
|
|
|
* @param \Magento\Framework\App\Action\Context $context |
43
|
|
|
* @param \Pagantis\Pagantis\Helper\Config $pagantisConfig |
44
|
|
|
* @param ResourceConnection $dbObject |
45
|
|
|
*/ |
46
|
|
|
public function __construct( |
47
|
|
|
\Magento\Framework\App\Action\Context $context, |
48
|
|
|
\Pagantis\Pagantis\Helper\Config $pagantisConfig, |
49
|
|
|
ResourceConnection $dbObject |
50
|
|
|
) { |
51
|
|
|
$this->config = $pagantisConfig->getConfig(); |
|
|
|
|
52
|
|
|
$this->dbObject = $dbObject; |
53
|
|
|
|
54
|
|
|
// CsrfAwareAction Magento2.3 compatibility |
55
|
|
|
if (interface_exists("\Magento\Framework\App\CsrfAwareActionInterface")) { |
56
|
|
|
$request = $this->getRequest(); |
57
|
|
|
if ($request instanceof HttpRequest && $request->isPost() && empty($request->getParam('form_key'))) { |
|
|
|
|
58
|
|
|
$formKey = $this->_objectManager->get(\Magento\Framework\Data\Form\FormKey::class); |
59
|
|
|
$request->setParam('form_key', $formKey->getFormKey()); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return parent::__construct($context); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Main function |
68
|
|
|
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void |
69
|
|
|
*/ |
70
|
|
|
public function execute() |
71
|
|
|
{ |
72
|
|
|
try { |
73
|
|
|
$response = array('status'=>null); |
74
|
|
|
$tableName = $this->dbObject->getTableName(self::CONFIG_TABLE); |
75
|
|
|
$secretKey = $this->getRequest()->getParam('secret'); |
76
|
|
|
$privateKey = isset($this->config['pagantis_private_key']) ? $this->config['pagantis_private_key'] : null; |
77
|
|
|
|
78
|
|
|
/** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */ |
79
|
|
|
$dbConnection = $this->dbObject->getConnection(); |
80
|
|
|
if ($privateKey != $secretKey) { |
81
|
|
|
$response['status'] = 401; |
82
|
|
|
$response['result'] = 'Unauthorized'; |
83
|
|
|
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST') { |
84
|
|
|
if (count($_POST)) { |
85
|
|
|
foreach ($_POST as $config => $value) { |
86
|
|
|
if (isset($this->defaultConfigs[$config]) && $response['status']==null) { |
87
|
|
|
$dbConnection->update( |
88
|
|
|
$tableName, |
89
|
|
|
array('value' => $value), |
90
|
|
|
"config='$config'" |
91
|
|
|
); |
92
|
|
|
} else { |
93
|
|
|
$response['status'] = 400; |
94
|
|
|
$response['result'] = 'Bad request'; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} else { |
98
|
|
|
$response['status'] = 422; |
99
|
|
|
$response['result'] = 'Empty data'; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$formattedResult = array(); |
104
|
|
|
if ($response['status']==null) { |
105
|
|
|
$dbResult = $dbConnection->fetchAll("select * from $tableName"); |
106
|
|
|
foreach ($dbResult as $value) { |
107
|
|
|
$formattedResult[$value['config']] = $value['value']; |
108
|
|
|
} |
109
|
|
|
$response['result'] = $formattedResult; |
110
|
|
|
} |
111
|
|
|
$result = json_encode($response['result']); |
112
|
|
|
header("HTTP/1.1 ".$response['status'], true, $response['status']); |
113
|
|
|
header('Content-Type: application/json', true); |
114
|
|
|
header('Content-Length: '.strlen($result)); |
115
|
|
|
echo($result); |
116
|
|
|
exit(); |
|
|
|
|
117
|
|
|
} catch (\Exception $e) { |
118
|
|
|
die($e->getMessage()); |
|
|
|
|
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param RequestInterface $request |
124
|
|
|
* |
125
|
|
|
* @return InvalidRequestException|null |
126
|
|
|
*/ |
127
|
|
|
public function createCsrfValidationException(RequestInterface $request): ?InvalidRequestException |
128
|
|
|
{ |
129
|
|
|
return null; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param RequestInterface $request |
134
|
|
|
* |
135
|
|
|
* @return bool|null |
136
|
|
|
*/ |
137
|
|
|
public function validateForCsrf(RequestInterface $request): ?bool |
138
|
|
|
{ |
139
|
|
|
return true; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|