44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?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,
|
|
];
|
|
}
|
|
}
|