From 6bfa13bb3bb801d9a44c8fc8d8ee2f1f79b36a77 Mon Sep 17 00:00:00 2001 From: Obinna Elvis Okechukwu Date: Mon, 3 Aug 2026 06:16:54 -0500 Subject: [PATCH] fix(checkout): apply new payment method fee immediately on selection The payment fee cart condition cached the resolved Payment model on first use and never refreshed it, so switching payment methods mid checkout kept using the previously selected method's fee until a full page reload. It also left a condition's passed/calculatedValue state stale once beforeApply() opted out, so a previously applied fee stuck around after switching to a method with no fee. Order totals were persisted before the fee was applied, so the stored order_total could be out of sync with the selected payment method. --- src/CartCondition.php | 3 +++ src/CartConditions/PaymentFee.php | 2 +- src/Classes/OrderManager.php | 5 +++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/CartCondition.php b/src/CartCondition.php index e2d89e10..61cec7c7 100644 --- a/src/CartCondition.php +++ b/src/CartCondition.php @@ -107,6 +107,9 @@ public function isInclusive() public function apply($subTotal) { if ($this->beforeApply() === false) { + $this->passed = false; + $this->calculatedValue = 0; + return $subTotal; } diff --git a/src/CartConditions/PaymentFee.php b/src/CartConditions/PaymentFee.php index d4ec9b8a..0eb1b08d 100644 --- a/src/CartConditions/PaymentFee.php +++ b/src/CartConditions/PaymentFee.php @@ -32,7 +32,7 @@ public function beforeApply(): ?bool return false; } - if (is_null($this->paymentModel)) { + if (is_null($this->paymentModel) || $this->paymentModel->code !== $paymentCode) { $this->paymentModel = Payment::whereCode($paymentCode)->first(); } diff --git a/src/Classes/OrderManager.php b/src/Classes/OrderManager.php index da8d710c..9e9e4244 100644 --- a/src/Classes/OrderManager.php +++ b/src/Classes/OrderManager.php @@ -288,13 +288,14 @@ public function applyRequiredAttributes($order): void $order->total_items = $this->cart->count(); $order->cart = $this->cart->content(); - $order->order_total = $this->cart->total(); $paymentCode = $this->getCurrentPaymentCode(); - $order->payment = $order->order_total > 0 ? $paymentCode : ''; + $order->payment = $this->cart->total() > 0 ? $paymentCode : ''; $this->applyCurrentPaymentFee($order->payment); + $order->order_total = $this->cart->total(); + $order->ip_address = Request::getClientIp(); }