Skip to content
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

[POS] Simultaneous cash and card payment handling #13277

Merged
merged 15 commits into from
Jan 15, 2025

Conversation

samiuelson
Copy link
Collaborator

@samiuelson samiuelson commented Jan 9, 2025

Closes: #13278 13278

Description

This PR adds improvements to the cash payment collection flow:

  1. When "Mark payment as complete" is tapped in the Cash payment screen, the card reader payment intent is canceled.
  2. If the card payment is initiated, the Cash payment screen should be interrupted/closed automatically, showing the card payment processing state.

Steps to reproduce

Verify the following on trunk:

Payment intent cancelation
  1. Open POS (menu more > Point of Sale)
  2. Create order and make sure the reader is connected
  3. Click "Cash payment"
  4. Complete order by clicking the button, and observe that card reader payment action is not canceled
Cash payment screen not closed when card payment initiated:
  1. Open POS (menu more > Point of Sale)
  2. Create order and make sure the reader is connected
  3. Click "Cash payment"
  4. Tap card to the reader and observe Cash payment screen is not closed automatically

Testing information

It should be verified that the above scenarios are fixed.

The tests that have been performed

  • Samsung S9 Tab, Android 14
  • Verified that payment intent is canceled properly when order is marked completed (with cash)
  • Verified that Cash payment screen gets closed automatically when user taps card to the reader

Images/gif

  1. Payment intent gets canceled when order marked as paid with cash
Screen_recording_20250109_173942.mp4
  1. Cash payment is closed when card is tapped to the reader
Screen_recording_20250109_173912.mp4
  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on big (tablet) and small (phone) in case of UI changes, and no regressions are added.

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jan 9, 2025

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App Name WooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commitda47b85
Direct Downloadwoocommerce-wear-prototype-build-pr13277-da47b85.apk

@samiuelson samiuelson marked this pull request as ready for review January 10, 2025 08:18
@samiuelson samiuelson requested a review from kidinov January 10, 2025 10:53
@samiuelson samiuelson added this to the 21.5 milestone Jan 10, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jan 10, 2025

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commitda47b85
Direct Downloadwoocommerce-prototype-build-pr13277-da47b85.apk

@codecov-commenter
Copy link

codecov-commenter commented Jan 10, 2025

Codecov Report

Attention: Patch coverage is 22.22222% with 21 lines in your changes missing coverage. Please review.

Project coverage is 41.09%. Comparing base (3222339) to head (da47b85).
Report is 31 commits behind head on trunk.

Files with missing lines Patch % Lines
...ndroid/ui/woopos/root/navigation/WooPosRootHost.kt 0.00% 12 Missing ⚠️
...rce/android/ui/woopos/home/WooPosHomeNavigation.kt 0.00% 5 Missing ⚠️
...oid/ui/woopos/home/totals/WooPosTotalsViewModel.kt 83.33% 0 Missing and 1 partial ⚠️
...d/ui/woopos/root/navigation/WooPosMainFlowGraph.kt 0.00% 1 Missing ⚠️
...ui/woopos/root/navigation/WooPosNavigationEvent.kt 0.00% 1 Missing ⚠️
...os/root/navigation/WooPosNavigationEventHandler.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #13277      +/-   ##
============================================
- Coverage     41.10%   41.09%   -0.01%     
+ Complexity     6421     6420       -1     
============================================
  Files          1321     1321              
  Lines         77177    77200      +23     
  Branches      10643    10650       +7     
============================================
+ Hits          31722    31727       +5     
- Misses        42646    42663      +17     
- Partials       2809     2810       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kidinov kidinov self-assigned this Jan 10, 2025
@@ -49,6 +53,18 @@ fun NavGraphBuilder.cashPaymentScreen(
}
},
) { backStackEntry ->
val homeViewModel = hiltViewModel<WooPosHomeViewModel>()
LaunchedEffect(homeViewModel) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if we need to have this code at all? Don't we handle the event in WooPosHomeScreen already?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LaunchedEffect coroutine in WooPosHomeScreen is not active when we navigate to CashPayment screen. That's why I subscribed to the events in the CashPayment screen here again.

An alternative approach could be to move the subscription to navigation events up in the compose navigation hierarchy, to theWooPosRootHost, in order to avoid duplicate subscriptions – 5f9d68e. Let me know what you think, @kidinov !

is ParentToChildrenEvent.OrderSuccessfullyPaid -> showSuccessfulPaymentState(
event.paymentMethod
)
is ParentToChildrenEvent.OrderSuccessfullyPaid -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking that it's ok that cancelation will be called also in the card reader payments cases

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The flow works correctly, but I switched to canceling payment intent only in case the payment success comes from cash payment to avoid redundant logic – 60ef6e2

@kidinov kidinov self-requested a review January 13, 2025 10:21
Copy link
Contributor

@kidinov kidinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks and works fine! I just left a few code improvements suggestions, please take a look!

@samiuelson
Copy link
Collaborator Author

Looks and works fine! I just left a few code improvements suggestions, please take a look!

Thanks for the review, @kidinov! I've addressed comments and pushed improvements. Let me know what you think.

@samiuelson samiuelson requested a review from kidinov January 14, 2025 17:01
Copy link
Contributor

@kidinov kidinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks and tests good!

@kidinov kidinov merged commit 53e4403 into trunk Jan 15, 2025
15 checks passed
@kidinov kidinov deleted the pos-cash-card-payment-collection-alignment branch January 15, 2025 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Woo POS] Simultaneous cash and card payment handling
4 participants