.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
فرمت هر خط:
|
||||
- YYYY-MM-DD | موضوع | مسیر فایل(ها) | نکتهٔ ۱ خطی
|
||||
|
||||
- 2026-11-02 | PDF وبسرویس شایگان | `docs/shayegan/shayegan.pdf` صفحه ارسال حساب | نمونهٔ رسمی `AccountNumber` نمیفرستد؛ `MoinNumber` + `UpdateKind=0` + `AccountTypeId=1`. فرمول `12101530` در PDF نیست
|
||||
- 2026-11-02 | دیباگ تبادل شایگان | `ShayeganClient::request` + `registerCustomer` / health / retry | پاسخ ادمین `client_request` و `server_response` دارد؛ رمز DB و Auth برابر `***`
|
||||
- 2026-11-02 | سه سطح شایگان | `ShayeganSyncService::registerCustomer` + migration `2026_11_02_000001` | کل 121، معین `12101`، تفصیلی = معین+کد کاربری (`12101530`). `1210101` غلط است
|
||||
- 2026-11-01 | پیامک تبدیل | `CopperConvertRequestService::notifyCustomer` | بعد از تأیید یا رد، پیامک جدا به موبایل مشتری؛ خطا پیامک سفارش را برنمیگرداند
|
||||
- 2026-11-01 | درخواست تبدیل مس | `CopperConvertRequestService` + `copper_convert_requests` + `POST customer/copper-convert-request` + `admin/copper-convert-request/{id}/approve` | تأیید = فروش دارایی و خرید حلقه با quote_unit_price؛ مهاجرت `2026_11_01_000001`
|
||||
|
||||
@@ -28,14 +28,13 @@ class ShayeganController extends Controller
|
||||
$result = $this->client->healthCheck();
|
||||
$status = ! empty($result['ok']) ? 200 : 422;
|
||||
|
||||
return response()->json([
|
||||
return response()->json(array_merge([
|
||||
'ok' => ! empty($result['ok']),
|
||||
'message' => $result['message'] ?? null,
|
||||
'http_status' => $result['http_status'] ?? null,
|
||||
'timeout' => ! empty($result['timeout']),
|
||||
// never echo Config passwords
|
||||
'body' => $this->sanitizeBodyForAdmin($result['body'] ?? null),
|
||||
], $status);
|
||||
], $this->client->debugExchange($result)), $status);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,13 +135,14 @@ class ShayeganController extends Controller
|
||||
}
|
||||
|
||||
$result = $this->client->put($endpoint, $put);
|
||||
$exchange = $this->client->debugExchange($result);
|
||||
if (! empty($result['timeout'])) {
|
||||
$row->sync_status = ShayeganSyncService::STATUS_TIMEOUT;
|
||||
$row->sync_log = (string) ($result['message'] ?? 'timeout');
|
||||
$row->res = json_encode(['timeout' => true], JSON_UNESCAPED_UNICODE);
|
||||
$row->save();
|
||||
|
||||
return response()->json(['ok' => false, 'message' => 'timeout', 'row' => $row], 422);
|
||||
return response()->json(array_merge(['ok' => false, 'message' => 'timeout', 'row' => $row], $exchange), 422);
|
||||
}
|
||||
|
||||
if (! empty($result['ok'])) {
|
||||
@@ -153,7 +153,7 @@ class ShayeganController extends Controller
|
||||
$row->res = json_encode($result['body'] ?? [], JSON_UNESCAPED_UNICODE);
|
||||
$row->save();
|
||||
|
||||
return response()->json(['ok' => true, 'row' => $row]);
|
||||
return response()->json(array_merge(['ok' => true, 'row' => $row], $exchange));
|
||||
}
|
||||
|
||||
$row->sync_status = ShayeganSyncService::STATUS_FAILED;
|
||||
@@ -161,7 +161,7 @@ class ShayeganController extends Controller
|
||||
$row->res = json_encode($result['body'] ?? [], JSON_UNESCAPED_UNICODE);
|
||||
$row->save();
|
||||
|
||||
return response()->json(['ok' => false, 'message' => $row->sync_log, 'row' => $row], 422);
|
||||
return response()->json(array_merge(['ok' => false, 'message' => $row->sync_log, 'row' => $row], $exchange), 422);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -125,12 +125,19 @@ class ShayeganClient
|
||||
$url = $this->endpointUrl($endpoint, $query);
|
||||
$timeout = max(5, $this->config->getInt('shayegan_timeout_seconds', 30));
|
||||
|
||||
$clientRequest = [
|
||||
'endpoint' => $endpoint,
|
||||
'url' => $url,
|
||||
'query' => $query,
|
||||
'payload' => $this->redactPayload($payload),
|
||||
];
|
||||
|
||||
$this->logTraffic('request', [
|
||||
'style' => $style,
|
||||
'endpoint' => $endpoint,
|
||||
'url' => $url,
|
||||
'timeout_seconds' => $timeout,
|
||||
'payload' => $this->redactPayload($payload),
|
||||
'payload' => $clientRequest['payload'],
|
||||
]);
|
||||
|
||||
try {
|
||||
@@ -147,13 +154,14 @@ class ShayeganClient
|
||||
}
|
||||
|
||||
$error = $this->extractErrorMessage($json);
|
||||
$serverResponse = $this->serverResponse($status, $error !== '' ? $error : 'OK', $json);
|
||||
if ($status >= 400) {
|
||||
$result = [
|
||||
$result = $this->withExchange([
|
||||
'ok' => false,
|
||||
'message' => $error !== '' ? $error : ('HTTP ' . $status),
|
||||
'http_status' => $status,
|
||||
'body' => $json,
|
||||
];
|
||||
], $clientRequest, $serverResponse);
|
||||
$this->logTraffic('response', [
|
||||
'style' => $style,
|
||||
'endpoint' => $endpoint,
|
||||
@@ -168,12 +176,12 @@ class ShayeganClient
|
||||
}
|
||||
|
||||
if ($error !== '') {
|
||||
$result = [
|
||||
$result = $this->withExchange([
|
||||
'ok' => false,
|
||||
'message' => $error,
|
||||
'http_status' => $status,
|
||||
'body' => $json,
|
||||
];
|
||||
], $clientRequest, $serverResponse);
|
||||
$this->logTraffic('response', [
|
||||
'style' => $style,
|
||||
'endpoint' => $endpoint,
|
||||
@@ -187,12 +195,12 @@ class ShayeganClient
|
||||
return $result;
|
||||
}
|
||||
|
||||
$result = [
|
||||
$result = $this->withExchange([
|
||||
'ok' => true,
|
||||
'message' => 'OK',
|
||||
'http_status' => $status,
|
||||
'body' => $json,
|
||||
];
|
||||
], $clientRequest, $serverResponse);
|
||||
$this->logTraffic('response', [
|
||||
'style' => $style,
|
||||
'endpoint' => $endpoint,
|
||||
@@ -213,13 +221,13 @@ class ShayeganClient
|
||||
'payload' => $this->redactPayload($payload),
|
||||
]);
|
||||
|
||||
return [
|
||||
return $this->withExchange([
|
||||
'ok' => false,
|
||||
'message' => 'timeout/connection: ' . $e->getMessage(),
|
||||
'http_status' => null,
|
||||
'body' => null,
|
||||
'timeout' => true,
|
||||
];
|
||||
], $clientRequest, $this->serverResponse(null, 'timeout/connection: ' . $e->getMessage(), null));
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('shayegan.request_failed', [
|
||||
'endpoint' => $endpoint,
|
||||
@@ -229,15 +237,58 @@ class ShayeganClient
|
||||
'payload' => $this->redactPayload($payload),
|
||||
]);
|
||||
|
||||
return [
|
||||
return $this->withExchange([
|
||||
'ok' => false,
|
||||
'message' => $e->getMessage(),
|
||||
'http_status' => null,
|
||||
'body' => null,
|
||||
];
|
||||
], $clientRequest, $this->serverResponse(null, $e->getMessage(), null));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $result
|
||||
* @return array{client_request:mixed,server_response:mixed}
|
||||
*/
|
||||
public function debugExchange(array $result): array
|
||||
{
|
||||
return [
|
||||
'client_request' => $result['client_request'] ?? null,
|
||||
'server_response' => $result['server_response'] ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $result
|
||||
* @param array<string, mixed> $clientRequest
|
||||
* @param array<string, mixed> $serverResponse
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function withExchange(array $result, array $clientRequest, array $serverResponse): array
|
||||
{
|
||||
$result['client_request'] = $clientRequest;
|
||||
$result['server_response'] = $serverResponse;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $body
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function serverResponse(?int $status, ?string $message, $body): array
|
||||
{
|
||||
$response = [
|
||||
'message' => $message,
|
||||
'http_status' => $status,
|
||||
];
|
||||
if (is_array($body)) {
|
||||
$response['body'] = $body;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, int|string> $query
|
||||
*/
|
||||
|
||||
@@ -138,16 +138,20 @@ class ShayeganSyncService
|
||||
|
||||
$result = $this->client->put('Account/Put', $put);
|
||||
$accountNumber = trim((string) ($result['number'] ?? ''));
|
||||
$exchange = $this->client->debugExchange($result);
|
||||
|
||||
if (! empty($result['timeout'])) {
|
||||
return ['ok' => false, 'message' => (string) ($result['message'] ?? 'timeout')];
|
||||
return array_merge([
|
||||
'ok' => false,
|
||||
'message' => (string) ($result['message'] ?? 'timeout'),
|
||||
], $exchange);
|
||||
}
|
||||
|
||||
if (empty($result['ok']) || $accountNumber === '') {
|
||||
return [
|
||||
return array_merge([
|
||||
'ok' => false,
|
||||
'message' => (string) ($result['message'] ?? 'ثبت حساب مشتری در شایگان ناموفق بود'),
|
||||
];
|
||||
], $exchange);
|
||||
}
|
||||
|
||||
$customer->moshtari_code = $accountNumber;
|
||||
@@ -174,11 +178,11 @@ class ShayeganSyncService
|
||||
$row->res = json_encode($result['body'] ?? [], JSON_UNESCAPED_UNICODE);
|
||||
$row->save();
|
||||
|
||||
return [
|
||||
return array_merge([
|
||||
'ok' => true,
|
||||
'message' => 'حساب تفصیلی مشتری در شایگان ایجاد شد',
|
||||
'moshtari_code' => $accountNumber,
|
||||
];
|
||||
], $exchange);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user