1
|
|
|
<?php |
2
|
|
|
namespace DigitalOrigin\Pmt\Controller\Payment; |
3
|
|
|
|
4
|
|
|
use Magento\Framework\App\Action\Action; |
5
|
|
|
use Magento\Framework\App\ResourceConnection; |
6
|
|
|
use Magento\Framework\DB\Ddl\Table; |
7
|
|
|
|
8
|
|
|
class Config extends Action |
9
|
|
|
{ |
10
|
|
|
/** Config tablename */ |
11
|
|
|
const CONFIG_TABLE = 'pmt_config'; |
12
|
|
|
|
13
|
|
|
/** @var ResourceConnection $dbObject */ |
14
|
|
|
protected $dbObject; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Log constructor. |
18
|
|
|
* |
19
|
|
|
* @param \Magento\Framework\App\Action\Context $context |
20
|
|
|
* @param \DigitalOrigin\Pmt\Helper\Config $pmtConfig |
21
|
|
|
* @param ResourceConnection $dbObject |
22
|
|
|
*/ |
23
|
|
|
public function __construct( |
24
|
|
|
\Magento\Framework\App\Action\Context $context, |
25
|
|
|
\DigitalOrigin\Pmt\Helper\Config $pmtConfig, |
26
|
|
|
ResourceConnection $dbObject |
27
|
|
|
) { |
28
|
|
|
$this->config = $pmtConfig->getConfig(); |
|
|
|
|
29
|
|
|
$this->dbObject = $dbObject; |
30
|
|
|
return parent::__construct($context); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Main function |
35
|
|
|
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void |
36
|
|
|
*/ |
37
|
|
|
public function execute() |
38
|
|
|
{ |
39
|
|
|
try { |
40
|
|
|
$response = array('status'=>null); |
41
|
|
|
$tableName = $this->dbObject->getTableName(self::CONFIG_TABLE); |
42
|
|
|
$secretKey = $this->getRequest()->getParam('secret'); |
43
|
|
|
$privateKey = isset($this->config['pmt_private_key']) ? $this->config['pmt_private_key'] : null; |
44
|
|
|
|
45
|
|
|
/** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */ |
46
|
|
|
$dbConnection = $this->dbObject->getConnection(); |
47
|
|
|
if ($privateKey != $secretKey) { |
48
|
|
|
$response['status'] = 401; |
49
|
|
|
$response['result'] = 'Unauthorized'; |
50
|
|
|
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST') { |
51
|
|
|
if (count($_POST)) { |
52
|
|
|
foreach ($_POST as $config => $value) { |
53
|
|
|
if (isset($this->defaultConfigs[$config]) && $response['status']==null) { |
|
|
|
|
54
|
|
|
$dbConnection->update( |
55
|
|
|
$tableName, |
56
|
|
|
array('value' => $value), |
57
|
|
|
"config='$$config'" |
58
|
|
|
); |
59
|
|
|
} else { |
60
|
|
|
$response['status'] = 400; |
61
|
|
|
$response['result'] = 'Bad request'; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} else { |
65
|
|
|
$response['status'] = 422; |
66
|
|
|
$response['result'] = 'Empty data'; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
if ($response['status']==null) { |
71
|
|
|
$dbResult = $dbConnection |
72
|
|
|
->select() |
73
|
|
|
->from($tableName, array('config', 'value')); |
|
|
|
|
74
|
|
|
foreach ($dbResult as $value) { |
75
|
|
|
$formattedResult[$value['config']] = $value['value']; |
76
|
|
|
} |
77
|
|
|
$response['result'] = $formattedResult; |
|
|
|
|
78
|
|
|
} |
79
|
|
|
$result = json_encode($response['result']); |
80
|
|
|
header("HTTP/1.1 ".$response['status'], true, $response['status']); |
81
|
|
|
header('Content-Type: application/json', true); |
82
|
|
|
header('Content-Length: '.strlen($result)); |
83
|
|
|
echo($result); |
84
|
|
|
exit(); |
|
|
|
|
85
|
|
|
} catch (\Exception $e) { |
86
|
|
|
die($e->getMessage()); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|