magento2-docker/app/code/IpSupply/SyncOrder/Sync/Index.php

50 lines
1.1 KiB
PHP

<?php
namespace IpSupply\SyncOrder\Sync;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request as GuzzRequest;
use IpSupply\SyncOrder\Config\Getter;
final class Index
{
protected $_config;
function __construct()
{
$this->_config = Getter::get('config');
}
protected function _headers($headers = array())
{
return array_merge([
'Authorization' => 'Bearer ' . ''
], $headers);
}
protected function _client() {
$client = new Client([
'headers' => $this->_headers(),
'base_url' => $this->_config['url'],
]);
return $client;
}
public function syncOrder($order): bool
{
if ($order instanceof \Magento\Sales\Model\Order\Interceptor) {
$payload = [
'url' => $this->_config['url'],
'source' => 'magento',
...(new Order($order))->jsonSerialize()
];
return true;
} else {
throw new \ErrorException('$order is not instance \Magento\Sales\Model\Order\Interceptor');
return false;
}
}
}