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