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 - 2020 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\PayoneConfig; |
||
30 | |||
31 | /** |
||
32 | * Resource model for payone_ratepay_profile_config table |
||
33 | */ |
||
34 | class RatepayProfileConfig extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb |
||
0 ignored issues
–
show
|
|||
35 | { |
||
36 | /** |
||
37 | * Map for methodCode to short payment method identifier for database columns |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $aMethodIdentifierMap = [ |
||
42 | PayoneConfig::METHOD_RATEPAY_INVOICE => 'invoice', |
||
43 | ]; |
||
44 | |||
45 | /** |
||
46 | * Initialize connection and table |
||
47 | * |
||
48 | * @return void |
||
49 | */ |
||
50 | protected function _construct() |
||
51 | { |
||
52 | $this->_init(\Payone\Core\Setup\Tables\RatepayProfileConfig::TABLE_RATEPAY_PROFILE_CONFIG, 'id'); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Returns all profile configs |
||
57 | * |
||
58 | * @return array |
||
59 | */ |
||
60 | public function getAllProfileConfigs() |
||
61 | { |
||
62 | return $this->getProfileConfigsByIds([]); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Get profile configs by given shop ids |
||
67 | * |
||
68 | * @param array $aShopIds |
||
69 | * @return array |
||
70 | */ |
||
71 | public function getProfileConfigsByIds($aShopIds) |
||
72 | { |
||
73 | $oSelect = $this->getConnection()->select() |
||
74 | ->from($this->getMainTable()) |
||
75 | ->order('shop_id ASC'); |
||
76 | |||
77 | if (!empty($aShopIds)) { |
||
78 | $oSelect->where("shop_id IN ('".implode("','", $aShopIds)."')"); |
||
79 | } |
||
80 | |||
81 | $aResult = $this->getConnection()->fetchAll($oSelect); |
||
82 | return $aResult; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Checks if given profile config exists in the database |
||
87 | * |
||
88 | * @param string $sShopId |
||
89 | * @return bool |
||
90 | */ |
||
91 | public function profileExists($sShopId) |
||
92 | { |
||
93 | $aProfileConfigs = $this->getProfileConfigsByIds([$sShopId]); |
||
94 | if (!empty($aProfileConfigs)) { |
||
95 | return true; |
||
96 | } |
||
97 | return false; |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Fills data array for insert and update queries |
||
102 | * |
||
103 | * @param array $aProfileResponse |
||
104 | * @return array |
||
105 | */ |
||
106 | protected function getDataArray($aProfileResponse) |
||
107 | { |
||
108 | $aData = [ |
||
109 | 'profile_id' => $aProfileResponse['add_paydata[profile-id]'], |
||
110 | 'merchant_name' => $aProfileResponse['add_paydata[merchant-name]'], |
||
111 | 'merchant_status' => $aProfileResponse['add_paydata[merchant-status]'], |
||
112 | 'shop_name' => $aProfileResponse['add_paydata[shop-name]'], |
||
113 | 'name' => $aProfileResponse['add_paydata[name]'], |
||
114 | 'currency' => $aProfileResponse['add_paydata[currency]'], |
||
115 | 'type' => $aProfileResponse['add_paydata[type]'], |
||
116 | 'activation_status_elv' => $aProfileResponse['add_paydata[activation-status-elv]'], |
||
117 | 'activation_status_installment' => $aProfileResponse['add_paydata[activation-status-installment]'], |
||
118 | 'activation_status_invoice' => $aProfileResponse['add_paydata[activation-status-invoice]'], |
||
119 | 'activation_status_prepayment' => $aProfileResponse['add_paydata[activation-status-prepayment]'], |
||
120 | 'amount_min_longrun' => $aProfileResponse['add_paydata[amount-min-longrun]'], |
||
121 | 'b2b_pq_full' => $aProfileResponse['add_paydata[b2b-PQ-full]'], |
||
122 | 'b2b_pq_light' => $aProfileResponse['add_paydata[b2b-PQ-light]'], |
||
123 | 'b2b_elv' => $aProfileResponse['add_paydata[b2b-elv]'], |
||
124 | 'b2b_installment' => $aProfileResponse['add_paydata[b2b-installment]'], |
||
125 | 'b2b_invoice' => $aProfileResponse['add_paydata[b2b-invoice]'], |
||
126 | 'b2b_prepayment' => $aProfileResponse['add_paydata[b2b-prepayment]'], |
||
127 | 'country_code_billing' => $aProfileResponse['add_paydata[country-code-billing]'], |
||
128 | 'country_code_delivery' => $aProfileResponse['add_paydata[country-code-delivery]'], |
||
129 | 'delivery_address_pq_full' => $aProfileResponse['add_paydata[delivery-address-PQ-full]'], |
||
130 | 'delivery_address_pq_light' => $aProfileResponse['add_paydata[delivery-address-PQ-light]'], |
||
131 | 'delivery_address_elv' => $aProfileResponse['add_paydata[delivery-address-elv]'], |
||
132 | 'delivery_address_installment' => $aProfileResponse['add_paydata[delivery-address-installment]'], |
||
133 | 'delivery_address_invoice' => $aProfileResponse['add_paydata[delivery-address-invoice]'], |
||
134 | 'delivery_address_prepayment' => $aProfileResponse['add_paydata[delivery-address-prepayment]'], |
||
135 | 'device_fingerprint_snippet_id' => isset($aProfileResponse['add_paydata[device-fingerprint-snippet-id]']) ? $aProfileResponse['add_paydata[device-fingerprint-snippet-id]'] : NULL, |
||
136 | 'eligibility_device_fingerprint' => isset($aProfileResponse['add_paydata[eligibility-device-fingerprint]']) ? $aProfileResponse['add_paydata[eligibility-device-fingerprint]'] : NULL, |
||
137 | 'eligibility_ratepay_elv' => $aProfileResponse['add_paydata[eligibility-ratepay-elv]'], |
||
138 | 'eligibility_ratepay_installment' => $aProfileResponse['add_paydata[eligibility-ratepay-installment]'], |
||
139 | 'eligibility_ratepay_invoice' => $aProfileResponse['add_paydata[eligibility-ratepay-invoice]'], |
||
140 | 'eligibility_ratepay_pq_full' => $aProfileResponse['add_paydata[eligibility-ratepay-pq-full]'], |
||
141 | 'eligibility_ratepay_pq_light' => $aProfileResponse['add_paydata[eligibility-ratepay-pq-light]'], |
||
142 | 'eligibility_ratepay_prepayment' => $aProfileResponse['add_paydata[eligibility-ratepay-prepayment]'], |
||
143 | 'interest_rate_merchant_towards_bank' => $aProfileResponse['add_paydata[interest-rate-merchant-towards-bank]'], |
||
144 | 'interestrate_default' => $aProfileResponse['add_paydata[interestrate-default]'], |
||
145 | 'interestrate_max' => $aProfileResponse['add_paydata[interestrate-max]'], |
||
146 | 'interestrate_min' => $aProfileResponse['add_paydata[interestrate-min]'], |
||
147 | 'min_difference_dueday' => $aProfileResponse['add_paydata[min-difference-dueday]'], |
||
148 | 'month_allowed' => $aProfileResponse['add_paydata[month-allowed]'], |
||
149 | 'month_longrun' => $aProfileResponse['add_paydata[month-longrun]'], |
||
150 | 'month_number_max' => $aProfileResponse['add_paydata[month-number-max]'], |
||
151 | 'month_number_min' => $aProfileResponse['add_paydata[month-number-min]'], |
||
152 | 'payment_amount' => $aProfileResponse['add_paydata[payment-amount]'], |
||
153 | 'payment_firstday' => $aProfileResponse['add_paydata[payment-firstday]'], |
||
154 | 'payment_lastrate' => $aProfileResponse['add_paydata[payment-lastrate]'], |
||
155 | 'rate_min_longrun' => $aProfileResponse['add_paydata[rate-min-longrun]'], |
||
156 | 'rate_min_normal' => $aProfileResponse['add_paydata[rate-min-normal]'], |
||
157 | 'service_charge' => $aProfileResponse['add_paydata[service-charge]'], |
||
158 | 'tx_limit_elv_max' => $aProfileResponse['add_paydata[tx-limit-elv-max]'], |
||
159 | 'tx_limit_elv_min' => $aProfileResponse['add_paydata[tx-limit-elv-min]'], |
||
160 | 'tx_limit_installment_max' => $aProfileResponse['add_paydata[tx-limit-installment-max]'], |
||
161 | 'tx_limit_installment_min' => $aProfileResponse['add_paydata[tx-limit-installment-min]'], |
||
162 | 'tx_limit_invoice_max' => $aProfileResponse['add_paydata[tx-limit-invoice-max]'], |
||
163 | 'tx_limit_invoice_min' => $aProfileResponse['add_paydata[tx-limit-invoice-min]'], |
||
164 | 'tx_limit_prepayment_max' => $aProfileResponse['add_paydata[tx-limit-prepayment-max]'], |
||
165 | 'tx_limit_prepayment_min' => $aProfileResponse['add_paydata[tx-limit-prepayment-min]'], |
||
166 | 'valid_payment_firstdays' => $aProfileResponse['add_paydata[valid-payment-firstdays]'], |
||
167 | ]; |
||
168 | return $aData; |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * Updates existing profile config in the database |
||
173 | * |
||
174 | * @param string $sShopId |
||
175 | * @param array $aProfileResponse |
||
176 | * @return void |
||
177 | */ |
||
178 | public function updateProfileConfig($sShopId, $aProfileResponse) |
||
179 | { |
||
180 | $data = $this->getDataArray($aProfileResponse); |
||
181 | $where = ['shop_id = ?' => $sShopId]; |
||
182 | $this->getConnection()->update($this->getMainTable(), $data, $where); |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * Insert new line into payone_ratepay_profile_config table |
||
187 | * |
||
188 | * @param string $sShopId |
||
189 | * @param array $aProfileResponse |
||
190 | * @return void |
||
191 | */ |
||
192 | public function insertProfileConfig($sShopId, $aProfileResponse) |
||
193 | { |
||
194 | $data = $this->getDataArray($aProfileResponse); |
||
195 | $data['shop_id'] = $sShopId; |
||
196 | $this->getConnection()->insert($this->getMainTable(), $data); |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * Returns ratepay method identifier |
||
201 | * |
||
202 | * @param string $sMethodCode |
||
203 | * @return string|false |
||
204 | */ |
||
205 | protected function getRatepayMethodIdentifierByMethodCode($sMethodCode) |
||
206 | { |
||
207 | if (isset($this->aMethodIdentifierMap[$sMethodCode])) { |
||
208 | return $this->aMethodIdentifierMap[$sMethodCode]; |
||
209 | } |
||
210 | return false; |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * Get matching shop id for current quote parameters |
||
215 | * |
||
216 | * @param string $sMethodCode |
||
217 | * @param array $aShopIds |
||
218 | * @param string $sCountryCode |
||
219 | * @param string $sCurrency |
||
220 | * @param double $dGrandTotal |
||
221 | * @return string|bool |
||
222 | */ |
||
223 | public function getMatchingShopId($sMethodCode, $aShopIds, $sCountryCode, $sCurrency, $dGrandTotal) |
||
224 | { |
||
225 | $sRatepayMethodIdentifier = $this->getRatepayMethodIdentifierByMethodCode($sMethodCode); |
||
226 | |||
227 | $oSelect = $this->getConnection()->select() |
||
228 | ->from($this->getMainTable(), ['shop_id']) |
||
229 | ->where("shop_id IN ('".implode("','", $aShopIds)."')") |
||
230 | ->where("tx_limit_".$sRatepayMethodIdentifier."_min <= :grandTotal") |
||
231 | ->where("tx_limit_".$sRatepayMethodIdentifier."_max >= :grandTotal") |
||
232 | ->where("country_code_billing = :countryCode") |
||
233 | ->where("currency = :currency") |
||
234 | ->order('shop_id ASC') |
||
235 | ->limit(1); |
||
236 | |||
237 | $aParams = [ |
||
238 | 'grandTotal' => $dGrandTotal, |
||
239 | 'countryCode' => $sCountryCode, |
||
240 | 'currency' => $sCurrency, |
||
241 | ]; |
||
242 | |||
243 | $sShopId = $this->getConnection()->fetchOne($oSelect, $aParams); |
||
244 | if (empty($sShopId)) { |
||
245 | return false; |
||
246 | } |
||
247 | return $sShopId; |
||
248 | } |
||
249 | } |
||
250 |
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