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

[Revamp Shipping Labels • Customs] Validation & Required #14921

Merged
merged 9 commits into from
Jan 22, 2025

Conversation

toupper
Copy link
Contributor

@toupper toupper commented Jan 20, 2025

Part of: #13784

Description

With this PR we implement validation and requirements for the International Transaction Number in Customs in Woo Shipping Label:

  • Validation: we follow this regular expression "^(?:(?:AES X\\d{14})|(?:NOEEI 30\\.\\d{1,2}(?:\\([a-z]\\)(?:\\(\\d\\))?)?))$"
  • Required ITN: If any item in Customs has a value of more than $2500 and a valid HS Tariff, the ITN is required. Update: If the value of the items linked to an HS Tariff adds more than $2500
  • Enable "Save Customs Details": If the ITN is required the button is only enabled if it's valid

Steps to reproduce

Validation

  1. Tap on Create Shipping Label on an order
  2. Tap on the Customs pencil
  3. Play with the International Transaction Number validation. Valid numbers: NOEEI 30.37, NOEEI 30.37(a), AES X12345678901234

ITN Required

  1. Tap on Create Shipping Label on an order
  2. Tap on the Customs pencil
  3. Open an item. Add a value of $2500 and a HS Tariff. Below the ITN text field we show the message: "International Transaction Number is required for shipping items valued over $2,500"
  4. Verify that the "Save Customs Details" button is not enabled until we enter a valid ITN

Testing information

See above

I tested:

  • When an item has more than 1 quantity
  • When there are different HS tariff numbers
  • When there are no HS tariff numbers

Screenshots

Validation

Simulator.Screen.Recording.-.iPhone.16.-.2025-01-20.at.15.23.34.mp4

ITN required

In this video, we can see how the items linked to an HS Tariff add more than $2500 (the second item has a quantity of 2)

Simulator.Screen.Recording.-.iPhone.16.-.2025-01-21.at.17.41.27.mp4

"Save Customs Details" button

Simulator.Screen.Recording.-.iPhone.16.-.2025-01-20.at.15.26.34.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.

@toupper toupper added type: task An internally driven task. feature: shipping labels Related to creating, ordering, or printing shipping labels. labels Jan 20, 2025
@toupper toupper added this to the 21.5 milestone Jan 20, 2025
@toupper toupper requested a review from rachelmcr January 20, 2025 14:54
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jan 20, 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 Numberpr14921-46288e7
Version21.4
Bundle IDcom.automattic.alpha.woocommerce
Commit46288e7
App Center BuildWooCommerce - Prototype Builds #12639
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

Copy link
Contributor

@rachelmcr rachelmcr left a comment

Choose a reason for hiding this comment

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

You mention this ITN requirement:

Required ITN: If any item in Customs has a value of more than $2500 and a valid HS Tariff, the ITN is required.

But based on the Slack conversation, my understanding is the ITN requirement is for the entire shipment cost:

ITN is also required for shipments exceeding $2500

Looking at the legacy flow, it looks the ITN validation is slightly different from both of these explanations (the requirement is if the total amount corresponding to a given HS tariff number in the shipment is above $2,500).

Could we clarify that requirement to make sure we're validating it correctly here?


// Items valued more than $2500 with a valid HSTariff Number require an International Transaction Number
self.internationalTransactionNumberIsRequired = self.currencySymbol == "$" &&
(Double(valuePerUnit) ?? 0) > 2500 &&
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to calculate this for all items in the shipment, right? So not just the valuePerUnit for an individual item. For example:

If a shipment contains 2 apples and 1 orange, and each apple costs $1,000 and an orange costs $600, the individual values per unit are all under $2,500 but the total shipment exceeds $2,500 so it requires an ITN.

// Items valued more than $2500 with a valid HSTariff Number require an International Transaction Number
self.internationalTransactionNumberIsRequired = self.currencySymbol == "$" &&
(Double(valuePerUnit) ?? 0) > 2500 &&
hsTariffNumber.isNotEmpty &&
Copy link
Contributor

@rachelmcr rachelmcr Jan 20, 2025

Choose a reason for hiding this comment

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

I'm not sure I understand the HS Tariff Number requirement here. Shouldn't the ITN requirement be based only on the shipment cost?

Edit to add: Unless the requirement is for the total amount depending on this number, but that's slightly different than what's defined here.

@dangermattic
Copy link
Collaborator

1 Warning
⚠️ This PR is assigned to the milestone 21.5. This milestone is due in less than 2 days.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.

Generated by 🚫 Danger

@toupper
Copy link
Contributor Author

toupper commented Jan 22, 2025

Thanks for the comments @rachelmcr!

After verification with the legacy flow and wp-admin, I see the logic is to require the ITN If the value of the items linked to an HS Tariff adds more than $2500. That takes into account when items have more than one quantity.

@toupper toupper requested a review from rachelmcr January 22, 2025 09:34
Copy link
Contributor

@rachelmcr rachelmcr left a comment

Choose a reason for hiding this comment

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

Looks great! 🚢

self?.internationalTransactionNumberIsRequired = value
.sink { [weak self] value in
// Remove nils
let compactedValues = value.compactMap { $0 }
Copy link
Contributor

Choose a reason for hiding this comment

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

tip: You can use compacted() when you want to remove nils; it does the same as compactMap { $0 }.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point thanks! Done in 46288e7

@toupper toupper merged commit a50b799 into trunk Jan 22, 2025
12 checks passed
@toupper toupper deleted the issue/13784-shipping-labels-customs-itn-validation branch January 22, 2025 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: shipping labels Related to creating, ordering, or printing shipping labels. type: task An internally driven task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants