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

[Woo POS] Improve Card Reader Payment Flow Error Handling #12543

Conversation

backwardstruck
Copy link
Contributor

@backwardstruck backwardstruck commented Sep 5, 2024

Closes: #12542

Branched off of this PR from @AnirudhBhat (thanks for the help):
#12569

Description

Addresses an issue with error handling in the card reader payment flow. Ensures that network connectivity is checked before attempting to fetch an order.

Steps to reproduce

  1. Add products and connect reader in POS mode
  2. Ensure the device is in airplane mode.
  3. Attempt to collect payment.
  4. Observe the error message indicating network unavailability.
  5. Disable airplane mode, ensuring the device has an active internet connection.
  6. Attempt to collect payment again.
  7. Observe that the payment flow now proceeds as expected.

Testing information

Devices used:

  • Tablet emualtor

Tested scenarios:

  • Network unavailable (airplane mode).
  • Normal card reader payment flow with network available and order fetch succeeds.

The tests that have been performed

  • Verified normal payment flow with successful order fetch and payment collection.

  • Manual smoke tests on both tablet and phone devices to ensure no regressions were introduced.

  • 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.

@backwardstruck backwardstruck added the type: bug A confirmed bug. label Sep 5, 2024
@backwardstruck backwardstruck added this to the 20.4 milestone Sep 5, 2024
@backwardstruck
Copy link
Contributor Author

@AnirudhBhat this is still in draft because I want to make sure I have the right approach. What do you think about me checking for connection before attempting to fetch the order?

Should I instead watch the connection state throughout the payment process or try to return an error from the order detail repository?

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Sep 5, 2024

📲 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
Commitab4d89a
Direct Downloadwoocommerce-wear-prototype-build-pr12543-ab4d89a.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Sep 5, 2024

📲 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
Commitab4d89a
Direct Downloadwoocommerce-prototype-build-pr12543-ab4d89a.apk

@AnirudhBhat AnirudhBhat self-assigned this Sep 10, 2024
@AnirudhBhat
Copy link
Contributor

AnirudhBhat commented Sep 10, 2024

Thanks for working on this improvement @backwardstruck!

this is still in draft because I want to make sure I have the right approach. What do you think about me checking for connection before attempting to fetch the order?
Should I instead watch the connection state throughout the payment process or try to return an error from the order detail repository?

The approach sounds fine. However, as I understand it, one of the key principles we’ve tried to maintain since the inception of POS is to minimise changes to the existing IPP store management code in order to avoid potential regressions. With that in mind, we could consider the following alternative:

In WooPosTotalsViewModel, we can check the internet connection before initiating the payment process, like this:

private fun collectPayment() {
    if (!wooPosNetworkStatus.isConnected()) {
        viewModelScope.launch {
            childrenToParentEventSender.sendToParent(ChildToParentEvent.NoInternet) // This event is being handled in the WooPosHomeViewModel - PR 12569
        }
    } else {
        val orderId = dataState.value.orderId
        check(orderId != EMPTY_ORDER_ID)
        cardReaderFacade.collectPayment(orderId)
    }
}

I implemented a similar solution while resolving #12497, and you can refer to the relevant code here: #12569. You can merge this changes into your branch and start modifying if you agree with this approach.

This approach allows us to resolve the issue without modifying the existing IPP-related code.

That said, I agree that in the current IPP store management solution, when there is no internet and we try to collect a payment, the "error fetching order" dialog is shown instead of a "No internet" message. However, in store management mode, a persistent offline banner is displayed at the bottom whenever we lose connectivity, giving users an indication of the issue. While I agree that the UI could be improved here, I think that can be addressed in a separate PR.

Screenshot 2024-09-10 at 10 24 19 AM

Let me know your thoughts on this approach!

@backwardstruck backwardstruck force-pushed the 12542-woo-pos-error-message-doesnt-feel-right-when-failing-to-collect-the-payment-due-to-the-lack-of-network branch from 3760f42 to e94d2b9 Compare September 12, 2024 12:14
@backwardstruck backwardstruck changed the base branch from trunk to issue/12497-pos-internet-issue September 12, 2024 12:15
@backwardstruck backwardstruck marked this pull request as ready for review September 12, 2024 16:21
@backwardstruck backwardstruck modified the milestones: 20.4, 20.5 Sep 12, 2024
…ht-when-failing-to-collect-the-payment-due-to-the-lack-of-network
…r-message-doesnt-feel-right-when-failing-to-collect-the-payment-due-to-the-lack-of-network
@codecov-commenter
Copy link

codecov-commenter commented Sep 12, 2024

Codecov Report

Attention: Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.

Project coverage is 40.61%. Comparing base (1c2cc6c) to head (ab4d89a).
Report is 9 commits behind head on trunk.

Files with missing lines Patch % Lines
...oid/ui/woopos/home/totals/WooPosTotalsViewModel.kt 87.50% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##              trunk   #12543   +/-   ##
=========================================
  Coverage     40.61%   40.61%           
- Complexity     5680     5681    +1     
=========================================
  Files          1229     1229           
  Lines         69123    69128    +5     
  Branches       9573     9573           
=========================================
+ Hits          28074    28079    +5     
  Misses        38466    38466           
  Partials       2583     2583           

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

Copy link
Contributor

@AnirudhBhat AnirudhBhat left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @backwardstruck. LGTM! I've added a minor comment regarding the inclusion of a unit test. I'm holding off on merging this since it's based on another PR; we'll proceed once that has been merged.

} else {
val orderId = dataState.value.orderId
check(orderId != EMPTY_ORDER_ID)
cardReaderFacade.collectPayment(orderId)
Copy link
Contributor

Choose a reason for hiding this comment

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

❓ What do you think about adding test to verify that cardReaderFacade.collectPayment is not called when there is no internet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you had suggested that earlier but I failed to add that test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

Base automatically changed from issue/12497-pos-internet-issue to trunk September 13, 2024 07:54
@backwardstruck backwardstruck merged commit 4c6eec7 into trunk Sep 13, 2024
14 checks passed
@backwardstruck backwardstruck deleted the 12542-woo-pos-error-message-doesnt-feel-right-when-failing-to-collect-the-payment-due-to-the-lack-of-network branch September 13, 2024 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Woo POS] Error message doesn’t feel right when failing to collect the payment due to the lack of network
4 participants