|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify |
|
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
|
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
7
|
|
|
* (at your option) any later version. |
|
8
|
|
|
* |
|
9
|
|
|
* PAYONE Magento 2 Connector is distributed in the hope that it will be useful, |
|
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12
|
|
|
* GNU Lesser General Public License for more details. |
|
13
|
|
|
* |
|
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
15
|
|
|
* along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>. |
|
16
|
|
|
* |
|
17
|
|
|
* PHP version 5 |
|
18
|
|
|
* |
|
19
|
|
|
* @category Payone |
|
20
|
|
|
* @package Payone_Magento2_Plugin |
|
21
|
|
|
* @author FATCHIP GmbH <[email protected]> |
|
22
|
|
|
* @copyright 2003 - 2016 Payone GmbH |
|
23
|
|
|
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License |
|
24
|
|
|
* @link http://www.payone.de |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace Payone\Core\Model\ResourceModel; |
|
28
|
|
|
|
|
29
|
|
|
use Payone\Core\Model\Api\Request\Base; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* ApiLog resource model |
|
33
|
|
|
*/ |
|
34
|
|
|
class ApiLog extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* PAYONE shop helper |
|
38
|
|
|
* |
|
39
|
|
|
* @var \Payone\Core\Helper\Shop |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $shopHelper; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* PAYONE toolkit helper |
|
45
|
|
|
* |
|
46
|
|
|
* @var \Payone\Core\Helper\Toolkit |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $toolkitHelper; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Fields that need to be masked before written in to the API log |
|
52
|
|
|
* |
|
53
|
|
|
* @var array |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $aMaskFields = [ |
|
56
|
|
|
'ip', |
|
57
|
|
|
'iban', |
|
58
|
|
|
]; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Class constructor |
|
62
|
|
|
* |
|
63
|
|
|
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context |
|
64
|
|
|
* @param \Payone\Core\Helper\Shop $shopHelper |
|
65
|
|
|
* @param \Payone\Core\Helper\Toolkit $toolkitHelper |
|
66
|
|
|
* @param string $connectionName |
|
67
|
|
|
*/ |
|
68
|
|
|
public function __construct( |
|
69
|
|
|
\Magento\Framework\Model\ResourceModel\Db\Context $context, |
|
|
|
|
|
|
70
|
|
|
\Payone\Core\Helper\Shop $shopHelper, |
|
71
|
|
|
\Payone\Core\Helper\Toolkit $toolkitHelper, |
|
72
|
|
|
$connectionName = null |
|
73
|
|
|
) { |
|
74
|
|
|
parent::__construct($context, $connectionName); |
|
75
|
|
|
$this->shopHelper = $shopHelper; |
|
76
|
|
|
$this->toolkitHelper = $toolkitHelper; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Initialize connection and table |
|
81
|
|
|
* |
|
82
|
|
|
* @return void |
|
83
|
|
|
*/ |
|
84
|
|
|
protected function _construct() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->_init('payone_protocol_api', 'id'); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Get value from array at given key or empty string if not set |
|
91
|
|
|
* |
|
92
|
|
|
* @param array $aRequest |
|
93
|
|
|
* @param string $sField |
|
94
|
|
|
* @param string|null $sDefault |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function getParamValue($aRequest, $sField, $sDefault = null) |
|
98
|
|
|
{ |
|
99
|
|
|
if (isset($aRequest[$sField])) { |
|
100
|
|
|
return $aRequest[$sField]; |
|
101
|
|
|
} elseif ($sDefault !== null) { |
|
102
|
|
|
return $sDefault; |
|
103
|
|
|
} |
|
104
|
|
|
return ''; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Mask a given value with Xs |
|
109
|
|
|
* |
|
110
|
|
|
* @param string $sValue |
|
111
|
|
|
* @return string |
|
112
|
|
|
*/ |
|
113
|
|
|
protected function maskValue($sValue) |
|
114
|
|
|
{ |
|
115
|
|
|
for ($i = 0; $i < strlen($sValue); $i++) { |
|
116
|
|
|
$sValue[$i] = 'x'; |
|
117
|
|
|
} |
|
118
|
|
|
return $sValue; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Mask certain fields in the request array |
|
123
|
|
|
* |
|
124
|
|
|
* @param array $aRequest |
|
125
|
|
|
* @return array |
|
126
|
|
|
*/ |
|
127
|
|
|
protected function maskParameters($aRequest) |
|
128
|
|
|
{ |
|
129
|
|
|
foreach ($this->aMaskFields as $sKey) { |
|
130
|
|
|
if (isset($aRequest[$sKey])) { |
|
131
|
|
|
if ($sKey == 'iban') { |
|
132
|
|
|
$aRequest[$sKey] = $this->toolkitHelper->maskIban($aRequest[$sKey]); |
|
133
|
|
|
} else { |
|
134
|
|
|
$aRequest[$sKey] = $this->maskValue($aRequest[$sKey]); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
return $aRequest; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Save Api-log entry to database |
|
143
|
|
|
* |
|
144
|
|
|
* @param array $aRequest |
|
145
|
|
|
* @param array $aResponse |
|
146
|
|
|
* @param string $sStatus |
|
147
|
|
|
* @param string $sOrderId |
|
148
|
|
|
* @return $this |
|
149
|
|
|
*/ |
|
150
|
|
|
public function addApiLogEntry($aRequest, $aResponse, $sStatus = '', $sOrderId = '') |
|
151
|
|
|
{ |
|
152
|
|
|
$aRequest = $this->maskParameters($aRequest); |
|
153
|
|
|
$iTxid = ''; |
|
154
|
|
|
if (isset($aResponse['txid'])) { |
|
155
|
|
|
$iTxid = $aResponse['txid']; |
|
156
|
|
|
} elseif (isset($aRequest['txid'])) { |
|
157
|
|
|
$iTxid = $aRequest['txid']; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
$this->getConnection()->insert( |
|
161
|
|
|
$this->getMainTable(), |
|
162
|
|
|
[ |
|
163
|
|
|
'order_id' => $sOrderId, |
|
164
|
|
|
'store_id' => $this->shopHelper->getStoreId(), |
|
165
|
|
|
'refnr' => $this->getParamValue($aRequest, 'reference'), |
|
166
|
|
|
'txid' => $iTxid, |
|
167
|
|
|
'requesttype' => $this->getParamValue($aRequest, 'request'), |
|
168
|
|
|
'responsestatus' => $sStatus, |
|
169
|
|
|
'mid' => $this->getParamValue($aRequest, 'mid'), |
|
170
|
|
|
'aid' => $this->getParamValue($aRequest, 'aid', '0'), |
|
171
|
|
|
'portalid' => $this->getParamValue($aRequest, 'portalid'), |
|
172
|
|
|
'raw_request' => serialize($aRequest), |
|
173
|
|
|
'raw_response' => serialize($aResponse), |
|
174
|
|
|
] |
|
175
|
|
|
); |
|
176
|
|
|
return $this; |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths