Feature: Add ACS courier integration
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.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user