89255687a1
ACS rate driver (live price quotes via ACS_Price_Calculation, cached postcode-to-station lookups) and fulfillment service (voucher creation, label printing, end-of-day pickup manifest). Adds a per-rate pricing_mode column so admins can choose live API pricing vs. a fixed price on ACS-driven shipping rates, surfaced via a custom Rates page.
44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\Core\Shipping\Carriers\Acs;
|
|
|
|
use Illuminate\Http\Client\Response;
|
|
use Modules\Core\Shipping\Carriers\Acs\Exceptions\AcsApiException;
|
|
|
|
class AcsResponse
|
|
{
|
|
private function __construct(
|
|
public readonly bool $hasError,
|
|
public readonly ?string $errorMessage,
|
|
public readonly array $valueOutput,
|
|
public readonly array $tableOutput,
|
|
) {}
|
|
|
|
public static function fromHttpResponse(Response $response): self
|
|
{
|
|
$body = $response->json() ?? [];
|
|
|
|
// ACS's own JSON key is misspelled ("Responce") — preserved here verbatim.
|
|
$output = $body['ACSOutputResponce'] ?? [];
|
|
|
|
return new self(
|
|
hasError: (bool) ($body['ACSExecution_HasError'] ?? ! $response->successful()),
|
|
errorMessage: $body['ACSExecutionErrorMessage'] ?? null,
|
|
valueOutput: $output['ACSValueOutput'][0] ?? [],
|
|
tableOutput: $output['ACSTableOutput'] ?? [],
|
|
);
|
|
}
|
|
|
|
public function throwIfError(): self
|
|
{
|
|
if ($this->hasError) {
|
|
throw new AcsApiException(
|
|
$this->errorMessage ?? ($this->valueOutput['Error_Message'] ?? 'Unknown ACS API error'),
|
|
$this->tableOutput,
|
|
);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|