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