<?php
namespace App\Services;
use App\Models\Order;
use Illuminate\Support\Number;
use App\Events\OrderProcessed;
class OrderProcessor
{
public function formatOrderSummary(Order $order, ?string $userLocale = null)
{
$locale = $userLocale ?? Number::defaultLocale();
$currency = $order->currency ?? Number::defaultCurrency();
return [
'order_number' => $order->reference,
'subtotal' => Number::currency($order->subtotal, in: $currency),
'tax' => Number::currency($order->tax, in: $currency),
'total' => Number::currency($order->total, in: $currency),
'formatted_date' => $order->created_at->locale($locale)->isoFormat('LLLL'),
'meta' => [
'display_locale' => $locale,
'currency' => $currency,
'exchange_rate' => $this->getExchangeRate(
from: Number::defaultCurrency(),
to: $currency
)
]
];
}
protected function getExchangeRate(string $from, string $to): float
{
// Exchange rate calculation logic
return 1.0;
}
}