Skip to content

Conversation

@RafaelKayumov
Copy link
Contributor

@RafaelKayumov RafaelKayumov commented Jul 1, 2025

WOOMOB-734

Description

This is a follow PR to complete the recent customs data prefill feature: [Shipping Labels] Prefill customs form origin country.
The customs data became complete after a prefill without interacting with the customs form. But the customsForm instance wasn't assigned because the onCompletion callback was only triggered by a manual customs form dismissal.

In this PR we automatically trigger the assignment callback as soon as the customs form data becomes completed. And we do that just once to handle the customs data completion by just a pre-fill.

  • Renamed onCompletion -> onFormReady since the callback is now not only related to the form editing completion.
  • Listen to requiredInformationIsEntered and trigger onFormReady just once when data becomes completed.
  • Updated tests

Testing steps

  • Navigate to a completed order with an unfulfilled shipment with a foreign destination address.
  • Go to "Create shipping label" flow
  • Select the unfulfilled shipment
  • Make sure the customs row is presented
  • Make sure the customs row displays "Completed" status
  • Don't open the customs form.
  • Select a package and a rate
  • Purchase label
  • Make sure the purchase is completed without any errors. (It would fail if customs data is missing any required fields)
  • Consider testing the flow with Proxyman. Track the /wcshipping/v1/label/purchase/[label id]&_method=post request and make sure the response contains proper customs data.

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

@RafaelKayumov RafaelKayumov added this to the 22.8 milestone Jul 1, 2025
@RafaelKayumov RafaelKayumov added type: task An internally driven task. feature: shipping labels Related to creating, ordering, or printing shipping labels. labels Jul 1, 2025
@RafaelKayumov RafaelKayumov requested a review from itsmeichigo July 1, 2025 15:40
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jul 1, 2025

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

App NameWooCommerce iOS Prototype
Build Number30940
VersionPR #15853
Bundle IDcom.automattic.alpha.woocommerce
Commit5bc1a76
Installation URL2h6cphhm7o608
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@itsmeichigo itsmeichigo self-assigned this Jul 2, 2025
Copy link
Contributor

@itsmeichigo itsmeichigo left a comment

Choose a reason for hiding this comment

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

I tested and confirmed the purchase success following the steps in the PR description.

However, I can still get a purchase failure if I edit the destination address from US to non-US (more details in a comment below).

I think it'd be simpler to add a computed variable for the customs form that can be retrieved from outside the view model. That way, we can avoid the complicated reactive code and closure. WDYT?

@Published private(set) var selectedRate: WooShippingSelectedRate?

@Published private var customsForm: ShippingLabelCustomsForm?
@Published private(set) var customsForm: ShippingLabelCustomsForm?
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering: why is this necessary?

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 exposed it as read-only to be trackable in unit tests. Returned it back to be just private. Checking the customsForm from package instance instead.

/// As soon as all required info is entered, calls the `emitForm` just once
func listenForRequiredInformationCompletedUponPreFill() {
$requiredInformationIsEntered
.first { $0 == true }
Copy link
Contributor

Choose a reason for hiding this comment

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

Using first here can be risky. I still see the purchase failure with the following steps (edge case):

  • Select an order with a US address as the destination.
  • Edit the address to outside of the US.
  • Proceed to purchase -> same error about missing customs form.

@RafaelKayumov RafaelKayumov requested a review from itsmeichigo July 2, 2025 13:28
@RafaelKayumov RafaelKayumov merged commit fe81261 into trunk Jul 3, 2025
13 checks passed
@RafaelKayumov RafaelKayumov deleted the WOOMOB-734-fix-customs-form-emission branch July 3, 2025 08:12
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