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][Design System] Reimplement 0.5 width for 4 payment error views #15249

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from

Conversation

jaclync
Copy link
Contributor

@jaclync jaclync commented Feb 25, 2025

Part of #15235

Description

This pull request updates the layout of 4 payment error message views to match the latest design so that CTAs have 0.5 of the container width. It was attempted before, but reverted because the container was often capped to a width that is not filling the available space.

Localization and Message Updates:

  • Removed the nextStep property and combined its message into the message property in PointOfSaleCardPresentPaymentCaptureErrorMessageViewModel (WooCommerce/Classes/POS/Presentation/Card Present Payments/Reader Messages/PointOfSaleCardPresentPaymentCaptureErrorMessageViewModel.swift). [1] [2] [3]

UI Layout Adjustments:

  • Adjusted the frame width and alignment for various error message views to ensure consistent spacing and alignment:
    • PointOfSaleCardPresentPaymentCaptureErrorMessageView (WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSaleCardPresentPaymentCaptureErrorMessageView.swift). [1] [2]
    • PointOfSaleCardPresentPaymentErrorMessageView (WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSaleCardPresentPaymentErrorMessageView.swift). [1] [2] [3]
    • PointOfSaleCardPresentPaymentIntentCreationErrorMessageView (WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSaleCardPresentPaymentIntentCreationErrorMessageView.swift).
    • PointOfSaleCardPresentPaymentNonRetryableErrorMessageView (WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSaleCardPresentPaymentNonRetryableErrorMessageView.swift). [1] [2]

Payment Layout Adjustments:

  • Updated the layout for the paymentError state in TotalsView to remove additional padding (WooCommerce/Classes/POS/Presentation/TotalsView.swift).
  • Modified TotalsViewHelper to remove additional padding for the paymentError state (WooCommerce/Classes/POS/ViewHelpers/TotalsViewHelper.swift).

Steps to reproduce

Not all errors are easily reproducible. Retryable and non-retryable payment errors are the easiest to repro, please feel free to share repro steps for the "capture error" and "payment intent creation" error.

  • Prerequisite: the store has a product eligible for POS with an invalid price in Stripe
  • Enter POS
  • Add the product in the prerequisite to cart, check out
  • Tap Connect your reader in the totals view
  • After reader is connected, tap test card to pay --> the non-retryable error view should be shown that shows the error message
  • Restart POS
  • Add item(s) to cart and check out
  • Turn off network connection
  • Tap test card to pay --> the retryable error view should be shown that shows the error message

Testing information

Feel free to also test other error cases by replacing the implementation of

func present(viewModel eventDetails: CardPresentPaymentEventDetails) {

to send the specific error, and test it by connecting the reader in the totals view after adding item(s) to cart and checking out. For example, to repro the "capture error" state:

paymentEventSubject.send(.show(
    eventDetails: .paymentCaptureError(cancelPayment: { [weak self] in })
))

Screenshots

PointOfSaleCardPresentPaymentIntentCreationErrorMessageView

PointOfSaleCardPresentPaymentCaptureErrorMessageView

PointOfSaleCardPresentPaymentNonRetryableErrorMessageView

PointOfSaleCardPresentPaymentErrorMessageView


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

Summary by CodeRabbit

  • Refactor

    • Streamlined payment error messages by removing redundant instructions. The revised messages now offer clear guidance for troubleshooting issues during transactions, helping users navigate errors more easily.
  • Style

    • Improved interface layout with enhanced spacing, width, and padding adjustments across error notifications and payment views. These changes provide a more adaptive and consistent user experience on various devices.

…nd string to enable 0.5 width with external padding removed.
…ard coded max width to enable 0.5 width for CTAs.
@jaclync jaclync added type: task An internally driven task. feature: POS labels Feb 25, 2025
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Feb 25, 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 Numberpr15249-2bf7c2a
Version21.8
Bundle IDcom.automattic.alpha.woocommerce
Commit2bf7c2a
App Center BuildWooCommerce - Prototype Builds #13159
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@jaclync jaclync marked this pull request as ready for review February 25, 2025 08:20
@jaclync jaclync added this to the 21.9 milestone Feb 25, 2025
@jaclync jaclync requested a review from joshheald February 25, 2025 08:24
@jaclync
Copy link
Contributor Author

jaclync commented Feb 25, 2025

@coderabbitai review

@joshheald
Copy link
Contributor

@jaclync in your screenshots, the PointOfSaleCardPresentPaymentNonRetryableErrorMessageView has full-width message text, while PointOfSaleCardPresentPaymentCaptureErrorMessageView and PointOfSaleCardPresentPaymentErrorMessageView only allow the same width as the buttons take up – is that deliberate?

Copy link

coderabbitai bot commented Feb 26, 2025

Walkthrough

The update removes the redundant nextStep property and refines error message localization in the payment capture error view model. Multiple UI components for displaying error messages were simplified by removing nested elements, adding spacing, and adjusting frame constraints to use half-width and infinite maximum dimensions. The layout for payment error in the TotalsView was updated to remove extra padding, and the TotalsViewHelper logic was modified to account for payment errors. Additionally, the constant for error content width was removed and unit tests were updated accordingly.

Changes

File(s) Change Summary
.../PointOfSaleCardPresentPaymentCaptureErrorMessageViewModel.swift Removed nextStep property and its equality check; updated localization key and message details.
.../PointOfSaleCardPresentPaymentCaptureErrorMessageView.swift, .../PointOfSaleCardPresentPaymentErrorMessageView.swift, .../PointOfSaleCardPresentPaymentNonRetryableErrorMessageView.swift Simplified UI layouts: removed nested VStack for next step text; added Spacer() elements; updated frame modifiers to use width * 0.5 and maxWidth/maxHeight: .infinity.
.../PointOfSaleCardPresentPaymentIntentCreationErrorMessageView.swift Added frame modifier for setting a fixed (width * 0.5) on the button container; changed outer frame constraint to .infinity.
.../PointOfSaleCardPresentPaymentLayout.swift Removed static constant errorContentMaxWidth.
.../TotalsView.swift, .../TotalsViewHelper.swift In TotalsView, replaced the .topAligned layout with a PaymentViewLayout instance that applies no padding; updated TotalsViewHelper’s shouldApplyPadding method to return false for .card(.paymentError).
.../PointOfSaleCardPresentPaymentCaptureErrorMessageViewModelTests.swift Updated the expected property count in the equatable test from 7 to 6.

Sequence Diagram(s)

sequenceDiagram
    participant PaymentProcess
    participant ErrorVM as Error ViewModel
    participant ErrorView as Error Message View
    participant TotalsHelper as TotalsViewHelper
    participant TotalsView as Totals View

    PaymentProcess->>ErrorVM: Capture payment error
    ErrorVM-->>ErrorView: Provide updated error message (no nextStep)
    ErrorView->>UI: Render error layout (fixed width, spacers, max dimensions)
    TotalsView->>TotalsHelper: shouldApplyPadding(.card(.paymentError))
    TotalsHelper-->>TotalsView: Return false (no extra padding)
    TotalsView->>UI: Render Payment Error Layout with PaymentViewLayout
Loading

Poem

I'm a code rabbit, hopping through the lines,
Removing extra steps and making layouts fine.
Fields and spacers now lead the dance,
With messages clear, there's no second chance.
In a burrow of logic, where clean code beams,
I nibble on bugs and dream delightful dreams.
Happy hops in every commit!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 430e2a5 and 2bf7c2a.

📒 Files selected for processing (9)
  • WooCommerce/Classes/POS/Presentation/Card Present Payments/Reader Messages/PointOfSaleCardPresentPaymentCaptureErrorMessageViewModel.swift (1 hunks)
  • WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSaleCardPresentPaymentCaptureErrorMessageView.swift (2 hunks)
  • WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSaleCardPresentPaymentErrorMessageView.swift (3 hunks)
  • WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSaleCardPresentPaymentIntentCreationErrorMessageView.swift (1 hunks)
  • WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSaleCardPresentPaymentLayout.swift (0 hunks)
  • WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSaleCardPresentPaymentNonRetryableErrorMessageView.swift (2 hunks)
  • WooCommerce/Classes/POS/Presentation/TotalsView.swift (1 hunks)
  • WooCommerce/Classes/POS/ViewHelpers/TotalsViewHelper.swift (1 hunks)
  • WooCommerce/WooCommerceTests/POS/Card Present Payments/PointOfSaleCardPresentPaymentCaptureErrorMessageViewModelTests.swift (1 hunks)
💤 Files with no reviewable changes (1)
  • WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSaleCardPresentPaymentLayout.swift
🔇 Additional comments (20)
WooCommerce/WooCommerceTests/POS/Card Present Payments/PointOfSaleCardPresentPaymentCaptureErrorMessageViewModelTests.swift (1)

8-8: Test update looks good.

The change to expected property count from 7 to 6 aligns with the removal of the nextStep property from the PointOfSaleCardPresentPaymentCaptureErrorMessageViewModel as mentioned in the PR objectives.

WooCommerce/Classes/POS/ViewHelpers/TotalsViewHelper.swift (1)

70-70: Correctly extended the padding condition.

Adding .card(.paymentError) to the cases where padding should not be applied aligns with the layout updates for error views mentioned in the PR objectives. This ensures consistent treatment of the payment error state.

WooCommerce/Classes/POS/Presentation/TotalsView.swift (1)

326-329: Consistent padding updates for error views.

The changes align with the updated padding logic in TotalsViewHelper and ensure the error view layout uses no padding, which will help properly position the CTA buttons as mentioned in the PR objectives.

WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSaleCardPresentPaymentNonRetryableErrorMessageView.swift (5)

11-12: Improved vertical spacing.

Adding a spacer at the beginning of the VStack improves the vertical distribution of elements in the error view.


34-34: Fixed message width to match PR requirements.

Setting the VStack width to half the container width ensures the message text will be properly constrained, aligning with the 0.5 width requirement mentioned in the PR objectives.


42-43: Fixed button width to match PR requirements.

Setting the button width to half the container width (0.5) matches exactly what was requested in the PR objectives.


44-45: Improved bottom spacing.

Adding a spacer at the end of the VStack improves vertical distribution and ensures proper spacing below the button.


47-47: Enhanced layout flexibility.

Changing from a fixed maximum width to .infinity allows the view to better utilize available space, addressing the container width issue mentioned in the PR objectives.

WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSaleCardPresentPaymentErrorMessageView.swift (5)

11-12: Well-balanced vertical spacing added

Adding this Spacer at the top of the view creates better vertical balance in the layout, which helps center the content properly in the available space.


31-31: Good implementation of 0.5 width constraint

Setting the text width to half of the container width aligns with the design specs mentioned in the PR objectives. This ensures the message has a consistent width across all error views.


47-48: Consistent button width implementation

The buttons now match the same width constraint as the text content above (0.5 of container width), creating visual harmony in the layout.


49-49: Added bottom spacing for balanced layout

This additional Spacer at the bottom creates proper vertical balance, ensuring the content is centered appropriately in the container.


52-52: Flexible container constraints applied

Replacing the fixed max width with .infinity allows the view to properly expand and utilize the available space, fixing the issue mentioned in the PR objectives.

WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSaleCardPresentPaymentCaptureErrorMessageView.swift (4)

29-32: Simplified message display

The code now uses a single Text view for the message instead of a nested structure, which simplifies the implementation while maintaining the necessary styling and animation effects.


34-34: Implemented 0.5 width constraint for text

Setting the text width to half of the container width aligns with the design specifications and creates a consistent layout with other error message views.


49-49: Consistent button width implementation

The buttons now use the same 0.5 width constraint as the text content, creating a cohesive layout that aligns with the design requirements.


52-52: Flexible container constraints applied

Replacing the fixed max width with .infinity allows the view to better utilize the available space, addressing the container width issue mentioned in the PR objectives.

WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSaleCardPresentPaymentIntentCreationErrorMessageView.swift (2)

44-44: Implemented 0.5 width constraint for buttons

Setting the button container to half of the available width creates consistency with the other error message views and aligns with the design requirements.


47-47: Flexible container constraints applied

Replacing the fixed max width with .infinity allows the view to better utilize the available space, matching the changes made to other error message views.

WooCommerce/Classes/POS/Presentation/Card Present Payments/Reader Messages/PointOfSaleCardPresentPaymentCaptureErrorMessageViewModel.swift (1)

47-50: Improved error message guidance

The updated message now provides comprehensive instructions that consolidate what was previously split between the message and nextStep properties. This change simplifies the view model while enhancing the user guidance.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jaclync
Copy link
Contributor Author

jaclync commented Feb 26, 2025

@jaclync in your screenshots, the PointOfSaleCardPresentPaymentNonRetryableErrorMessageView has full-width message text, while PointOfSaleCardPresentPaymentCaptureErrorMessageView and PointOfSaleCardPresentPaymentErrorMessageView only allow the same width as the buttons take up – is that deliberate?

In the largest font size in shorter tablets like iPad mini, the error message text views can get tall with 0.5 width:

larger font size disabled largest font size

However, after some thinking this is an edge case and the CTA is still tappable it might be better going with UI/UX consistency. I updated the text container in the non-retryable error view to be 0.5 width in 2bf7c2a. Feel free to share other thoughts!

@joshheald
Copy link
Contributor

please feel free to share repro steps for the "capture error" and "payment intent creation" error.

For payment intent creation:

  1. Set up Charles or Proxyman
  2. Add a breakpoint on https://api.stripe.com/v1/payment_intents
  3. Attempt to take a payment
  4. Abort the request when you hit the breakpoint

Note that when you do this, the Terminal SDK has some heuristic that means it starts saying you're not connected to the internet when you retry. If you wait a couple of minutes, it'll work again. I don't think this will happen so consistently for real reproductions.

For the capture error, see the instructions in #13642

Copy link
Contributor

@joshheald joshheald 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 for the changes.

Re: larger dynamic text sizes... as they increase, the design starts to look very unbalanced when it's all constrained to 50% width, and it doesn't make the best use of space.

I think we should increase the percentage width we use as the dynamic type size increases. This could just be "go direct to 100% when we hit accessibility2" or something like that – use your best judgement 😊

@@ -323,7 +323,10 @@ private extension TotalsView {
case .validatingOrderError:
return .outlined
case .paymentError:
return .topAligned
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove the topAligned definition if we're not using it here. Or update it to match this new one.

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