M3 Integration fixes

This commit is contained in:
Mark Gregory
2026-09-22 11:08:39 +01:00
parent e4213d1fd6
commit dc97598278
7 changed files with 158 additions and 136 deletions
+36 -24
View File
@@ -22,32 +22,44 @@ class ReplenAPI extends Controller
$context = $this->requestContext($request);
try {
if ($context['params'] === []) {
return $this->missingParametersResponse($context);
}
$this->logRequest($context);
$tokenResponse = Helper::checkReceiveTokenV2();
$tokenData = $tokenResponse->getData();
if ((string) ($tokenData->code ?? '') !== '200') {
$this->log($context, (string) ($tokenData->message ?? ''), 'X', 'M3-Res-out');
return $tokenResponse;
}
$result = $this->fetchInventory($context, (string) ($tokenData->token ?? ''));
if ($result['error'] !== '') {
$this->log($context, $result['status'] . '-' . $result['error'] . $result['session'], 'X', 'M3-Res-out');
return response()->json(['code' => '405', 'status' => 'error', 'message' => $result['error']]);
}
$this->log($context, $result['status'] . '-' . $result['json'] . $result['session'], '', 'M3-Res-out');
$rows = $this->flattenInventory($result['result']);
$this->replaceInventory($context, $rows);
return response()->json(['code' => '200', 'status' => 'Success']);
$response = $this->processInventoryRequest($context);
} catch (\Throwable $throwable) {
return $this->exceptionResponse($context, $throwable);
$response = $this->exceptionResponse($context, $throwable);
}
return $response;
}
private function processInventoryRequest(array $context)
{
if ($context['params'] === []) {
return $this->missingParametersResponse($context);
}
$this->logRequest($context);
$tokenResponse = Helper::checkReceiveTokenV2();
$tokenData = $tokenResponse->getData();
if ((string) ($tokenData->code ?? '') !== '200') {
$this->log($context, (string) ($tokenData->message ?? ''), 'X', 'M3-Res-out');
return $tokenResponse;
}
return $this->inventoryResponse($context, (string) ($tokenData->token ?? ''));
}
private function inventoryResponse(array $context, string $token)
{
$result = $this->fetchInventory($context, $token);
if ($result['error'] !== '') {
$this->log($context, $result['status'] . '-' . $result['error'] . $result['session'], 'X', 'M3-Res-out');
return response()->json(['code' => '405', 'status' => 'error', 'message' => $result['error']]);
}
$this->log($context, $result['status'] . '-' . $result['json'] . $result['session'], '', 'M3-Res-out');
$rows = $this->flattenInventory($result['result']);
$this->replaceInventory($context, $rows);
return response()->json(['code' => '200', 'status' => 'Success']);
}
private function configureTimeouts(): void