88class WooCommerce extends ApiAbstract
99{
1010 protected $ endpoint = 'woocommerce ' ;
11- /**
12- * Sends shop data to our api to be saved(or updated) in the db
13- */
11+
1412 public function setConsumerData ( $ consumerKey , $ consumerSecret , $ store , $ apiKey , $ currency )
1513 {
1614
@@ -19,13 +17,10 @@ public function setConsumerData( $consumerKey, $consumerSecret, $store, $apiKey,
1917 $ params = array_merge ($ this ->prepareParams (), ['consumer_key ' => $ consumerKey , 'consumer_secret ' => $ consumerSecret , 'store ' => $ store , 'api_key ' => $ apiKey , 'currency ' => $ currency ] );
2018
2119 $ response = $ this ->restClient ->post ( $ endpoint , $ params );
22-
20+
2321 return $ response ['body ' ];
2422 }
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- */
23+
2924 public function setWebhooks ($ shop )
3025 {
3126 $ endpoint = $ this ->endpoint .'/webhooks ' ;
@@ -34,21 +29,15 @@ public function setWebhooks($shop)
3429
3530 return $ this ->restClient ->post ( $ endpoint , $ params );
3631 }
37- /**
38- * Sends the completed order data to the api
39- */
32+
4033 public function saveOrder ($ orderData , $ shop )
4134 {
4235 $ endpoint = 'woocommerce/alternative_save_order ' ;
4336
4437 $ params = array_merge ($ this ->prepareParams (), ['order_data ' => $ orderData , 'shop ' => $ shop ] );
45-
4638 return $ this ->restClient ->post ( $ endpoint , $ params );
4739 }
48- /**
49- * Calls api endpoint that will toggle shop's active state
50- * in our db
51- */
40+
5241 public function toggleShopConnection ($ shop , $ activeState )
5342 {
5443 $ shopName = parse_url ($ shop , PHP_URL_HOST );
@@ -57,4 +46,33 @@ public function toggleShopConnection($shop, $activeState)
5746 $ params = array_merge ($ this ->prepareParams (), ['active_state ' => $ activeState , 'shop ' => $ shopName ] );
5847 return $ this ->restClient ->post ( $ endpoint , $ params );
5948 }
49+
50+ public function sendCartData ($ shopUrl , $ cartData ) {
51+ $ endpoint = 'woocommerce/save_cart ' ;
52+
53+ $ params = array_merge ($ this ->prepareParams (), ['cart_data ' => $ cartData , 'shop ' => $ shopUrl ] );
54+ return $ this ->restClient ->post ( $ endpoint , $ params );
55+ }
56+
57+ public function sendSubscriberData ($ data ) {
58+ $ endpoint = 'woocommerce/save_subscriber ' ;
59+
60+ $ params = array_merge ($ this ->prepareParams (), ['data ' =>$ data ] );
61+ $ response = $ this ->restClient ->post ( $ endpoint , $ params );
62+
63+ if (isset ($ response ['body ' ])){
64+ return $ response ['body ' ];
65+ } else {
66+ return false ;
67+ }
68+ }
69+
70+ public function sendOrderProcessingData ($ data ) {
71+ $ endpoint = 'woocommerce/order_processing ' ;
72+
73+ $ params = array_merge ($ this ->prepareParams (), ['data ' =>$ data ] );
74+ $ this ->restClient ->post ( $ endpoint , $ params );
75+
76+ return true ;
77+ }
6078}
0 commit comments