Refactor code structure for improved readability and maintainability

This commit is contained in:
baodev0
2026-08-10 08:37:52 +07:00
parent d6d63e5152
commit e3d3dea8aa
31 changed files with 290 additions and 319 deletions
@@ -0,0 +1,43 @@
<?php
namespace App\Http\Resources\Api\Service\Order;
use App\Models\Invoice;
trait ResolvesPaymentMethod
{
/** invoice.payment_method holds a code (balance/credit/transfer/...), not always a Payment row id. */
private const METHOD_LABELS = [
'balance' => 'Số dư tài khoản',
'credit' => 'Số dư tài khoản',
'transfer' => 'Chuyển khoản ngân hàng',
'vnpay' => 'VNPay',
'momo' => 'Momo',
'bank_transfer' => 'Chuyển khoản ngân hàng',
'admin' => 'Xác nhận thủ công',
];
private function resolvePaymentMethod(Invoice $invoice): ?array
{
$method = $invoice->payment_method;
if (! $method) {
return null;
}
if (ctype_digit((string) $method) && $invoice->payment) {
return [
'code' => null,
'name' => $invoice->payment->name,
'bank_name' => $invoice->payment->bankName,
'logo' => $invoice->payment->logo,
];
}
return [
'code' => $method,
'name' => self::METHOD_LABELS[$method] ?? $method,
'bank_name' => null,
'logo' => null,
];
}
}