fix(checkout): apply new payment method fee immediately on selection - #138
Open
obinnaelviso wants to merge 1 commit into
Open
fix(checkout): apply new payment method fee immediately on selection#138obinnaelviso wants to merge 1 commit into
obinnaelviso wants to merge 1 commit into
Conversation
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.
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes checkout recalculation so switching payment methods immediately applies (or removes) the payment fee without requiring a full refresh, and ensures the persisted order_total matches the cart total after conditions are applied.
Changes:
- Refresh
PaymentFee’s resolvedPaymentmodel when the selected payment code changes within the same request. - Reset
CartConditioninternal state (passed/calculatedValue) whenbeforeApply()opts out to prevent stale “applied” state. - Recompute
OrderManager’sorder_totalafter applying the current payment fee condition.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Classes/OrderManager.php | Applies payment fee before assigning order_total so the stored total stays in sync with the selected payment method. |
| src/CartConditions/PaymentFee.php | Refetches the Payment model when metadata code changes to avoid stale fee calculations. |
| src/CartCondition.php | Clears stale condition state when beforeApply() returns false, preventing lingering applied/value data. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Switching payment methods during checkout didn't apply the new method's fee until the page was fully refreshed, and a previously-applied fee could linger after switching to a method with no fee.
Root causes:
PaymentFee::beforeApply()cached the resolvedPaymentmodel on first use and never refreshed it when the selected code changed within the same request.CartCondition::apply()leftpassed/calculatedValuestale whenbeforeApply()opted out, so a previously-applied condition kept reporting itself as applied with its old value.OrderManager::applyRequiredAttributes()computedorder_totalbefore the fee condition was applied, so the stored total could be out of sync with the selected payment method.Fix
Paymentmodel whenever the metadata code changes, not just when it's null.passed/calculatedValuewhen a condition opts out viabeforeApply(), so stale state doesn't persist.order_totalafter the fee condition is applied.Existing test suite passes (
vendor/bin/pest), includingPaymentFeeTest,CartConditionTest,CartTest, andOrderManagerTest.