-
Notifications
You must be signed in to change notification settings - Fork 121
POS cash payment: prefill order amount and update analytics tracking #16058
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
Changes from 3 commits
363e0b0
7119219
004b624
f149da7
0dff142
7c576c0
15e4a27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,12 @@ struct PointOfSaleCollectCashView: View { | |
| String.localizedStringWithFormat(Localization.backNavigationSubtitle, orderTotal) | ||
| } | ||
|
|
||
| private var isButtonEnabled: Bool { | ||
| viewHelper.isPaymentButtonEnabled(orderTotal: orderTotal, | ||
| textFieldAmountInput: textFieldAmountInput, | ||
| isLoading: isLoading) | ||
| } | ||
|
|
||
| @StateObject private var textFieldViewModel = FormattableAmountTextFieldViewModel(size: .extraLarge, | ||
| locale: Locale.autoupdatingCurrent, | ||
| storeCurrencySettings: ServiceLocator.currencySettings, | ||
|
|
@@ -89,7 +95,7 @@ struct PointOfSaleCollectCashView: View { | |
| .buttonStyle(POSFilledButtonStyle(size: .normal, isLoading: isLoading)) | ||
| .frame(maxWidth: .infinity) | ||
| .dynamicTypeSize(...DynamicTypeSize.accessibility1) | ||
| .disabled(isLoading) | ||
| .disabled(!isButtonEnabled) | ||
| } | ||
| .padding([.horizontal]) | ||
| .padding(.bottom, max(keyboardFrame.height - geometry.safeAreaInsets.bottom, | ||
|
|
@@ -110,6 +116,9 @@ struct PointOfSaleCollectCashView: View { | |
| } | ||
| } | ||
| .frame(maxWidth: .infinity, maxHeight: .infinity) | ||
| .onAppear { | ||
| prefillOrderTotal() | ||
| } | ||
| } | ||
|
|
||
| private func markComplete() async throws { | ||
|
|
@@ -121,9 +130,7 @@ struct PointOfSaleCollectCashView: View { | |
|
|
||
| private extension PointOfSaleCollectCashView { | ||
| private func submitCashAmount() async { | ||
| guard validateAmountOnSubmit() else { | ||
| return | ||
| } | ||
| ServiceLocator.analytics.track(.pointOfSaleCashPaymentTapped) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessarily for this PR, but I wonder if we should expose the analytics prop in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When reviewing Povilas' POS modularization PRs in the last HACK Week, he updated all the ServiceLocator analytics usage with an
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'll bring some of these things to the trunk, without the POS module itself, so it could be used within the code now. |
||
| isLoading = true | ||
| do { | ||
| try await markComplete() | ||
|
|
@@ -140,14 +147,12 @@ private extension PointOfSaleCollectCashView { | |
| textFieldAmountInput: textFieldAmountInput) | ||
| } | ||
|
|
||
| private func validateAmountOnSubmit() -> Bool { | ||
| viewHelper.validateAmountOnSubmit( | ||
| orderTotal: orderTotal, | ||
| textFieldAmountInput: textFieldAmountInput, | ||
| onError: { error in | ||
| errorMessage = error | ||
| }) | ||
| private func prefillOrderTotal() { | ||
| if let orderDecimal = viewHelper.parseCurrency(orderTotal) { | ||
| textFieldViewModel.presetAmount(orderDecimal) | ||
| } | ||
| isTextFieldFocused = true | ||
| } | ||
| } | ||
|
|
||
| private extension PointOfSaleCollectCashView { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,25 +54,17 @@ final class CollectCashViewHelper { | |
| } | ||
| } | ||
|
|
||
| func validateAmountOnSubmit(orderTotal: String, | ||
| func isPaymentButtonEnabled(orderTotal: String, | ||
| textFieldAmountInput: String, | ||
| onError: (String) -> Void) -> Bool { | ||
| let userInput = textFieldAmountInput.isNotEmpty ? textFieldAmountInput : "0" | ||
|
|
||
| isLoading: Bool) -> Bool { | ||
| guard let orderDecimal = parseCurrency(orderTotal), | ||
| let inputDecimal = parseCurrency(userInput) else { | ||
| onError(Localization.failedToCollectCashPayment) | ||
| return false | ||
| } | ||
|
|
||
| if inputDecimal < orderDecimal { | ||
| onError(Localization.cashPaymentAmountNotEnough) | ||
| let inputDecimal = parseCurrency(textFieldAmountInput.isNotEmpty ? textFieldAmountInput : "0") else { | ||
| return false | ||
| } | ||
| return true | ||
| return inputDecimal >= orderDecimal && !isLoading | ||
|
||
| } | ||
|
|
||
| private func parseCurrency(_ amountString: String) -> Decimal? { | ||
| func parseCurrency(_ amountString: String) -> Decimal? { | ||
| // Removes all leading/trailing whitespace, if any | ||
| let sanitized = amountString.trimmingCharacters(in: .whitespacesAndNewlines) | ||
|
|
||
|
|
@@ -101,16 +93,6 @@ private extension CollectCashViewHelper { | |
| comment: "Change due when the cash amount entered exceeds the order total." + | ||
| "Reads as 'Change due: $1.23'" | ||
| ) | ||
| static let failedToCollectCashPayment = NSLocalizedString( | ||
| "collectcashviewhelper.failedtocollectcashpayment.errormessage", | ||
| value: "Error trying to process payment. Try again.", | ||
| comment: "Error message when the system fails to collect a cash payment." | ||
| ) | ||
| static let cashPaymentAmountNotEnough = NSLocalizedString( | ||
| "collectcashviewhelper.cashpaymentamountnotenough.errormessage", | ||
| value: "Amount must be more or equal to total.", | ||
| comment: "Error message when the cash amount entered is less than the order total." | ||
| ) | ||
| } | ||
| } | ||
|
|
||
|
|
||
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 updating this file and testing the cash payment, we could also update the warnings for iOS17 in lines 65 and 108 regarding
onChangedeprecation 👍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.
Good catch, fixed in 0dff142. Hopefully we can reset build warnings to 0 and new warnings are detected in CI in the near future.
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.
Btw @iamgabrielma while checking your PR #16002 from the latest merge conflicts, the release notes entry seemed to get into 23.1 instead of 23.2. Not sure what impact it has though, maybe just for Peacock beta testing.
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.
Oh, appreciated, I did move them here then it seems messed it up when merging trunk into the branch. Thanks, I'll address it 🙇