-
Notifications
You must be signed in to change notification settings - Fork 117
[Woo POS] Make cash payment events independent from card payment events #15769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
[Woo POS] Make cash payment events independent from card payment events #15769
Conversation
Turn cash and card relationship from OR (enum) to AND (struct), allowing them to co-exist together. Keeping both cash and card payment state in a single variable can cause occasional issues when card payment event unexpectedly arrives and changes the state while cash payment was in progress.
Generated by 🚫 Danger |
…ndent-from-card-payment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors PointOfSalePaymentState
from an enum into a struct with separate card
and cash
states, adds an activePaymentMethod
helper, and updates all dependent helpers, views, models, mocks, and tests accordingly.
- Replace
PointOfSalePaymentState
enum with a struct containingcard
andcash
properties - Introduce
activePaymentMethod
and route logic in helpers/views through it - Update aggregate model, mocks, and tests to initialize and compare the new struct state
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
WooCommerceTests/POS/ViewHelpers/TotalsViewHelperTests.swift | Updated tests to wrap card state in new struct initializer |
WooCommerceTests/POS/ViewHelpers/CartViewHelperTests.swift | Updated tests to initialize PointOfSalePaymentState(card:…) |
WooCommerceTests/POS/Models/PointOfSaleAggregateModelTests.swift | Adjusted expected state comparisons to new struct with card and cash |
WooCommerceTests/POS/Mocks/MockPointOfSaleAggregateModel.swift | Changed mock default paymentState to use empty PointOfSalePaymentState() |
Classes/POS/ViewHelpers/TotalsViewHelper.swift | Switched helper logic to use activePaymentMethod and separate .card and .cash branches |
Classes/POS/ViewHelpers/CartViewHelper.swift | Updated guard to reference paymentState.card and moved allowsCartEditing into PointOfSaleCardPaymentState |
Classes/POS/Presentation/TotalsView.swift | Rewrote UI switches to branch on activePaymentMethod and nested card /cash states |
Classes/POS/Presentation/PointOfSaleDashboardView.swift | Updated background environment binding to check .card state only |
Classes/POS/Presentation/POSFloatingControlView.swift | Changed disabling to use paymentState.card |
Classes/POS/Models/PointOfSalePaymentState.swift | Converted enum to struct, added activePaymentMethod , moved initializers |
Classes/POS/Models/PointOfSaleAggregateModel.swift | Adjusted default initializer, state mutations for card vs. cash events |
Comments suppressed due to low confidence (2)
WooCommerce/WooCommerceTests/POS/ViewHelpers/CartViewHelperTests.swift:12
- Add tests for
shouldPreventCartEditing
whenpaymentState.cash
is.collectingCash
and.paymentSuccess
to ensure cart editing is correctly prevented for cash payment scenarios.
#expect(sut.shouldPreventCartEditing(orderState: .syncing,
WooCommerce/Classes/POS/ViewHelpers/TotalsViewHelper.swift:4
- Consider adding tests for cash payment states to
shouldShowTotalsFields
, verifying it returnsfalse
forcash
states like.collectingCash
and.paymentSuccess
.
func shouldShowTotalsFields(for paymentState: PointOfSalePaymentState) -> Bool {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looking good! I left a couple of non-blocking comments.
Allow me a couple of hours to test this on a card reader before approving, I have a bad internet today and updating the firmware is taking forever! Edit: Done!
@@ -177,7 +177,7 @@ extension PointOfSaleAggregateModel { | |||
|
|||
private func setStateForEditing() { | |||
orderStage = .building | |||
paymentState = .card(.idle) | |||
paymentState = PointOfSalePaymentState() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question:
Should we remove the .idle
states as default params when we initialize a PointOfSalePaymentState
instance? While it makes sense in this function, being able to instantiate it without having to explicitly pass any initial values could make us mistakenly override current payment state if we call it in the wrong place, and reset the payment state to .idle when it shouldn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessarily for this PR but I wonder if there's a benefit of making TotalsViewHelper
just hold static functions rather than instance functions, it's currently stateless and has no dependencies, we're not mocking anything specific, and doesn't need to conform to anything. (same case for CartViewHelper
)
The question comes from seeing it initialized in each test, rather than the actual number of real allocations when the app runs, so it seems trivial either way, but happy to hear you thoughts in general about these 👍
@@ -80,7 +80,7 @@ struct PointOfSaleDashboardView: View { | |||
.environment(\.floatingControlAreaSize, | |||
CGSizeMake(floatingSize.width + Constants.floatingControlHorizontalOffset, | |||
floatingSize.height + Constants.floatingControlVerticalOffset)) | |||
.environment(\.posBackgroundAppearance, posModel.paymentState != .card(.processingPayment) ? .primary : .secondary) | |||
.environment(\.posBackgroundAppearance, posModel.paymentState.card != .processingPayment ? .primary : .secondary) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're already updating this let's extract the bg color:
private var backgroundAppearance: POSBackgroundAppearanceKey.Appearance {
posModel.paymentState.card != .processingPayment ? .primary : .secondary
}
WOOMOB-120
Description
Keeping
paymentState
enum
in a single variable can introduce unwanted issues. For example, having.collectCash
state active when a latercard
payment event arrives and changes a view state.The solution is to switch from
enum'to
struct` when managing a payment state. It allows changing card and cash states without affecting the overall payment state by mistake:PointOfSalePaymentState
as structactivePaymentMethod
variable that could be used for clarity within viewspaymentState.cash
orpaymentState.card
Steps to reproduce
These changes shouldn't change the behavior. Verify:
Testing information
Tested on:
Screenshots
cash.payment.events.MP4
RELEASE-NOTES.txt
if necessary.