shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

etsy.php (2011B)


      1 <?php
      2 class ControllerExtensionOpenbayEtsy extends Controller {
      3 	public function inbound() {
      4 		if ($this->config->get('etsy_status') != '1') {
      5 			$this->openbay->etsy->log('etsy/inbound - module inactive (503)');
      6 			http_response_code(503);
      7 			exit();
      8 		}
      9 
     10 		$body = $this->request->post;
     11 
     12 		if (!isset($body['action']) || !isset($body['auth'])) {
     13 			$this->openbay->etsy->log('etsy/inbound - action or auth data not set (401)');
     14 			http_response_code(401);
     15 			exit();
     16 		}
     17 
     18 		$incoming_token = isset($body['auth']['token']) ? $body['auth']['token'] : '';
     19 
     20 		if (!hash_equals($this->config->get('etsy_token'), $incoming_token)) {
     21 			$this->openbay->etsy->log('etsy/inbound - Auth failed (401): ' . $incoming_token);
     22 			http_response_code(401);
     23 			exit();
     24 		}
     25 
     26 		$data = array();
     27 
     28 		if (isset($body['data']) && !empty($body['data'])) {
     29             $decrypted = $this->openbay->decrypt($body['data'], $this->openbay->etsy->getEncryptionKey(), $this->openbay->etsy->getEncryptionIv());
     30 
     31 			if (!$decrypted) {
     32 				$this->openbay->etsy->log('etsy/inbound Failed to decrypt data');
     33 				http_response_code(400);
     34 				exit();
     35 			}
     36 
     37 			$data = json_decode($decrypted);
     38 		}
     39 
     40 		switch ($body['action']) {
     41 			case 'orders':
     42 				$this->load->model('extension/openbay/etsy_order');
     43 
     44 				$this->openbay->etsy->log('Orders action found');
     45 
     46 				$this->model_extension_openbay_etsy_order->inbound($data);
     47 
     48 				break;
     49 			case 'products';
     50 				$this->load->model('extension/openbay/etsy_product');
     51 
     52 				$this->model_extension_openbay_etsy_product->inbound($data);
     53 
     54 				break;
     55 		}
     56 	}
     57 
     58 	public function eventAddOrderHistory($route, $data) {
     59 		$this->openbay->etsy->log('eventAddOrderHistory Event fired: ' . $route);
     60 
     61 		if (isset($data[0]) && !empty($data[0])) {
     62 			$this->load->model('extension/openbay/etsy_order');
     63 
     64 			$this->openbay->etsy->log('Order ID: ' . (int)$data[0]);
     65 
     66 			$this->model_extension_openbay_etsy_order->addOrderHistory((int)$data[0]);
     67 		}
     68 	}
     69 }