Add cash-on-delivery payment type with cart fee pipeline

This commit is contained in:
2026-07-19 03:35:16 +03:00
parent 4c00369005
commit 808c769595
4 changed files with 113 additions and 2 deletions
@@ -0,0 +1,30 @@
<?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);
}
}