PluginProbe
MailerLite – WooCommerce integration / 1.8.7
MailerLite – WooCommerce integration v1.8.7
3.1.27 3.1.25 3.1.26 3.1.24 3.1.23 3.1.22 3.1.21 3.1.20 3.1.19 3.1.18 3.1.17 3.1.16 3.1.15 1.8.7 1.8.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 All 148 releases
woo-mailerlite / includes / shared / api / class.woo-mailerlite-platform-api.php

class.woo-mailerlite-platform-api.php in MailerLite – WooCommerce integration 1.8.7, at includes/shared/api/class.woo-mailerlite-platform-api.php

859 lines 17.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MailerLite\Includes\Shared\Api;
4
5 class PlatformAPI
6 {
7
8 private $api;
9 private $api_key;
10
11 /**
12 * MailerLiteAPI constructor
13 *
14 * @access public
15 * @return void
16 * @since 1.6.0
17 */
18 public function __construct($api_key)
19 {
20
21 $this->api_key = $api_key;
22
23 if ($api_key !== '') {
24
25 switch ($this->getApiType()) {
26 case ApiType::CLASSIC:
27 $this->api = new MailerLiteClassicAPI($api_key);
28 break;
29 case ApiType::CURRENT:
30 $this->api = new MailerLiteAPI($api_key);
31 break;
32 default:
33 $this->api_key = '';
34 break;
35 }
36 }
37 }
38
39 /**
40 * get API Key Type
41 *
42 * @access public
43 * @return int
44 * @since 1.6.0
45 */
46 public function getApiType()
47 {
48
49 if ($this->api_key == '') {
50
51 return ApiType::INVALID;
52 }
53
54 if ($this->isValidClassicKey()) {
55
56 return ApiType::CLASSIC;
57 } else {
58
59 return ApiType::CURRENT;
60 }
61 }
62
63 /**
64 * Validate API Key
65 *
66 * @access public
67 * @return mixed
68 * @since 1.6.0
69 */
70 public function validateKey()
71 {
72
73 return $this->api->validateKey();
74 }
75
76 /**
77 * Update subscriber
78 *
79 * @access public
80 * @return mixed
81 * @since 1.6.0
82 */
83 public function updateSubscriber($subscriber_email, $subscriber_data)
84 {
85
86 return $this->api->updateSubscriber($subscriber_email, $subscriber_data);
87 }
88
89 /**
90 * Update subscriber status
91 *
92 * @access public
93 * @return mixed
94 * @since 1.7.4
95 */
96 public function updateSubscriberStatus($email, $status)
97 {
98
99 return $this->api->updateSubscriberStatus($email, $status);
100 }
101
102 /**
103 * Search for a subscriber
104 *
105 * @access public
106 * @return mixed
107 * @since 1.6.0
108 */
109 public function searchSubscriber($query)
110 {
111
112 return $this->api->searchSubscriber($query);
113 }
114
115 /**
116 * Get groups
117 *
118 * @access public
119 * @return mixed
120 * @since 1.6.0
121 */
122 public function getGroups($params = [])
123 {
124
125 return $this->api->getGroups($params);
126 }
127
128 /**
129 * Check if more groups need to be loaded
130 *
131 * @access public
132 * @return mixed
133 * @since 1.6.0
134 */
135 public function checkMoreGroups($limit = 100, $offset = 2)
136 {
137
138 return $this->api->checkMoreGroups($limit, $offset);
139 }
140
141 /**
142 * Check if more groups need to be loaded
143 *
144 * @access public
145 * @return mixed
146 * @since 1.6.0
147 */
148 public function getMoreGroups($limit = 100, $offset = 1)
149 {
150
151 return $this->api->getMoreGroups($limit, $offset);
152 }
153
154 /**
155 * Get Double opt-in setting
156 *
157 * @access public
158 * @return mixed
159 * @since 1.6.0
160 */
161 public function getDoubleOptin()
162 {
163
164 return $this->api->getDoubleOptin();
165 }
166
167 /**
168 * Enable/Disable Double opt-in setting
169 *
170 * @access public
171 * @return mixed
172 * @since 1.6.0
173 */
174 public function setDoubleOptin($enable)
175 {
176 return $this->api->setDoubleOptin($enable);
177 }
178
179 /**
180 * Get Fields
181 *
182 * @access public
183 * @return mixed
184 * @since 1.6.0
185 */
186 public function getFields($params = [])
187 {
188
189 return $this->api->getFields($params);
190 }
191
192 /**
193 * Create Custom Field
194 *
195 * @access public
196 * @return mixed
197 * @since 1.6.0
198 */
199 public function createField($title, $type)
200 {
201
202 return $this->api->createField($title, $type);
203 }
204
205 /**
206 * Update Custom Field
207 *
208 * @access public
209 * @return mixed
210 * @since 1.7.11
211 */
212 public function updateField($id, $name)
213 {
214
215 return $this->api->updateField($id, $name);
216 }
217
218 /**
219 * Sync WooCommerce Customer
220 *
221 * @access public
222 * @return mixed
223 * @since 1.6.0
224 */
225 public function syncCustomerWooCommerce($customer_id, $email, $fields, $shopUrl)
226 {
227
228 return $this->api->syncCustomerWooCommerce($customer_id, $email, $fields, $shopUrl);
229 }
230
231 /**
232 * Set WooCommerce Consumer Data
233 *
234 * @access public
235 * @return mixed
236 * @since 1.6.0
237 */
238 public function setConsumerData(
239 $consumerKey,
240 $consumerSecret,
241 $store,
242 $currency,
243 $group_id,
244 $resubscribe,
245 $ignoreList,
246 $create_segments,
247 $shop_name,
248 $shop_id,
249 $popups_enabled
250 ) {
251
252 return $this->api->setConsumerData($consumerKey, $consumerSecret, $store, $currency, $group_id, $resubscribe,
253 $ignoreList, $create_segments, $shop_name, $shop_id, $popups_enabled);
254 }
255
256 /**
257 * Send WooCommerce Subscriber Data
258 *
259 * @access public
260 * @return mixed
261 * @since 1.6.0
262 */
263 public function sendSubscriberData($shop_id, $data)
264 {
265
266 return $this->api->sendSubscriberData($shop_id, $data);
267 }
268
269 /**
270 * Save WooCommerce Order
271 *
272 * @access public
273 * @return mixed
274 * @since 1.6.0
275 */
276 public function saveOrder($shop, $orderData)
277 {
278
279 return $this->api->saveOrder($shop, $orderData);
280 }
281
282 /**
283 * Send WooCommerce Order Processing
284 *
285 * @access public
286 *
287 * @param $shop_id
288 * @param $data
289 *
290 * @return mixed
291 * @since 1.6.0
292 */
293 public function sendOrderProcessing($shop_id, $data)
294 {
295
296 return $this->api->sendOrderProcessing($shop_id, $data);
297 }
298
299 /**
300 * Send WooCommerce Cart
301 *
302 * @access public
303 * @return mixed
304 * @since 1.6.0
305 */
306 public function sendCart($shop, $cartData)
307 {
308
309 return $this->api->sendCart($shop, $cartData);
310 }
311
312 /**
313 * Toggle WooCommerce Shop
314 *
315 * @access public
316 *
317 * @param $shop
318 * @param $activeState
319 * @param $shop_id
320 * @param $shop_name
321 *
322 * @return mixed
323 * @since 1.6.0
324 */
325 public function toggleShop($shop, $activeState, $shop_id, $shop_name)
326 {
327
328 return $this->api->toggleShop($shop, $activeState, $shop_id, $shop_name);
329 }
330
331 /**
332 * Get WooCommerce Shop Settings
333 *
334 * @access public
335 * @return mixed
336 * @since 1.6.0
337 */
338 public function getShopSettings($shopUrl)
339 {
340
341 return $this->api->getShopSettings($shopUrl);
342 }
343
344 /**
345 * Validate WooCommerce Account
346 *
347 * @access public
348 * @return mixed
349 * @since 1.6.0
350 */
351 public function validateAccount()
352 {
353
354 return $this->api->validateAccount();
355 }
356
357 /**
358 * Get list of shops
359 *
360 * @access public
361 * @return mixed
362 * @since 1.6.0
363 */
364 public function getShops()
365 {
366 return $this->api->getShops();
367 }
368
369 /**
370 * Get a shop
371 *
372 * @access public
373 * @return mixed
374 * @since 1.6.0
375 */
376 public function getShop($shop_id)
377 {
378
379 return $this->api->getShop($shop_id);
380 }
381
382 /**
383 * Create shop
384 *
385 * @access public
386 *
387 * @param $name
388 * @param $url
389 * @param $currency
390 * @param $group_id
391 * @param $enable_popups
392 * @param $access_data
393 *
394 * @return mixed
395 * @since 1.6.0
396 */
397 public function createShop($name, $url, $currency, $group_id, $enable_popups, $access_data)
398 {
399 return $this->api->createShop($name, $url, $currency, $group_id, $enable_popups, $access_data);
400 }
401
402 /**
403 * Delete shop
404 *
405 * @access public
406 *
407 * @param $shop
408 *
409 * @return mixed
410 * @since 1.6.0
411 */
412 public function deleteShop($shop)
413 {
414 return $this->api->deleteShop($shop);
415 }
416
417 /**
418 * Fetch order
419 *
420 * @access public
421 *
422 * @param $shop_id
423 * @param $order_id
424 *
425 * @return mixed
426 * @since 1.6.0
427 */
428 public function fetchOrder($shop_id, $order_id)
429 {
430
431 return $this->api->fetchOrder($shop_id, $order_id);
432 }
433
434 /**
435 * Import orders
436 *
437 * @access public
438 *
439 * @param $shop_id
440 * @param $orders
441 *
442 * @return array
443 * @since 1.6.0
444 */
445 public function importOrders($shop_id, $orders)
446 {
447
448 return $this->api->importOrders($shop_id, $orders);
449 }
450
451 /**
452 * Import customers
453 *
454 * @access public
455 *
456 * @param $shop_id
457 * @param $customers
458 *
459 * @return array
460 * @since 1.8.5
461 */
462 public function importCustomers($shop_id, $customers)
463 {
464
465 return $this->api->importCustomers($shop_id, $customers);
466 }
467
468 /**
469 * Sync order
470 *
471 * @access public
472 *
473 * @param $shop_id
474 * @param $order_id
475 * @param $customer
476 * @param $cart
477 * @param $status
478 * @param $total_price
479 * @param $created_at
480 *
481 * @return mixed
482 * @since 1.6.0
483 */
484 public function syncOrder($shop_id, $order_id, $customer, $cart, $status, $total_price, $created_at)
485 {
486
487 return $this->api->syncOrder($shop_id, $order_id, $customer, $cart, $status, $total_price, $created_at);
488 }
489
490 /**
491 * Delete order
492 *
493 * @access public
494 *
495 * @param $shop_id
496 * @param $order_id
497 *
498 * @return mixed
499 * @since 1.6.0
500 */
501 public function deleteOrder($shop_id, $order_id)
502 {
503
504 return $this->api->deleteOrder($shop_id, $order_id);
505 }
506
507 /**
508 * Update order
509 *
510 * @access public
511 *
512 * @param $shop_id
513 * @param $order_id
514 * @param $status
515 * @param $total_price
516 *
517 * @return mixed
518 * @since 1.6.0
519 */
520 public function updateOrder($shop_id, $order_id, $status, $total_price)
521 {
522
523 return $this->api->updateOrder($shop_id, $order_id, $status, $total_price);
524 }
525
526 /**
527 * Sync product
528 *
529 * @access public
530 *
531 * @param $shop_id
532 * @param $product_id
533 * @param $name
534 * @param $price
535 * @param $exclude_automation
536 * @param $url
537 * @param $image
538 * @param $categories
539 *
540 * @return mixed
541 * @since 1.6.0
542 */
543 public function syncProduct($shop_id, $product_id, $name, $price, $exclude_automation, $url, $image, $categories)
544 {
545
546 return $this->api->syncProduct($shop_id, $product_id, $name, $price, $exclude_automation, $url, $image,
547 $categories);
548 }
549
550 /**
551 * Replace product categories
552 *
553 * @access public
554 *
555 * @param $shop_id
556 * @param $product_id
557 * @param $categories
558 *
559 * @return mixed
560 * @since 1.6.0
561 */
562 public function replaceProductCategories($shop_id, $product_id, $categories)
563 {
564
565 return $this->api->replaceProductCategories($shop_id, $product_id, $categories);
566 }
567
568 /**
569 * Import products
570 *
571 * @access public
572 *
573 * @param $shop_id
574 * @param $products
575 *
576 * @return array
577 * @since 1.6.0
578 */
579 public function importProducts($shop_id, $products)
580 {
581
582 return $this->api->importProducts($shop_id, $products);
583 }
584
585 /**
586 * Delete product
587 *
588 * @access public
589 *
590 * @param $shop_id
591 * @param $product_id
592 *
593 * @return mixed
594 * @since 1.6.0
595 */
596 public function deleteProduct($shop_id, $product_id)
597 {
598
599 return $this->api->deleteOrder($shop_id, $product_id);
600 }
601
602 /**
603 * Create product category
604 *
605 * @access public
606 *
607 * @param $shop_id
608 * @param $category_id
609 * @param $name
610 *
611 * @return mixed
612 * @since 1.6.0
613 */
614 public function syncCategory($shop_id, $category_id, $name)
615 {
616
617 return $this->api->syncCategory($shop_id, $category_id, $name);
618 }
619
620 /**
621 * Import categories
622 *
623 * @access public
624 *
625 * @param $shop_id
626 * @param $categories
627 *
628 * @return array
629 * @since 1.6.0
630 */
631 public function importCategories($shop_id, $categories)
632 {
633
634 return $this->api->importCategories($shop_id, $categories);
635 }
636
637 /**
638 * Delete product category
639 *
640 * @access public
641 *
642 * @param $shop_id
643 * @param $category_id
644 *
645 * @return mixed
646 * @since 1.6.0
647 */
648 public function deleteCategory($shop_id, $category_id)
649 {
650
651 return $this->api->deleteCategory($shop_id, $category_id);
652 }
653
654 /**
655 * Sync customer
656 *
657 * @access public
658 *
659 * @param $shop_id
660 * @param $customer_id
661 * @param $email
662 * @param $fields
663 *
664 * @return mixed
665 * @since 1.6.0
666 */
667 public function syncCustomer($shop_id, $customer_id, $email, $fields)
668 {
669
670 return $this->api->syncCustomer($shop_id, $customer_id, $email, $fields);
671 }
672
673 /**
674 * Update customer
675 *
676 * @access public
677 *
678 * @param $shop_id
679 * @param $customer_id
680 * @param $email
681 * @param $accepts_marketing
682 * @param $create_subscriber
683 *
684 * @return mixed
685 * @since 1.6.0
686 */
687 public function updateCustomer($shop_id, $customer_id, $email, $accepts_marketing, $create_subscriber)
688 {
689
690 return $this->api->updateCustomer($shop_id, $customer_id, $email, $accepts_marketing, $create_subscriber);
691 }
692
693 /**
694 * Delete customer
695 *
696 * @access public
697 *
698 * @param $shop_id
699 * @param $customer_id
700 *
701 * @return bool
702 * @since 1.6.0
703 */
704 public function deleteCustomer($shop_id, $customer_id)
705 {
706 return $this->api->deleteCustomer($shop_id, $customer_id);
707 }
708
709 /**
710 * Fetch order
711 *
712 * @access public
713 *
714 * @param $shop_id
715 * @param $customer_id
716 *
717 * @return mixed
718 * @since 1.6.0
719 */
720 public function fetchCustomer($shop_id, $customer_id)
721 {
722
723 return $this->api->fetchCustomer($shop_id, $customer_id);
724 }
725
726 /**
727 * Update cart
728 *
729 * @access public
730 *
731 * @param $shop_id
732 * @param $cart_id
733 * @param $checkout_url
734 * @param $cart_total
735 * @param $order_id
736 *
737 * @return mixed
738 * @since 1.6.0
739 */
740 public function updateCart($shop_id, $cart_id, $checkout_url, $cart_total, $order_id)
741 {
742
743 return $this->api->updateCart($shop_id, $cart_id, $checkout_url, $cart_total, $order_id);
744 }
745
746
747 /**
748 * Add cart item
749 *
750 * @access public
751 *
752 * @param $shop_id
753 * @param $cart_id
754 * @param $item
755 *
756 * @return mixed
757 * @since 1.6.0
758 */
759 public function addCartItem($shop_id, $cart_id, $item)
760 {
761
762 return $this->api->addCartItem($shop_id, $cart_id, $item);
763 }
764
765 /**
766 * Replace cart items
767 *
768 * @access public
769 *
770 * @param $shop_id
771 * @param $cart_id
772 * @param $items
773 *
774 * @return mixed
775 * @since 1.6.0
776 */
777 public function replaceCartItems($shop_id, $cart_id, $items)
778 {
779
780 return $this->api->replaceCartItems($shop_id, $cart_id, $items);
781 }
782
783 /**
784 * Get cart items
785 *
786 * @access public
787 *
788 * @param $shop_id
789 * @param $cart_id
790 *
791 * @return mixed
792 * @since 1.6.0
793 */
794 public function getCartItems($shop_id, $cart_id)
795 {
796
797 return $this->api->getCartItems($shop_id, $cart_id);
798 }
799
800 /**
801 * Delete cart items
802 *
803 * @access public
804 *
805 * @param $shop_id
806 * @param $cart_id
807 * @param $item_id
808 *
809 * @return mixed
810 * @since 1.6.0
811 */
812 public function deleteCartItem($shop_id, $cart_id, $item_id)
813 {
814
815 return $this->api->deleteCartItem($shop_id, $cart_id, $item_id);
816 }
817
818 public function batch($requests)
819 {
820 return $this->api->batch($requests);
821 }
822
823 /**
824 * Get raw response body
825 *
826 * @access public
827 * @return string
828 * @since 1.6.0
829 */
830 public function getResponseBody()
831 {
832 return $this->api->getResponseBody();
833 }
834
835 /**
836 * Get response code
837 *
838 * @access public
839 * @return int
840 * @since 1.6.0
841 */
842 public function responseCode()
843 {
844 return $this->api->responseCode();
845 }
846
847 /**
848 * Checks if token is a valid md5 string
849 *
850 * @access private
851 * @return bool
852 * @since 1.6.0
853 */
854 private function isValidClassicKey()
855 {
856
857 return (strlen($this->api_key) < 100);
858 }
859 }