62 lines
1.3 KiB
PHP
Executable File
62 lines
1.3 KiB
PHP
Executable File
<?php
|
|
|
|
namespace IpSupply\SyncOrder\Api;
|
|
|
|
use IpSupply\SyncOrder\Api\RepositoryInterface;
|
|
|
|
/**
|
|
* @api
|
|
*/
|
|
class Repository implements RepositoryInterface
|
|
{
|
|
function __construct()
|
|
{
|
|
$this->_authorization();
|
|
}
|
|
|
|
private function _authorization()
|
|
{
|
|
$headers = apache_request_headers();
|
|
$apiKey = \IpSupply\SyncOrder\Helper::API_KEY;
|
|
|
|
foreach ($headers as $key => $value) {
|
|
$key = strtolower($key);
|
|
if ('api-key' === $key && $value === $apiKey) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
header('HTTP/1.1 401 Unauthorized');
|
|
header('Accept: application/json');
|
|
header('Content-Type: application/json');
|
|
die(json_encode(['message' => 'unauthorized']));
|
|
}
|
|
|
|
public function getData()
|
|
{
|
|
return \IpSupply\SyncOrder\Helper::responseOk([
|
|
'status' => true,
|
|
'data' => []
|
|
]);
|
|
}
|
|
|
|
public function postData()
|
|
{
|
|
parse_str(
|
|
string: file_get_contents('php://input'),
|
|
result: $payload,
|
|
);
|
|
|
|
unset($payload['form_key']);
|
|
|
|
\IpSupply\SyncOrder\Config\Setter::set(
|
|
path: 'config',
|
|
value: json_encode($payload),
|
|
);
|
|
|
|
return \IpSupply\SyncOrder\Helper::responseOk([
|
|
'status' => true,
|
|
]);
|
|
}
|
|
}
|