Skip to content

Conversation

@staskus
Copy link
Contributor

@staskus staskus commented Mar 25, 2025

Closes: #15403

Description

Show an error and CTA to proceed without Coupons.

Solution

  • Updating orderState error set in PointOfSaleOrderController to be more versatile and allow expansion to specific error cases
  • Added invalidCoupon error state
  • Created CouponError to distinguish coupon errors both for self-hosted and Dotcom logins
  • Created PointOfSaleOrderSyncCouponsErrorMessageView with dummy UI and ability to remove coupons before retrying order creation
  • PointOfSaleOrderSyncCouponsErrorMessageView parses HTML error since sometimes coupons errors arrive with HTML tags

Steps to reproduce

Before testing, update addToCart method in PointOfSaleAggregateModel to add an invalid coupon with an item, for example:

    func addToCart(_ item: POSItem) {
        trackCustomerInteractionStarted()
        cart.add(POSItem.coupon(.init(id: UUID(), code: "10_invalid")))
        cart.add(item)
    }

Test with both Dotcom and Self-hosted login:

  1. Log in with dotcom account
  2. Open POS
  3. Add an item and an invalid coupon
  4. Check out
  5. Confirm the error appears with an error message from the backend
  6. Tap "Proceed without coupons"
  7. Confirm the order is succesfully created

Testing information

  • Test with Dotcom login
  • Test with Self-hosted login

Screenshots

Simulator.Screen.Recording.-.iPad.Air.11-inch.M2.-.2025-03-25.at.15.46.47.mp4

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

staskus added 5 commits March 25, 2025 16:31
With this commit the functionality doesn't change - PointOfSaleOrderSyncErrorMessageView is presented with an error that is returned by the API. However, now we can distinguish between coupon and other errors.
Show PointOfSaleOrderSyncCouponsErrorMessageView when invalidCoupons error happens during Order creation.

Remove coupons from cart before retrying.
@staskus staskus added type: task An internally driven task. feature: POS labels Mar 25, 2025
@staskus staskus requested a review from iamgabrielma March 25, 2025 14:43
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Mar 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 Numberpr15420-6376ff7
Version22.0
Bundle IDcom.automattic.alpha.woocommerce
Commit6376ff7
App Center BuildWooCommerce - Prototype Builds #13421
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

Base automatically changed from task/15331-woo-pos-send-coupons-in-order-creation-request to trunk March 25, 2025 14:53
@iamgabrielma iamgabrielma added this to the 22.1 milestone Mar 26, 2025
@iamgabrielma iamgabrielma self-assigned this Mar 26, 2025
Copy link
Contributor

@iamgabrielma iamgabrielma left a comment

Choose a reason for hiding this comment

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

Works great! 🚢

Self-hosted

🔵 Tracked pos_order_creation_failed, properties: [error_description: The operation couldn’t be completed. (Networking.NetworkError error 2.), was_ecommerce_trial: false, plan: , site_url: https://indiemelon.mystagingwebsite.com, blog_id: -1, store_id: c5bd46cc-1804-4f7b-badb-bb98c449127f, is_wpcom_store: false, error_context: Sorry, there was an issue with the server. Please try again later. (Error code: 400). Response: {"code":"woocommerce_rest_invalid_coupon","message":"Coupon \"invalid_coupon\" does not exist!","data":{"status":400}}, use_gift_card: false]

Then:

🔵 Tracked pos_order_creation_success, properties: [store_id: c5bd46cc-1804-4f7b-badb-bb98c449127f, was_ecommerce_trial: false, is_wpcom_store: false, plan: , site_url: https://indiemelon.mystagingwebsite.com, blog_id: -1]

Dotcom:

🔵 Tracked pos_order_creation_failed, properties: [site_url: https://indiemelon.mystagingwebsite.com, use_gift_card: false, is_wpcom_store: false, error_description: The operation couldn’t be completed. (Networking.DotcomError error 0.), blog_id: 215063064, error_context: Dotcom Error: [woocommerce_rest_invalid_coupon] Coupon "invalid_coupon" does not exist!, plan: jetpack_security_daily, store_id: c5bd46cc-1804-4f7b-badb-bb98c449127f, was_ecommerce_trial: false]

then 

🔵 Tracked pos_order_creation_success, properties: [was_ecommerce_trial: false, blog_id: 215063064, is_wpcom_store: false, store_id: c5bd46cc-1804-4f7b-badb-bb98c449127f, plan: jetpack_security_daily, site_url: https://indiemelon.mystagingwebsite.com]

data: data,
options: [.documentType: NSAttributedString.DocumentType.html],
documentAttributes: nil) {
var attributedString = AttributedString(nsAttributedString)
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL we can also attempt to parse this to markdown via try AttributedString(markdown: message) (need to import Foundation). Maybe would be cleaner than using NSAttributedString, or we could keep both as a fallback if the initial decoding fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I'll try 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, it doesn't parse through all the HTML tags. I tried different options but it didn't work.

Comment on lines 67 to 83
// MARK: - TODO when copy is finalized
//
//private extension PointOfSaleOrderSyncErrorMessageView {
// enum Localization {
// static let title = NSLocalizedString(
// "pointOfSale.orderSync.couponsError.title",
// value: "Invalid coupons",
// comment: "Title of the error when failing to validate coupons and calculate order totals"
// )
//
// static let actionTitle = NSLocalizedString(
// "pointOfSale.orderSync.couponsError.proceed",
// value: "Continue without coupons",
// comment: "Button title to remove coupons and retry synchronizing order and calculating order totals"
// )
// }
//}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a follow-up somewhere and a link here so we don't forget :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Okay, I will. All these PRs are with dummy UI so we'll need to do a second round to create a proper look,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@staskus staskus changed the title [Woo POS] Coupons: Show an error and CTA to proceed without Coupons [Woo POS] Coupons: Show an error and CTA to proceed without Coupons (dummy UI) Mar 26, 2025
@staskus staskus changed the title [Woo POS] Coupons: Show an error and CTA to proceed without Coupons (dummy UI) [Woo POS] Coupons: Show an error and CTA to proceed without Coupons - Dummy UI Mar 26, 2025
@staskus staskus enabled auto-merge March 26, 2025 08:29
@staskus staskus merged commit 9d56402 into trunk Mar 26, 2025
13 of 14 checks passed
@staskus staskus deleted the task/15403-woo-pos-coupons-show-an-error-and-cta-to-proceed-without-coupons branch March 26, 2025 08:49
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.

[Woo POS] Coupons: Show an error and CTA to proceed without Coupons - Dummy UI

4 participants