@php $lines = $payment->items->map(function ($row) { return $row->assistedPurchaseRequest; })->filter()->values(); $primaryRequest = $lines->firstWhere('id', $payment->assisted_purchase_request_id) ?: $lines->first(); $pathway = strtolower((string) ($payment->pathway ?: '')); $payStatus = strtolower((string) $payment->payment_status); $isPaid = in_array($payStatus, ['success', 'completed'], true); $isFailed = !$isPaid && $pathway === 'a' && in_array($payStatus, ['failed', 'cancelled', 'canceled'], true); $bankRecorded = $pathway === 'c' && $payment->bank_transactionID; $trackingStatus = optional($payment->tracking)->status ?: $payment->status; if ($isFailed) { $statusLabel = 'Failed'; $statusClass = 'is-fail'; } elseif ($isPaid || $bankRecorded) { $statusLabel = $bankRecorded && !$isPaid ? 'Recorded' : 'Completed'; $statusClass = 'is-done'; } else { $statusLabel = 'Pending'; $statusClass = 'is-pending'; } if ($trackingStatus && !$isFailed) { $statusLabel = $trackingStatus; $statusClass = $trackingStatus === 'Customer Paid' ? 'is-done' : 'is-pending'; } $warehouseMarked = $pathway === 'c' && $payment->trackingHistory->contains(function ($row) { return $row->status === 'Customer Paid' && $row->wuser_id; }); if ($pathway === 'c' && $statusLabel === 'Customer Paid' && !$warehouseMarked) { $statusLabel = 'Transaction Successful'; } $storeIcons = $lines->map(function ($line) { $path = trim((string) $line->store_icon); if ($path === '') { $path = \App\Support\AssistedStoreIcon::match($line->url)['path']; } return [ 'store' => trim((string) $line->store) ?: 'Store', 'icon' => asset($path), ]; })->unique('store')->values(); $pathwayNames = ['a' => 'Card Gateway', 'b' => 'Maldives Post Link', 'c' => 'Cash / Bank Transfer']; $methodLabel = isset($pathwayNames[$pathway]) ? 'Payment method - Pathway '.strtoupper($pathway).': '.$pathwayNames[$pathway] : ''; $suiteNumber = $payment->suite_number ?: optional($primaryRequest)->suite_number; $suiteAddress = $payment->virtualAddress; if (!$suiteAddress && $suiteNumber && isset($deliverySuites)) { $suiteAddress = $deliverySuites->firstWhere('suite_number', $suiteNumber); } $suiteBadges = $suiteAddress ? $suiteAddress->deliveryBadges() : null; $purchaseCount = max($lines->count(), 1); $currencyCode = strtoupper((string) ($payment->currency ?: 'INR')); $currencyMark = ['INR' => '₹', 'USD' => '$', 'MVR' => 'Rf'][$currencyCode] ?? $currencyCode; $money = $payment->selectedMoney(); $payableAmount = $money['total']; @endphp