50 lines
1.7 KiB
PHP
50 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Modules\Core\Order\Filament\Extensions;
|
|
|
|
use Filament\Infolists\Components\TextEntry;
|
|
use Lunar\Admin\Support\Extending\ViewPageExtension;
|
|
use Lunar\Models\Order;
|
|
use Modules\Core\Payment\Models\PaymentMethod;
|
|
|
|
/**
|
|
* Adds a "Payment Method" entry to the order summary sidebar — previously
|
|
* nowhere on the order page told staff which payment method a shopper
|
|
* actually used. Reads Order.meta['payment_method'] (written by
|
|
* Modules\Core\Checkout\Services\CheckoutService::initiatePayment()), the
|
|
* same source Modules\Core\Order\Services\OrderStatusFlow::isCod() reads,
|
|
* so this entry and the "Mark Paid" action's visibility always agree on
|
|
* what payment method an order used. Falls back to the most recent
|
|
* Transaction.driver for an order placed before that field existed.
|
|
*
|
|
* Uses the extendOrderSummarySchema hook, same as the deleted 3-axis
|
|
* OrderStatusSummaryExtension did — see that class's git history for the
|
|
* hook's own docblock/rationale.
|
|
*/
|
|
class OrderPaymentMethodSummaryExtension extends ViewPageExtension
|
|
{
|
|
public function extendOrderSummarySchema(array $schema): array
|
|
{
|
|
$schema[] = TextEntry::make('payment_method')
|
|
->label('Payment method')
|
|
->state(fn (Order $record) => $this->resolveLabel($record))
|
|
->placeholder('—')
|
|
->alignEnd();
|
|
|
|
return $schema;
|
|
}
|
|
|
|
private function resolveLabel(Order $record): ?string
|
|
{
|
|
$type = $record->meta['payment_method'] ?? $record->transactions()->latest('id')->value('driver');
|
|
|
|
if ($type === null) {
|
|
return null;
|
|
}
|
|
|
|
$method = PaymentMethod::where('type', $type)->first();
|
|
|
|
return $method?->translate('name') ?? $type;
|
|
}
|
|
}
|