Skip to content

Commit 3fe918f

Browse files
authored
Merge pull request #18 from mailerlite/develop
Develop
2 parents 2bae0aa + c04baaf commit 3fe918f

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/Api/WooCommerce.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
4+
namespace MailerLiteApi\Api;
5+
6+
use MailerLiteApi\Common\ApiAbstract;
7+
8+
class WooCommerce extends ApiAbstract
9+
{
10+
protected $endpoint = 'woocommerce';
11+
/**
12+
* Sends shop data to our api to be saved(or updated) in the db
13+
*/
14+
public function setConsumerData( $consumerKey, $consumerSecret, $store, $apiKey, $currency )
15+
{
16+
17+
$endpoint = $this->endpoint . '/consumer_data';
18+
19+
$params = array_merge($this->prepareParams(), ['consumer_key' => $consumerKey, 'consumer_secret' => $consumerSecret, 'store' => $store, 'api_key' => $apiKey, 'currency' => $currency] );
20+
21+
$response = $this->restClient->post( $endpoint, $params );
22+
23+
return $response['body'];
24+
}
25+
/**
26+
* Currenty not in use as this is meant to save webhooks for created and updated orders
27+
* however, now we're instead listening for the event in the plugin so no need for webhooks
28+
*/
29+
public function setWebhooks($shop)
30+
{
31+
$endpoint = $this->endpoint.'/webhooks';
32+
33+
$params = array_merge($this->prepareParams(), ['shop' => $shop] );
34+
35+
return $this->restClient->post( $endpoint, $params );
36+
}
37+
/**
38+
* Sends the completed order data to the api
39+
*/
40+
public function saveOrder($orderData, $shop)
41+
{
42+
$endpoint = 'woocommerce/alternative_save_order';
43+
44+
$params = array_merge($this->prepareParams(), ['order_data' => $orderData, 'shop' => $shop] );
45+
46+
return $this->restClient->post( $endpoint, $params );
47+
}
48+
/**
49+
* Calls api endpoint that will toggle shop's active state
50+
* in our db
51+
*/
52+
public function toggleShopConnection($shop, $activeState)
53+
{
54+
$shopName = parse_url($shop, PHP_URL_HOST);
55+
$endpoint = 'woocommerce/toggle_shop_connection';
56+
57+
$params = array_merge($this->prepareParams(), ['active_state' => $activeState, 'shop' => $shopName] );
58+
return $this->restClient->post( $endpoint, $params );
59+
}
60+
}

src/MailerLite.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ public function settings()
8989
return new \MailerLiteApi\Api\Settings($this->restClient);
9090
}
9191

92+
public function woocommerce()
93+
{
94+
return new \MailerLiteApi\Api\WooCommerce($this->restClient);
95+
}
96+
9297
/**
9398
* @return \MailerLiteApi\Api\Segments
9499
*/

0 commit comments

Comments
 (0)