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] [Cash & Receipts] Validate cash amount #14811

Open
wants to merge 4 commits into
base: task/14602-handle-cash-payment-success
Choose a base branch
from

Conversation

iamgabrielma
Copy link
Contributor

@iamgabrielma iamgabrielma commented Jan 7, 2025

Closes: #14749
#14602 must be merged first

Description

This PR adds validation to the cash amount entered by a merchant during the cash collection flow.

  • If the amount is not enough, does not show any message until we press the "collect" button, at which point an error message (red) will appear
  • If the amount is exact, we can collect normally
  • If the amount exceeds the order total, a "change due" (green) message will be shown each time we change the input.
Screen.Recording.2025-01-07.at.19.19.53.mov

Testing

  • Enable .acceptCashForPointOfSale feature flag
  • In POS, add items to the cart, then tap on "Cash Payment"
  • Enter an amount less, equal, and exceeding the order total. Observe that responds as in the description
  • Using . or , for decimals should behave the same.
  • Upon completion, the order appears in the app under the Orders tab.

You will see some additional space at the bottom of the success view, as well as the floating button to connect the reader. This is unrelated to this PR and will be addressed in the parent PR (#14602) or in a follow-up


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

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 all devices (phone/tablet) and no regressions are added.

@iamgabrielma iamgabrielma added type: task An internally driven task. feature: POS labels Jan 7, 2025
@iamgabrielma iamgabrielma added this to the 21.4 milestone Jan 7, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jan 7, 2025

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

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr14811-1339f75
Version21.3
Bundle IDcom.automattic.alpha.woocommerce
Commit1339f75
App Center BuildWooCommerce - Prototype Builds #12385
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@@ -112,6 +117,46 @@ struct PointOfSaleCollectCashView: View {
}
}

private extension PointOfSaleCollectCashView {
func parseCurrency(_ amountString: String) -> NSDecimalNumber? {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've attempted to implement this from zero using Decimal but dealing with currency was anything but fun, so I've relied on our own CurrencyFormatter implementation. That said we seem to carry our own downsides (eg: #13829 ) so I'm not sure if there's a better way we could use to handle formatting here, since we use the same currency formatter in other places in POS 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, understandable. It's okay to use what we currently have. We can make improvements internally within the formatters.

The largest issues I've seen were when converting amounts back and forth when creating and then editing Order fields again. It's not the case with this POS cash payment so it should be fine.

@iamgabrielma iamgabrielma marked this pull request as ready for review January 7, 2025 12:33
@iamgabrielma iamgabrielma requested a review from staskus January 7, 2025 12:33
Copy link
Collaborator

@staskus staskus left a comment

Choose a reason for hiding this comment

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

Works well, thanks!

I suggest moving cash calculations into a separate helper and to write unit tests.

@@ -112,6 +117,46 @@ struct PointOfSaleCollectCashView: View {
}
}

private extension PointOfSaleCollectCashView {
func parseCurrency(_ amountString: String) -> NSDecimalNumber? {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, understandable. It's okay to use what we currently have. We can make improvements internally within the formatters.

The largest issues I've seen were when converting amounts back and forth when creating and then editing Order fields again. It's not the case with this POS cash payment so it should be fine.

currencyFormatter.convertToDecimal(amountString, locale: .current)
}

private func formatAsCurrency(_ amount: NSDecimalNumber) -> String {
Copy link
Collaborator

Choose a reason for hiding this comment

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

All these methods could be unit tested (with mocked currency formatter). We have calculations happening within them. These methods would likely need to change into pure functions within a helper and then View would just set appropriate labels based on the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: POS type: task An internally driven task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants