|
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 Magento\Quote\Api\Data\AddressInterface; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* CheckedAddresses resource model |
|
33
|
|
|
*/ |
|
34
|
|
|
class CheckedAddresses extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
|
|
/** |
|
37
|
|
|
* Shop helper object |
|
38
|
|
|
* |
|
39
|
|
|
* @var \Payone\Core\Helper\Checkout |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $checkoutHelper; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Class constructor |
|
45
|
|
|
* |
|
46
|
|
|
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context |
|
47
|
|
|
* @param \Payone\Core\Helper\Checkout $checkoutHelper |
|
48
|
|
|
* @param string $connectionName |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __construct( |
|
51
|
|
|
\Magento\Framework\Model\ResourceModel\Db\Context $context, |
|
|
|
|
|
|
52
|
|
|
\Payone\Core\Helper\Checkout $checkoutHelper, |
|
53
|
|
|
$connectionName = null |
|
54
|
|
|
) { |
|
55
|
|
|
parent::__construct($context, $connectionName); |
|
56
|
|
|
$this->checkoutHelper = $checkoutHelper; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Initialize connection and table |
|
61
|
|
|
* |
|
62
|
|
|
* @return void |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function _construct() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->_init('payone_checked_addresses', 'address_hash'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Save Api-log entry to database |
|
71
|
|
|
* |
|
72
|
|
|
* @param AddressInterface $oAddress |
|
73
|
|
|
* @param array $aResponse |
|
74
|
|
|
* @param string $sChecktype |
|
75
|
|
|
* @param bool $blIsBonicheck |
|
76
|
|
|
* @return $this |
|
77
|
|
|
*/ |
|
78
|
|
|
public function addCheckedAddress(AddressInterface $oAddress, $aResponse, $sChecktype, $blIsBonicheck = false) |
|
79
|
|
|
{ |
|
80
|
|
|
$sHash = $this->checkoutHelper->getHashFromAddress($oAddress, $aResponse); // generate hash from given address |
|
81
|
|
|
$this->getConnection()->insert( |
|
82
|
|
|
$this->getMainTable(), |
|
83
|
|
|
[ |
|
84
|
|
|
'address_hash' => $sHash, |
|
85
|
|
|
'is_bonicheck' => $blIsBonicheck, |
|
86
|
|
|
'checktype' => $sChecktype, |
|
87
|
|
|
'score' => isset($aResponse['score']) ? $aResponse['score'] : '' |
|
88
|
|
|
] |
|
89
|
|
|
); |
|
90
|
|
|
return $this; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Get lifetime config |
|
95
|
|
|
* |
|
96
|
|
|
* @param string $sConfigField |
|
97
|
|
|
* @param bool $blIsBonicheck |
|
98
|
|
|
* @return string |
|
99
|
|
|
*/ |
|
100
|
|
|
protected function getConfigValue($sConfigField, $blIsBonicheck) |
|
101
|
|
|
{ |
|
102
|
|
|
$sGroup = 'address_check'; |
|
103
|
|
|
if ($blIsBonicheck === true) { |
|
104
|
|
|
$sGroup = 'creditrating'; |
|
105
|
|
|
} |
|
106
|
|
|
return $this->checkoutHelper->getConfigParam($sConfigField, $sGroup, 'payone_protect'); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Executes a select on the checked addresses table |
|
111
|
|
|
* |
|
112
|
|
|
* @param AddressInterface $oAddress |
|
113
|
|
|
* @param string $sChecktype |
|
114
|
|
|
* @param bool $blIsBonicheck |
|
115
|
|
|
* @param string $sLifetime |
|
116
|
|
|
* @param array $aSelectFields |
|
117
|
|
|
* @return string |
|
118
|
|
|
* @throws \Magento\Framework\Exception\LocalizedException |
|
119
|
|
|
*/ |
|
120
|
|
|
protected function selectAddressesChecked(AddressInterface $oAddress, $sChecktype, $blIsBonicheck, $sLifetime, $aSelectFields) |
|
121
|
|
|
{ |
|
122
|
|
|
$oSelect = $this->getConnection()->select() |
|
123
|
|
|
->from($this->getMainTable(), $aSelectFields) |
|
124
|
|
|
->where("address_hash = :hash") |
|
125
|
|
|
->where("is_bonicheck = :isBoni") |
|
126
|
|
|
->where("checktype = :checkType") |
|
127
|
|
|
->where('checkdate > DATE_SUB(NOW(), INTERVAL :lifetime DAY)'); |
|
128
|
|
|
|
|
129
|
|
|
$aParams = [ |
|
130
|
|
|
'hash' => $this->checkoutHelper->getHashFromAddress($oAddress), |
|
131
|
|
|
'isBoni' => $blIsBonicheck, |
|
132
|
|
|
'checkType' => $sChecktype, |
|
133
|
|
|
'lifetime' => $sLifetime |
|
134
|
|
|
]; |
|
135
|
|
|
|
|
136
|
|
|
return $this->getConnection()->fetchOne($oSelect, $aParams); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Returns score for the given address |
|
141
|
|
|
* |
|
142
|
|
|
* @param AddressInterface $oAddress |
|
143
|
|
|
* @param bool $blIsBonicheck |
|
144
|
|
|
* @return string |
|
145
|
|
|
* @throws \Magento\Framework\Exception\LocalizedException |
|
146
|
|
|
*/ |
|
147
|
|
|
public function getLatestScoreForAddress(AddressInterface $oAddress, $blIsBonicheck) |
|
148
|
|
|
{ |
|
149
|
|
|
$sLifetime = $this->getConfigValue('result_lifetime', $blIsBonicheck); |
|
150
|
|
|
$sChecktype = $this->getConfigValue('type', $blIsBonicheck); |
|
151
|
|
|
return $this->selectAddressesChecked($oAddress, $sChecktype, $blIsBonicheck, $sLifetime, ['score']); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Check and return if this exact address has been checked before |
|
156
|
|
|
* |
|
157
|
|
|
* @param AddressInterface $oAddress |
|
158
|
|
|
* @param string $sChecktype |
|
159
|
|
|
* @param bool $blIsBonicheck |
|
160
|
|
|
* @return bool |
|
161
|
|
|
* @throws \Magento\Framework\Exception\LocalizedException |
|
162
|
|
|
*/ |
|
163
|
|
|
public function wasAddressCheckedBefore(AddressInterface $oAddress, $sChecktype, $blIsBonicheck = false) |
|
164
|
|
|
{ |
|
165
|
|
|
$sLifetime = $this->getConfigValue('result_lifetime', $blIsBonicheck); |
|
166
|
|
|
if (empty($sLifetime) || !is_numeric($sLifetime)) { |
|
167
|
|
|
return false; // no lifetime = check every time |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
$sDate = $this->selectAddressesChecked($oAddress, $sChecktype, $blIsBonicheck, $sLifetime, ['checkdate']); |
|
171
|
|
|
if ($sDate != false) { |
|
|
|
|
|
|
172
|
|
|
return true; |
|
173
|
|
|
} |
|
174
|
|
|
return false; |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
|
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