35 lines
1002 B
PHP
35 lines
1002 B
PHP
<?php
|
|||
|
|
|
||
|
|
namespace Modules\Core\Shipping\Carriers\Acs;
|
||
|
|
|
||
|
|
use Illuminate\Support\Facades\Http;
|
||
|
|
|
||
|
|
class AcsClient
|
||
|
|
{
|
||
|
|
public function __construct(private readonly array $config) {}
|
||
|
|
|
||
|
|
public function call(string $alias, array $parameters = []): AcsResponse
|
||
|
|
{
|
||
|
|
$response = Http::withHeaders([
|
||
|
|
'AcsApiKey' => $this->config['api_key'],
|
||
|
|
])
|
||
|
|
->timeout($this->config['timeout'])
|
||
|
|
->post($this->config['base_url'], [
|
||
|
|
'ACSAlias' => $alias,
|
||
|
|
'ACSInputParameters' => array_merge($this->credentialParams(), $parameters),
|
||
|
|
]);
|
||
|
|
|
||
|
|
return AcsResponse::fromHttpResponse($response);
|
||
|
|
}
|
||
|
|
|
||
|
|
private function credentialParams(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'Company_ID' => $this->config['company_id'],
|
||
|
|
'Company_Password' => $this->config['company_password'],
|
||
|
|
'User_ID' => $this->config['user_id'],
|
||
|
|
'User_Password' => $this->config['user_password'],
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|