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