fixed bug of transaction
This commit is contained in:
@@ -2076,7 +2076,7 @@ class SingleOrderController extends Controller
|
||||
$service = app(ColleagueOrderCallbackService::class);
|
||||
$order = $service->pendingForCustomer((int) auth('customer')->id());
|
||||
if ($order) {
|
||||
$order = $service->refreshIfDue($order);
|
||||
$order = $service->refreshIfDue($order, true);
|
||||
}
|
||||
|
||||
return response()->json($service->publicStatusPayload($order));
|
||||
@@ -2090,7 +2090,8 @@ class SingleOrderController extends Controller
|
||||
->where('customer_id', auth('customer')->id())
|
||||
->first();
|
||||
if ($order) {
|
||||
$order = $service->refreshIfDue($order);
|
||||
// هر بار که کلاینت وضعیت میپرسد، استعلام همکار را اجباری کن
|
||||
$order = $service->refreshIfDue($order, true);
|
||||
}
|
||||
|
||||
return response()->json($service->publicStatusPayload($order));
|
||||
|
||||
@@ -51,13 +51,13 @@ class ColleagueOrderCallbackService
|
||||
return $this->applyProviderSts($order, $sts, $body);
|
||||
}
|
||||
|
||||
public function refreshIfDue(Order $order): Order
|
||||
public function refreshIfDue(Order $order, bool $force = false): Order
|
||||
{
|
||||
if ((int) $order->sts !== 4) {
|
||||
return $order;
|
||||
}
|
||||
|
||||
if (!$this->isPollDue($order)) {
|
||||
if (!$force && !$this->isPollDue($order)) {
|
||||
return $order;
|
||||
}
|
||||
|
||||
@@ -94,9 +94,10 @@ class ColleagueOrderCallbackService
|
||||
return ['ok' => true, 'state' => 'wait'];
|
||||
}
|
||||
|
||||
// جدول سفارش همکار همان sts مدل است (۲ موفق / ۳ ناموفق / ۴ هنوز باز).
|
||||
// کالبک جداست: آنجا ۴ و ۶ یعنی رد.
|
||||
if (in_array($sts, [3, 6], true)) {
|
||||
// جدول سفارش همکار: ۲ موفق / ۳ ناموفق / ۴ هنوز باز.
|
||||
// بعضی پاسخهای تکی/کالبکمانند: ۴ و ۶ = رد.
|
||||
// اگر sts_str هم صریحاً رد/ناموفق باشد، همان را قطعی میگیریم.
|
||||
if ($this->providerBodyLooksRejected($body, $sts)) {
|
||||
return $this->rejectPending($order, $body);
|
||||
}
|
||||
|
||||
@@ -298,7 +299,13 @@ class ColleagueOrderCallbackService
|
||||
*/
|
||||
public function providerStsFromBody(array $body): ?int
|
||||
{
|
||||
$rows = [$body, $body['data'] ?? null, $body['order'] ?? null];
|
||||
// اول ردیف سفارش تودرتو / rows — نه خودِ envelope که گاهی sts کهنه میگذارد
|
||||
$rows = [];
|
||||
foreach ([$body['order'] ?? null, $body['data'] ?? null] as $row) {
|
||||
if (is_array($row)) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
}
|
||||
if (isset($body['rows']) && is_array($body['rows'])) {
|
||||
foreach ($body['rows'] as $row) {
|
||||
if (is_array($row)) {
|
||||
@@ -311,9 +318,14 @@ class ColleagueOrderCallbackService
|
||||
continue;
|
||||
}
|
||||
$rows[] = $item;
|
||||
$rows[] = $item['order'] ?? null;
|
||||
$rows[] = $item['data'] ?? null;
|
||||
if (isset($item['order']) && is_array($item['order'])) {
|
||||
$rows[] = $item['order'];
|
||||
}
|
||||
if (isset($item['data']) && is_array($item['data'])) {
|
||||
$rows[] = $item['data'];
|
||||
}
|
||||
}
|
||||
$rows[] = $body;
|
||||
|
||||
foreach ($rows as $row) {
|
||||
if (!is_array($row) || !array_key_exists('sts', $row) || $row['sts'] === null || $row['sts'] === '') {
|
||||
@@ -326,12 +338,37 @@ class ColleagueOrderCallbackService
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $body
|
||||
*/
|
||||
private function providerBodyLooksRejected(array $body, int $sts): bool
|
||||
{
|
||||
if (in_array($sts, [3, 6], true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$str = mb_strtolower(trim((string) (
|
||||
$body['sts_str']
|
||||
?? $body['order']['sts_str']
|
||||
?? $body['data']['sts_str']
|
||||
?? $body['message']
|
||||
?? ''
|
||||
)));
|
||||
|
||||
if ($str !== '' && preg_match('/رد|ناموفق|reject|fail|cancel|لغو/u', $str)) {
|
||||
// فقط وقتی sts هنوز «باز/در انتظار» نیست که با متن موفق قاطی شود
|
||||
return $sts !== 2;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $body
|
||||
*/
|
||||
private function providerIdFromBody(array $body): int
|
||||
{
|
||||
foreach ([$body, $body['data'] ?? null, $body['order'] ?? null] as $row) {
|
||||
foreach ([$body['order'] ?? null, $body['data'] ?? null, $body] as $row) {
|
||||
if (!is_array($row)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user