2026-07-19 03:35:16 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Modules\Core\Payment\Pipelines\Cart;
|
|
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
|
use Lunar\DataTypes\Price;
|
|
|
|
|
use Lunar\Models\Contracts\Cart as CartContract;
|
2026-08-31 13:54:20 +03:00
|
|
|
use Modules\Core\Payment\Models\PaymentMethod;
|
2026-07-19 03:35:16 +03:00
|
|
|
|
|
|
|
|
final class ApplyCashOnDeliveryFee
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Called just before cart totals are calculated.
|
|
|
|
|
*
|
|
|
|
|
* @param Closure(CartContract): mixed $next
|
|
|
|
|
*/
|
|
|
|
|
public function handle(CartContract $cart, Closure $next): mixed
|
|
|
|
|
{
|
|
|
|
|
if (($cart->meta['payment_method'] ?? null) === 'cash-on-delivery') {
|
2026-08-31 13:54:20 +03:00
|
|
|
$fee = (int) (PaymentMethod::where('type', 'cash-on-delivery')->value('data->fee') ?? 0);
|
2026-07-19 03:35:16 +03:00
|
|
|
|
|
|
|
|
$cart->shippingTotal = new Price(
|
|
|
|
|
($cart->shippingTotal?->value ?? 0) + $fee,
|
|
|
|
|
$cart->currency,
|
|
|
|
|
1
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $next($cart);
|
|
|
|
|
}
|
|
|
|
|
}
|