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+ }
0 commit comments