Total Complexity | 98 |
Total Lines | 786 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like WcPagantisGateway often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use WcPagantisGateway, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class WcPagantisGateway extends WC_Payment_Gateway |
||
|
|||
26 | { |
||
27 | const METHOD_ID = "pagantis"; |
||
28 | |||
29 | /** Orders tablename */ |
||
30 | const ORDERS_TABLE = 'cart_process'; |
||
31 | |||
32 | /** Concurrency tablename */ |
||
33 | const LOGS_TABLE = 'pagantis_logs'; |
||
34 | |||
35 | const NOT_CONFIRMED = 'No se ha podido confirmar el pago'; |
||
36 | |||
37 | const CONFIG_TABLE = 'pagantis_config'; |
||
38 | |||
39 | /** @var Array $extraConfig */ |
||
40 | public $extraConfig; |
||
41 | |||
42 | /** @var string $language */ |
||
43 | public $language; |
||
44 | |||
45 | /** |
||
46 | * WcPagantisGateway constructor. |
||
47 | */ |
||
48 | public function __construct() |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @param $mofile |
||
92 | * @param $domain |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | public function loadPagantisTranslation($mofile, $domain) |
||
102 | } |
||
103 | |||
104 | /*********** |
||
105 | * |
||
106 | * HOOKS |
||
107 | * |
||
108 | ***********/ |
||
109 | |||
110 | /** |
||
111 | * PANEL - Display admin panel -> Hook: woocommerce_update_options_payment_gateways_pagantis |
||
112 | */ |
||
113 | public function admin_options() |
||
114 | { |
||
115 | $template_fields = array( |
||
116 | 'panel_description' => $this->method_description, |
||
117 | 'button1_label' => __('Login to your panel', 'pagantis'), |
||
118 | 'button2_label' => __('Documentation', 'pagantis'), |
||
119 | 'logo' => $this->icon, |
||
120 | 'settings' => $this->generate_settings_html($this->form_fields, false) |
||
121 | ); |
||
122 | wc_get_template('admin_header.php', $template_fields, '', $this->template_path); |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * PANEL - Check admin panel fields -> Hook: admin_notices |
||
127 | */ |
||
128 | public function pagantisCheckFields() |
||
129 | { |
||
130 | $error_string = ''; |
||
131 | if ($this->settings['enabled'] !== 'yes') { |
||
132 | return; |
||
133 | } elseif (!version_compare(phpversion(), '5.3.0', '>=')) { |
||
134 | $error_string = __(' is not compatible with your php and/or curl version', 'pagantis'); |
||
135 | $this->settings['enabled'] = 'no'; |
||
136 | } elseif ($this->settings['pagantis_public_key']=="" || $this->settings['pagantis_private_key']=="") { |
||
137 | $error_string = __(' is not configured correctly, the fields Public Key and Secret Key are mandatory for use this plugin', 'pagantis'); |
||
138 | $this->settings['enabled'] = 'no'; |
||
139 | } elseif (!in_array(get_woocommerce_currency(), $this->allowed_currencies)) { |
||
140 | $error_string = __(' only can be used in Euros', 'pagantis'); |
||
141 | $this->settings['enabled'] = 'no'; |
||
142 | } elseif ($this->extraConfig['PAGANTIS_SIMULATOR_MAX_INSTALLMENTS']<'2' |
||
143 | || $this->extraConfig['PAGANTIS_SIMULATOR_MAX_INSTALLMENTS']>'12') { |
||
144 | $error_string = __(' only can be payed from 2 to 12 installments', 'pagantis'); |
||
145 | } elseif ($this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS']<'2' |
||
146 | || $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS']>'12') { |
||
147 | $error_string = __(' only can be payed from 2 to 12 installments', 'pagantis'); |
||
148 | } elseif ($this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT']<0) { |
||
149 | $error_string = __(' can not have a minimum amount less than 0', 'pagantis'); |
||
150 | } |
||
151 | |||
152 | if ($error_string!='') { |
||
153 | $template_fields = array( |
||
154 | 'error_msg' => ucfirst(WcPagantisGateway::METHOD_ID).' '.$error_string, |
||
155 | ); |
||
156 | wc_get_template('error_msg.php', $template_fields, '', $this->template_path); |
||
157 | } |
||
158 | } |
||
159 | |||
160 | |||
161 | /** |
||
162 | * CHECKOUT - Generate the pagantis form. "Return" iframe or redirect. - Hook: woocommerce_receipt_pagantis |
||
163 | * @param $order_id |
||
164 | * |
||
165 | * @throws Exception |
||
166 | */ |
||
167 | public function pagantisReceiptPage($order_id) |
||
168 | { |
||
169 | try { |
||
170 | require_once(__ROOT__.'/vendor/autoload.php'); |
||
171 | global $woocommerce; |
||
172 | $order = new WC_Order($order_id); |
||
173 | |||
174 | if (!isset($order)) { |
||
175 | throw new Exception(_("Order not found")); |
||
176 | } |
||
177 | |||
178 | $shippingAddress = $order->get_address('shipping'); |
||
179 | $billingAddress = $order->get_address('billing'); |
||
180 | if ($shippingAddress['address_1'] == '') { |
||
181 | $shippingAddress = $billingAddress; |
||
182 | } |
||
183 | |||
184 | $national_id = $this->getNationalId($order); |
||
185 | $tax_id = $this->getTaxId($order); |
||
186 | |||
187 | $userAddress = new Address(); |
||
188 | $userAddress |
||
189 | ->setZipCode($shippingAddress['postcode']) |
||
190 | ->setFullName($shippingAddress['first_name']." ".$shippingAddress['last_name']) |
||
191 | ->setCountryCode('ES') |
||
192 | ->setCity($shippingAddress['city']) |
||
193 | ->setAddress($shippingAddress['address_1']." ".$shippingAddress['address_2']) |
||
194 | ; |
||
195 | $orderShippingAddress = new Address(); |
||
196 | $orderShippingAddress |
||
197 | ->setZipCode($shippingAddress['postcode']) |
||
198 | ->setFullName($shippingAddress['first_name']." ".$shippingAddress['last_name']) |
||
199 | ->setCountryCode('ES') |
||
200 | ->setCity($shippingAddress['city']) |
||
201 | ->setAddress($shippingAddress['address_1']." ".$shippingAddress['address_2']) |
||
202 | ->setFixPhone($shippingAddress['phone']) |
||
203 | ->setMobilePhone($shippingAddress['phone']) |
||
204 | ->setNationalId($national_id) |
||
205 | ->setTaxId($tax_id) |
||
206 | ; |
||
207 | $orderBillingAddress = new Address(); |
||
208 | $orderBillingAddress |
||
209 | ->setZipCode($billingAddress['postcode']) |
||
210 | ->setFullName($billingAddress['first_name']." ".$billingAddress['last_name']) |
||
211 | ->setCountryCode('ES') |
||
212 | ->setCity($billingAddress['city']) |
||
213 | ->setAddress($billingAddress['address_1']." ".$billingAddress['address_2']) |
||
214 | ->setFixPhone($billingAddress['phone']) |
||
215 | ->setMobilePhone($billingAddress['phone']) |
||
216 | ->setNationalId($national_id) |
||
217 | ->setTaxId($tax_id) |
||
218 | ; |
||
219 | $orderUser = new User(); |
||
220 | $orderUser |
||
221 | ->setAddress($userAddress) |
||
222 | ->setFullName($billingAddress['first_name']." ".$billingAddress['last_name']) |
||
223 | ->setBillingAddress($orderBillingAddress) |
||
224 | ->setEmail($billingAddress['email']) |
||
225 | ->setFixPhone($billingAddress['phone']) |
||
226 | ->setMobilePhone($billingAddress['phone']) |
||
227 | ->setShippingAddress($orderShippingAddress) |
||
228 | ->setNationalId($national_id) |
||
229 | ->setTaxId($tax_id) |
||
230 | ; |
||
231 | |||
232 | $previousOrders = $this->getOrders($order->get_user(), $billingAddress['email']); |
||
233 | foreach ($previousOrders as $previousOrder) { |
||
234 | $orderHistory = new OrderHistory(); |
||
235 | $orderElement = wc_get_order($previousOrder); |
||
236 | $orderCreated = $orderElement->get_date_created(); |
||
237 | $orderHistory |
||
238 | ->setAmount(intval(100 * $orderElement->get_total())) |
||
239 | ->setDate(new \DateTime($orderCreated->date('Y-m-d H:i:s'))) |
||
240 | ; |
||
241 | $orderUser->addOrderHistory($orderHistory); |
||
242 | } |
||
243 | |||
244 | $details = new Details(); |
||
245 | $shippingCost = $order->shipping_total; |
||
246 | $details->setShippingCost(intval(strval(100 * $shippingCost))); |
||
247 | $items = $woocommerce->cart->get_cart(); |
||
248 | foreach ($items as $key => $item) { |
||
249 | $product = new Product(); |
||
250 | $productDescription = sprintf( |
||
251 | '%s %s %s', |
||
252 | $item['data']->get_title(), |
||
253 | $item['data']->get_description(), |
||
254 | $item['data']->get_short_description() |
||
255 | ); |
||
256 | $product |
||
257 | ->setAmount(intval(100 * $item['line_total'])) |
||
258 | ->setQuantity($item['quantity']) |
||
259 | ->setDescription($productDescription); |
||
260 | $details->addProduct($product); |
||
261 | } |
||
262 | |||
263 | $orderShoppingCart = new ShoppingCart(); |
||
264 | $orderShoppingCart |
||
265 | ->setDetails($details) |
||
266 | ->setOrderReference($order->get_id()) |
||
267 | ->setPromotedAmount(0) |
||
268 | ->setTotalAmount(intval(strval(100 * $order->total))) |
||
269 | ; |
||
270 | $orderConfigurationUrls = new Urls(); |
||
271 | $cancelUrl = $this->getKoUrl($order); |
||
272 | $callback_arg = array( |
||
273 | 'wc-api'=>'wcpagantisgateway', |
||
274 | 'key'=>$order->get_order_key(), |
||
275 | 'order-received'=>$order->get_id()); |
||
276 | $callback_url = add_query_arg($callback_arg, home_url('/')); |
||
277 | $orderConfigurationUrls |
||
278 | ->setCancel($cancelUrl) |
||
279 | ->setKo($callback_url) |
||
280 | ->setAuthorizedNotificationCallback($callback_url) |
||
281 | ->setRejectedNotificationCallback($callback_url) |
||
282 | ->setOk($callback_url) |
||
283 | ; |
||
284 | $orderChannel = new Channel(); |
||
285 | $orderChannel |
||
286 | ->setAssistedSale(false) |
||
287 | ->setType(Channel::ONLINE) |
||
288 | ; |
||
289 | $orderConfiguration = new Configuration(); |
||
290 | |||
291 | $orderConfiguration |
||
292 | ->setChannel($orderChannel) |
||
293 | ->setUrls($orderConfigurationUrls) |
||
294 | ->setPurchaseCountry($this->language) |
||
295 | ; |
||
296 | $metadataOrder = new Metadata(); |
||
297 | $metadata = array( |
||
298 | 'woocommerce' => WC()->version, |
||
299 | 'pagantis' => $this->plugin_info['Version'], |
||
300 | 'php' => phpversion() |
||
301 | ); |
||
302 | foreach ($metadata as $key => $metadatum) { |
||
303 | $metadataOrder->addMetadata($key, $metadatum); |
||
304 | } |
||
305 | $orderApiClient = new Order(); |
||
306 | $orderApiClient |
||
307 | ->setConfiguration($orderConfiguration) |
||
308 | ->setMetadata($metadataOrder) |
||
309 | ->setShoppingCart($orderShoppingCart) |
||
310 | ->setUser($orderUser) |
||
311 | ; |
||
312 | |||
313 | if ($this->pagantis_public_key=='' || $this->pagantis_private_key=='') { |
||
314 | throw new \Exception('Public and Secret Key not found'); |
||
315 | } |
||
316 | $orderClient = new Client($this->pagantis_public_key, $this->pagantis_private_key); |
||
317 | $pagantisOrder = $orderClient->createOrder($orderApiClient); |
||
318 | if ($pagantisOrder instanceof \Pagantis\OrdersApiClient\Model\Order) { |
||
319 | $url = $pagantisOrder->getActionUrls()->getForm(); |
||
320 | $this->insertRow($order->get_id(), $pagantisOrder->getId()); |
||
321 | } else { |
||
322 | throw new OrderNotFoundException(); |
||
323 | } |
||
324 | |||
325 | if ($url=="") { |
||
326 | throw new Exception(_("No ha sido posible obtener una respuesta de Pagantis")); |
||
327 | } elseif ($this->extraConfig['PAGANTIS_FORM_DISPLAY_TYPE']=='0') { |
||
328 | wp_redirect($url); |
||
329 | exit; |
||
330 | } else { |
||
331 | $template_fields = array( |
||
332 | 'url' => $url, |
||
333 | 'checkoutUrl' => $cancelUrl |
||
334 | ); |
||
335 | wc_get_template('iframe.php', $template_fields, '', $this->template_path); |
||
336 | } |
||
337 | } catch (\Exception $exception) { |
||
338 | wc_add_notice(__('Payment error ', 'pagantis') . $exception->getMessage(), 'error'); |
||
339 | $this->insertLog($exception); |
||
340 | $checkout_url = get_permalink(wc_get_page_id('checkout')); |
||
341 | wp_redirect($checkout_url); |
||
342 | exit; |
||
343 | } |
||
344 | } |
||
345 | |||
346 | /** |
||
347 | * NOTIFICATION - Endpoint for Json notification - Hook: woocommerce_api_wcpagantisgateway |
||
348 | */ |
||
349 | public function pagantisNotification() |
||
350 | { |
||
351 | try { |
||
352 | $origin = ($_SERVER['REQUEST_METHOD'] == 'POST') ? 'Notify' : 'Order'; |
||
353 | |||
354 | include_once('notifyController.php'); |
||
355 | $notify = new WcPagantisNotify(); |
||
356 | $notify->setOrigin($origin); |
||
357 | /** @var \Pagantis\ModuleUtils\Model\Response\AbstractJsonResponse $result */ |
||
358 | $result = $notify->processInformation(); |
||
359 | } catch (Exception $exception) { |
||
360 | $result['notification_message'] = $exception->getMessage(); |
||
361 | $result['notification_error'] = true; |
||
362 | } |
||
363 | |||
364 | $paymentOrder = new WC_Order($result->getMerchantOrderId()); |
||
365 | if ($paymentOrder instanceof WC_Order) { |
||
366 | $orderStatus = strtolower($paymentOrder->get_status()); |
||
367 | } else { |
||
368 | $orderStatus = 'cancelled'; |
||
369 | } |
||
370 | $acceptedStatus = array('processing', 'completed'); |
||
371 | if (in_array($orderStatus, $acceptedStatus)) { |
||
372 | $returnUrl = $this->getOkUrl($paymentOrder); |
||
373 | } else { |
||
374 | $returnUrl = $this->getKoUrl($paymentOrder); |
||
375 | } |
||
376 | |||
377 | wp_redirect($returnUrl); |
||
378 | exit; |
||
379 | } |
||
380 | |||
381 | /** |
||
382 | * After failed status, set to processing not complete -> Hook: woocommerce_payment_complete_order_status |
||
383 | * @param $status |
||
384 | * @param $order_id |
||
385 | * @param $order |
||
386 | * |
||
387 | * @return string |
||
388 | */ |
||
389 | public function pagantisCompleteStatus($status, $order_id, $order) |
||
390 | { |
||
391 | if ($order->get_payment_method() == WcPagantisGateway::METHOD_ID) { |
||
392 | if ($order->get_status() == 'failed') { |
||
393 | $status = 'processing'; |
||
394 | } elseif ($order->get_status() == 'pending' && $status=='completed') { |
||
395 | $status = 'processing'; |
||
396 | } |
||
397 | } |
||
398 | |||
399 | return $status; |
||
400 | } |
||
401 | |||
402 | /*********** |
||
403 | * |
||
404 | * REDEFINED FUNCTIONS |
||
405 | * |
||
406 | ***********/ |
||
407 | |||
408 | /** |
||
409 | * CHECKOUT - Check if payment method is available (called by woocommerce, can't apply cammel caps) |
||
410 | * @return bool |
||
411 | */ |
||
412 | public function is_available() |
||
413 | { |
||
414 | $locale = strtolower(strstr(get_locale(), '_', true)); |
||
415 | $allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']); |
||
416 | $allowedCountry = (in_array(strtolower($locale), $allowedCountries)); |
||
417 | if ($this->enabled==='yes' && $this->pagantis_public_key!='' && $this->pagantis_private_key!='' && |
||
418 | (int)$this->get_order_total()>$this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'] && $allowedCountry) { |
||
419 | return true; |
||
420 | } |
||
421 | |||
422 | return false; |
||
423 | } |
||
424 | |||
425 | /** |
||
426 | * CHECKOUT - Checkout + admin panel title(method_title - get_title) (called by woocommerce,can't apply cammel caps) |
||
427 | * @return string |
||
428 | */ |
||
429 | public function get_title() |
||
430 | { |
||
431 | return __($this->extraConfig['PAGANTIS_TITLE'], 'pagantis'); |
||
432 | } |
||
433 | |||
434 | /** |
||
435 | * CHECKOUT - Called after push pagantis button on checkout(called by woocommerce, can't apply cammel caps |
||
436 | * @param $order_id |
||
437 | * @return array |
||
438 | */ |
||
439 | public function process_payment($order_id) |
||
440 | { |
||
441 | try { |
||
442 | $order = new WC_Order($order_id); |
||
443 | |||
444 | $redirectUrl = $order->get_checkout_payment_url(true); //pagantisReceiptPage function |
||
445 | if (strpos($redirectUrl, 'order-pay=')===false) { |
||
446 | $redirectUrl.="&order-pay=".$order_id; |
||
447 | } |
||
448 | |||
449 | return array( |
||
450 | 'result' => 'success', |
||
451 | 'redirect' => $redirectUrl |
||
452 | ); |
||
453 | |||
454 | } catch (Exception $e) { |
||
455 | wc_add_notice(__('Payment error ', 'pagantis') . $e->getMessage(), 'error'); |
||
456 | return array(); |
||
457 | } |
||
458 | } |
||
459 | |||
460 | /** |
||
461 | * CHECKOUT - simulator (called by woocommerce, can't apply cammel caps) |
||
462 | */ |
||
463 | public function payment_fields() |
||
464 | { |
||
465 | $locale = strtolower(strstr(get_locale(), '_', true)); |
||
466 | $allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']); |
||
467 | $allowedCountry = (in_array(strtolower($locale), $allowedCountries)); |
||
468 | |||
469 | $template_fields = array( |
||
470 | 'public_key' => $this->pagantis_public_key, |
||
471 | 'total' => WC()->session->cart_totals['total'], |
||
472 | 'enabled' => $this->settings['enabled'], |
||
473 | 'min_installments' => $this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'], |
||
474 | 'simulator_enabled' => $this->settings['pagantis_simulator'], |
||
475 | 'locale' => $locale, |
||
476 | 'allowedCountry' => $allowedCountry, |
||
477 | 'simulator_type' => $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'] |
||
478 | ); |
||
479 | wc_get_template('checkout_description.php', $template_fields, '', $this->template_path); |
||
480 | } |
||
481 | |||
482 | /*********** |
||
483 | * |
||
484 | * UTILS FUNCTIONS |
||
485 | * |
||
486 | ***********/ |
||
487 | |||
488 | /** |
||
489 | * PANEL KO_URL FIELD |
||
490 | * CHECKOUT PAGE => ?page_id=91 // ORDER-CONFIRMATION PAGE => ?page_id=91&order-pay=<order_id>&key=<order_key> |
||
491 | */ |
||
492 | private function generateOkUrl() |
||
493 | { |
||
494 | return $this->generateUrl($this->get_return_url()); |
||
495 | } |
||
496 | |||
497 | /** |
||
498 | * PANEL OK_URL FIELD |
||
499 | */ |
||
500 | private function generateKoUrl() |
||
501 | { |
||
502 | return $this->generateUrl(get_permalink(wc_get_page_id('checkout'))); |
||
503 | } |
||
504 | |||
505 | /** |
||
506 | * Replace empty space by {{var}} |
||
507 | * @param $url |
||
508 | * |
||
509 | * @return string |
||
510 | */ |
||
511 | private function generateUrl($url) |
||
512 | { |
||
513 | $parsed_url = parse_url($url); |
||
514 | if ($parsed_url !== false) { |
||
515 | $parsed_url['query'] = !isset($parsed_url['query']) ? '' : $parsed_url['query']; |
||
516 | parse_str($parsed_url['query'], $arrayParams); |
||
517 | foreach ($arrayParams as $keyParam => $valueParam) { |
||
518 | if ($valueParam=='') { |
||
519 | $arrayParams[$keyParam] = '{{'.$keyParam.'}}'; |
||
520 | } |
||
521 | } |
||
522 | $parsed_url['query'] = http_build_query($arrayParams); |
||
523 | $return_url = $this->unparseUrl($parsed_url); |
||
524 | return urldecode($return_url); |
||
525 | } else { |
||
526 | return $url; |
||
527 | } |
||
528 | } |
||
529 | |||
530 | /** |
||
531 | * Replace {{}} by vars values inside ok_url |
||
532 | * @param $order |
||
533 | * |
||
534 | * @return string |
||
535 | */ |
||
536 | private function getOkUrl($order) |
||
537 | { |
||
538 | return $this->getKeysUrl($order, $this->ok_url); |
||
539 | } |
||
540 | |||
541 | /** |
||
542 | * Replace {{}} by vars values inside ko_url |
||
543 | * @param $order |
||
544 | * |
||
545 | * @return string |
||
546 | */ |
||
547 | private function getKoUrl($order) |
||
548 | { |
||
549 | return $this->getKeysUrl($order, $this->ko_url); |
||
550 | } |
||
551 | |||
552 | /** |
||
553 | * Replace {{}} by vars values |
||
554 | * @param $order |
||
555 | * @param $url |
||
556 | * |
||
557 | * @return string |
||
558 | */ |
||
559 | private function getKeysUrl($order, $url) |
||
560 | { |
||
561 | $defaultFields = (get_class($order)=='WC_Order') ? |
||
562 | array('order-received'=>$order->get_id(), 'key'=>$order->get_order_key()) : |
||
563 | array(); |
||
564 | |||
565 | $parsedUrl = parse_url($url); |
||
566 | if ($parsedUrl !== false) { |
||
567 | //Replace parameters from url |
||
568 | $parsedUrl['query'] = $this->getKeysParametersUrl($parsedUrl['query'], $defaultFields); |
||
569 | |||
570 | //Replace path from url |
||
571 | $parsedUrl['path'] = $this->getKeysPathUrl($parsedUrl['path'], $defaultFields); |
||
572 | |||
573 | $returnUrl = $this->unparseUrl($parsedUrl); |
||
574 | return $returnUrl; |
||
575 | } |
||
576 | return $url; |
||
577 | } |
||
578 | |||
579 | /** |
||
580 | * Replace {{}} by vars values inside parameters |
||
581 | * @param $queryString |
||
582 | * @param $defaultFields |
||
583 | * |
||
584 | * @return string |
||
585 | */ |
||
586 | private function getKeysParametersUrl($queryString, $defaultFields) |
||
596 | } |
||
597 | |||
598 | /** |
||
599 | * Replace {{}} by vars values inside path |
||
600 | * @param $pathString |
||
601 | * @param $defaultFields |
||
602 | * |
||
603 | * @return string |
||
604 | */ |
||
605 | private function getKeysPathUrl($pathString, $defaultFields) |
||
606 | { |
||
607 | $arrayParams = explode("/", $pathString); |
||
608 | foreach ($arrayParams as $keyParam => $valueParam) { |
||
609 | preg_match('#\{{.*?}\}#', $valueParam, $match); |
||
610 | if (count($match)) { |
||
611 | $key = str_replace(array('{{','}}'), array('',''), $match[0]); |
||
612 | $arrayParams[$keyParam] = $defaultFields[$key]; |
||
613 | } |
||
614 | } |
||
615 | return implode('/', $arrayParams); |
||
616 | } |
||
617 | |||
618 | /** |
||
619 | * Replace {{var}} by empty space |
||
620 | * @param $parsed_url |
||
621 | * |
||
622 | * @return string |
||
623 | */ |
||
624 | private function unparseUrl($parsed_url) |
||
625 | { |
||
626 | $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : ''; |
||
627 | $host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; |
||
628 | $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''; |
||
629 | $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : ''; |
||
630 | $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : ''; |
||
631 | $path = $parsed_url['path']; |
||
632 | return $scheme . $host . $port . $path . $query . $fragment; |
||
633 | } |
||
634 | |||
635 | /** |
||
636 | * Get the orders of a customer |
||
637 | * @param $current_user |
||
638 | * @param $billingEmail |
||
639 | * |
||
640 | * @return mixed |
||
641 | */ |
||
642 | private function getOrders($current_user, $billingEmail) |
||
643 | { |
||
644 | $sign_up = ''; |
||
645 | $total_orders = 0; |
||
646 | $total_amt = 0; |
||
647 | $refund_amt = 0; |
||
648 | $total_refunds = 0; |
||
649 | $partial_refunds = 0; |
||
650 | if ($current_user->user_login) { |
||
651 | $is_guest = "false"; |
||
652 | $sign_up = substr($current_user->user_registered, 0, 10); |
||
653 | $customer_orders = get_posts(array( |
||
654 | 'numberposts' => - 1, |
||
655 | 'meta_key' => '_customer_user', |
||
656 | 'meta_value' => $current_user->ID, |
||
657 | 'post_type' => array( 'shop_order' ), |
||
658 | 'post_status' => array( 'wc-completed', 'wc-processing', 'wc-refunded' ), |
||
659 | )); |
||
660 | } else { |
||
661 | $is_guest = "true"; |
||
662 | $customer_orders = get_posts(array( |
||
663 | 'numberposts' => - 1, |
||
664 | 'meta_key' => '_billing_email', |
||
665 | 'meta_value' => $billingEmail, |
||
666 | 'post_type' => array( 'shop_order' ), |
||
667 | 'post_status' => array( 'wc-completed', 'wc-processing', 'wc-refunded'), |
||
668 | )); |
||
669 | foreach ($customer_orders as $customer_order) { |
||
670 | if (trim($sign_up)=='' || |
||
671 | strtotime(substr($customer_order->post_date, 0, 10)) <= strtotime($sign_up)) { |
||
672 | $sign_up = substr($customer_order->post_date, 0, 10); |
||
673 | } |
||
674 | } |
||
675 | } |
||
676 | |||
677 | return $customer_orders; |
||
678 | } |
||
679 | |||
680 | |||
681 | /** |
||
682 | * @param $orderId |
||
683 | * @param $pagantisOrderId |
||
684 | * |
||
685 | * @throws Exception |
||
686 | */ |
||
687 | private function insertRow($orderId, $pagantisOrderId) |
||
688 | { |
||
689 | global $wpdb; |
||
690 | $this->checkDbTable(); |
||
691 | $tableName = $wpdb->prefix.self::ORDERS_TABLE; |
||
692 | |||
693 | //Check if id exists |
||
694 | $resultsSelect = $wpdb->get_results("select * from $tableName where id='$orderId'"); |
||
695 | $countResults = count($resultsSelect); |
||
696 | if ($countResults == 0) { |
||
697 | $wpdb->insert( |
||
698 | $tableName, |
||
699 | array('id' => $orderId, 'order_id' => $pagantisOrderId), |
||
700 | array('%d', '%s') |
||
701 | ); |
||
702 | } else { |
||
703 | $wpdb->update( |
||
704 | $tableName, |
||
705 | array('order_id' => $pagantisOrderId), |
||
706 | array('id' => $orderId), |
||
707 | array('%s'), |
||
708 | array('%d') |
||
709 | ); |
||
710 | } |
||
711 | } |
||
712 | |||
713 | /** |
||
714 | * Check if orders table exists |
||
715 | */ |
||
716 | private function checkDbTable() |
||
717 | { |
||
718 | global $wpdb; |
||
719 | $tableName = $wpdb->prefix.self::ORDERS_TABLE; |
||
720 | |||
721 | if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") != $tableName) { |
||
722 | $charset_collate = $wpdb->get_charset_collate(); |
||
723 | $sql = "CREATE TABLE $tableName ( id int, order_id varchar(50), wc_order_id varchar(50), |
||
724 | UNIQUE KEY id (id)) $charset_collate"; |
||
725 | |||
726 | require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
||
727 | dbDelta($sql); |
||
728 | } |
||
729 | } |
||
730 | |||
731 | /** |
||
732 | * @return array |
||
733 | */ |
||
734 | private function getExtraConfig() |
||
735 | { |
||
736 | global $wpdb; |
||
737 | $tableName = $wpdb->prefix.self::CONFIG_TABLE; |
||
738 | $response = array(); |
||
739 | $dbResult = $wpdb->get_results("select config, value from $tableName", ARRAY_A); |
||
740 | foreach ($dbResult as $value) { |
||
741 | $response[$value['config']] = $value['value']; |
||
742 | } |
||
743 | |||
744 | return $response; |
||
745 | } |
||
746 | |||
747 | /** |
||
748 | * @param $order |
||
749 | * |
||
750 | * @return null |
||
751 | */ |
||
752 | private function getNationalId($order) |
||
753 | { |
||
754 | foreach ((array)$order->get_meta_data() as $mdObject) { |
||
755 | $data = $mdObject->get_data(); |
||
756 | if ($data['key'] == 'vat_number') { |
||
757 | return $data['value']; |
||
758 | } |
||
759 | } |
||
760 | |||
761 | return null; |
||
762 | } |
||
763 | |||
764 | /** |
||
765 | * @param $order |
||
766 | * |
||
767 | * @return mixed |
||
768 | */ |
||
769 | private function getTaxId($order) |
||
770 | { |
||
771 | foreach ((array)$order->get_meta_data() as $mdObject) { |
||
772 | $data = $mdObject->get_data(); |
||
773 | if ($data['key'] == 'billing_cfpiva') { |
||
774 | return $data['value']; |
||
775 | } |
||
776 | } |
||
777 | } |
||
778 | |||
779 | /** |
||
780 | * @param null $exception |
||
781 | * @param null $message |
||
782 | */ |
||
783 | private function insertLog($exception = null, $message = null) |
||
784 | { |
||
785 | global $wpdb; |
||
786 | $this->checkDbLogTable(); |
||
787 | $logEntry = new LogEntry(); |
||
788 | if ($exception instanceof \Exception) { |
||
789 | $logEntry = $logEntry->error($exception); |
||
790 | } else { |
||
791 | $logEntry = $logEntry->info($message); |
||
792 | } |
||
793 | $tableName = $wpdb->prefix.self::LOGS_TABLE; |
||
794 | $wpdb->insert($tableName, array('log' => $logEntry->toJson())); |
||
795 | } |
||
796 | /** |
||
797 | * Check if logs table exists |
||
798 | */ |
||
799 | private function checkDbLogTable() |
||
811 | } |
||
812 | } |
||
813 |
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