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
|
|
|
* Variable which contains extra configuration. |
18
|
|
|
* @var array $defaultConfigs |
19
|
|
|
*/ |
20
|
|
|
public $defaultConfigs = array('PMT_TITLE'=>'Instant Financing', |
21
|
|
|
'PMT_SIMULATOR_DISPLAY_TYPE'=>'pmtSDK.simulator.types.SIMPLE', |
22
|
|
|
'PMT_SIMULATOR_DISPLAY_SKIN'=>'pmtSDK.simulator.skins.BLUE', |
23
|
|
|
'PMT_SIMULATOR_DISPLAY_POSITION'=>'hookDisplayProductButtons', |
24
|
|
|
'PMT_SIMULATOR_START_INSTALLMENTS'=>3, |
25
|
|
|
'PMT_SIMULATOR_MAX_INSTALLMENTS'=>12, |
26
|
|
|
'PMT_SIMULATOR_CSS_POSITION_SELECTOR'=>'default', |
27
|
|
|
'PMT_SIMULATOR_DISPLAY_CSS_POSITION'=>'pmtSDK.simulator.positions.INNER', |
28
|
|
|
'PMT_SIMULATOR_CSS_PRICE_SELECTOR'=>'default', |
29
|
|
|
'PMT_SIMULATOR_CSS_QUANTITY_SELECTOR'=>'default', |
30
|
|
|
'PMT_FORM_DISPLAY_TYPE'=>0, |
31
|
|
|
'PMT_DISPLAY_MIN_AMOUNT'=>1, |
32
|
|
|
'PMT_URL_OK'=>'', |
33
|
|
|
'PMT_URL_KO'=>'', |
34
|
|
|
'PMT_TITLE_EXTRA' => 'Paga hasta en 12 cómodas cuotas con Paga+Tarde. Solicitud totalmente |
35
|
|
|
online y sin papeleos,¡y la respuesta es inmediata!' |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Log constructor. |
40
|
|
|
* |
41
|
|
|
* @param \Magento\Framework\App\Action\Context $context |
42
|
|
|
* @param \DigitalOrigin\Pmt\Helper\Config $pmtConfig |
43
|
|
|
* @param ResourceConnection $dbObject |
44
|
|
|
*/ |
45
|
|
|
public function __construct( |
46
|
|
|
\Magento\Framework\App\Action\Context $context, |
47
|
|
|
\DigitalOrigin\Pmt\Helper\Config $pmtConfig, |
48
|
|
|
ResourceConnection $dbObject |
49
|
|
|
) { |
50
|
|
|
$this->config = $pmtConfig->getConfig(); |
|
|
|
|
51
|
|
|
$this->dbObject = $dbObject; |
52
|
|
|
return parent::__construct($context); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Main function |
57
|
|
|
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void |
58
|
|
|
*/ |
59
|
|
|
public function execute() |
60
|
|
|
{ |
61
|
|
|
try { |
62
|
|
|
$response = array('status'=>null); |
63
|
|
|
$tableName = $this->dbObject->getTableName(self::CONFIG_TABLE); |
64
|
|
|
$secretKey = $this->getRequest()->getParam('secret'); |
65
|
|
|
$privateKey = isset($this->config['pmt_private_key']) ? $this->config['pmt_private_key'] : null; |
66
|
|
|
|
67
|
|
|
/** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */ |
68
|
|
|
$dbConnection = $this->dbObject->getConnection(); |
69
|
|
|
if ($privateKey != $secretKey) { |
70
|
|
|
$response['status'] = 401; |
71
|
|
|
$response['result'] = 'Unauthorized'; |
72
|
|
|
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST') { |
73
|
|
|
if (count($_POST)) { |
74
|
|
|
foreach ($_POST as $config => $value) { |
75
|
|
|
if (isset($this->defaultConfigs[$config]) && $response['status']==null) { |
76
|
|
|
$dbConnection->update( |
77
|
|
|
$tableName, |
78
|
|
|
array('value' => $value), |
79
|
|
|
"config='$config'" |
80
|
|
|
); |
81
|
|
|
} else { |
82
|
|
|
$response['status'] = 400; |
83
|
|
|
$response['result'] = 'Bad request'; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} else { |
87
|
|
|
$response['status'] = 422; |
88
|
|
|
$response['result'] = 'Empty data'; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$formattedResult = array(); |
93
|
|
|
if ($response['status']==null) { |
94
|
|
|
$dbResult = $dbConnection->fetchAll("select * from $tableName"); |
95
|
|
|
foreach ($dbResult as $value) { |
96
|
|
|
$formattedResult[$value['config']] = $value['value']; |
97
|
|
|
} |
98
|
|
|
$response['result'] = $formattedResult; |
99
|
|
|
} |
100
|
|
|
$result = json_encode($response['result']); |
101
|
|
|
header("HTTP/1.1 ".$response['status'], true, $response['status']); |
102
|
|
|
header('Content-Type: application/json', true); |
103
|
|
|
header('Content-Length: '.strlen($result)); |
104
|
|
|
echo($result); |
105
|
|
|
exit(); |
|
|
|
|
106
|
|
|
} catch (\Exception $e) { |
107
|
|
|
die($e->getMessage()); |
|
|
|
|
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|