31 lines
765 B
PHP
31 lines
765 B
PHP
<?php
|
|||
|
|
|
||
|
|
namespace Modules\Core\Payment\Pipelines\Cart;
|
||
|
|
|
||
|
|
use Closure;
|
||
|
|
use Lunar\DataTypes\Price;
|
||
|
|
use Lunar\Models\Contracts\Cart as CartContract;
|
||
|
|
|
||
|
|
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') {
|
||
|
|
$fee = (int) config('lunar.payments.types.cash-on-delivery.fee', 0);
|
||
|
|
|
||
|
|
$cart->shippingTotal = new Price(
|
||
|
|
($cart->shippingTotal?->value ?? 0) + $fee,
|
||
|
|
$cart->currency,
|
||
|
|
1
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
return $next($cart);
|
||
|
|
}
|
||
|
|
}
|