_config = json_decode(Getter::get('config'), true); } protected function _headers($headers = array()) { return array_merge([ 'Authorization' => 'Bearer ' . null ], $headers); } protected function _client() { $client = new Client([ 'headers' => $this->_headers() ]); return $client; } public function syncOrder($order) { if ($order instanceof \Magento\Sales\Model\Order) { $orderDetail = new Order($order); $shippingAddress = new ShippingAddress($order->getShippingAddress()); $buyer = new Buyer($order); $payload = [ ...$orderDetail->jsonSerialize(), 'url' => $this->_config['url'], 'source' => 'magento', 'details' => [], 'buyer' => $buyer->jsonSerialize(), 'shippingAddress' => $shippingAddress->jsonSerialize(), ]; foreach ($order->getAllVisibleItems() as $item) { $payload['details'][] = (new Detail($item))->jsonSerialize(); } $this->_client()->post($this->_config['url'], [ 'body' => [ "magento_2_" . time() => $payload ] ]); return json_encode($payload); } else { throw new \ErrorException('$order is not instance \Magento\Sales\Model\Order\Interceptor'); return false; } } }