Skip to content

[Shipping labels] Request label refund network #14171

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

Merged
merged 8 commits into from
Jun 13, 2025

Conversation

irfano
Copy link
Contributor

@irfano irfano commented Jun 10, 2025

Part of WOOMOB-370

Description

This implements network integration for the Refund Request screen.

Warning

Known issues:

  • The condition for the visibility of the "Request refund" button will be handled in a separate PR.

Steps to reproduce

Successful case

  1. Open the Orders screen.
  2. Select an order that includes a purchased shipment.
  3. Tap the "Request refund" button.
  4. Tap the "Refund label" button

Testing information

  • Test tapping back while the refund is in progress.
  • Test the failure case. You can do this by attempting to refund a shipment that has already been refunded. Since the visibility condition for the refund button is currently broken, you can take advantage of that to test the failure case.
  • Test refunding a shipment after a successful purchase.

The tests that have been performed

Steps above.

Images/gif

  • I have considered if this change warrants release notes and have added them to RELEASE-NOTES.txt if necessary. Use the "[Internal]" label for non-user-facing changes.

@irfano irfano added this to the 22.6 milestone Jun 10, 2025
@irfano irfano added feature: shipping labels Related to creating, ordering, or printing shipping labels. Task (new) labels Jun 10, 2025
irfano added 3 commits June 11, 2025 02:20
This commit adds a new data class `RefundLabelResponseDTO` to handle the response when refunding a shipping label.
This commit introduces the functionality to request a refund for a shipping label directly from the `WooShippingLabelRefundViewModel`.
@irfano irfano force-pushed the issue/WOOMOB-370-shipping-label-refund-network branch from d0163c0 to bb8177b Compare June 10, 2025 23:21
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jun 10, 2025

📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App Name WooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commitec27f71
Direct Downloadwoocommerce-wear-prototype-build-pr14171-ec27f71.apk

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jun 10, 2025

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

App Name WooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commitec27f71
Direct Downloadwoocommerce-prototype-build-pr14171-ec27f71.apk

@codecov-commenter
Copy link

codecov-commenter commented Jun 11, 2025

Codecov Report

Attention: Patch coverage is 40.90909% with 13 lines in your changes missing coverage. Please review.

Project coverage is 37.75%. Comparing base (d86e726) to head (ec27f71).
Report is 189 commits behind head on trunk.

Files with missing lines Patch % Lines
...inglabels/networking/WooShippingLabelRestClient.kt 0.00% 7 Missing ⚠️
...nglabels/refund/WooShippingLabelRefundViewModel.kt 61.53% 3 Missing and 2 partials ⚠️
...inglabels/networking/WooShippingLabelRepository.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              trunk   #14171      +/-   ##
============================================
+ Coverage     37.74%   37.75%   +0.01%     
- Complexity     8952     8956       +4     
============================================
  Files          1955     1955              
  Lines        109520   109542      +22     
  Branches      14364    14365       +1     
============================================
+ Hits          41334    41363      +29     
+ Misses        64427    64416      -11     
- Partials       3759     3763       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Base automatically changed from issue/WOOMOB-370-shipping-label-refund-UI to trunk June 12, 2025 10:30
@hichamboushaba hichamboushaba self-assigned this Jun 12, 2025
Copy link
Member

@hichamboushaba hichamboushaba left a comment

Choose a reason for hiding this comment

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

Thanks @irfano, this works well, I left some comments, and I'll explain the currency issue with more details below:

I see that we currently use the order.currency for formatting of the shipping label rates and refund, which is problematic, as the order could be created using a different currency (either when using a multi-currency plugin, or just by changing Woo settings), and this issue results in the following:

Screenshot_20250613_105757 Screenshot_20250613_105034

I think we should use the currency from the StoreOptionsModel and for refund another option is to use the currency that we get from the endpoint /wcshipping/v1/label/purchase/<order-id> (that's what was done in the old flow), anyway, I think each approach is fine.

Given this issue is present in other places of the flow, I'm pre-approving the PR, as I think it should be addressed in a separate PR.

@@ -56,6 +60,19 @@ class WooShippingLabelRefundViewModel @Inject constructor(
if (networkStatus.isConnected()) {
_viewState.update { ViewState.Loading }
launch {
selectedSite.getOrNull()?.let {
Copy link
Member

Choose a reason for hiding this comment

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

np, I'm not sure using getOrNull() in this cases is needed, IMO it just complicates the code with nullability handling. When the user reaches this step, we are sure there is a selected site, so it should be fine to use get()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense! Done: ec27f71

repository.refundLabel(
it,
arguments.orderId,
arguments.shipment.labelId ?: return@launch
Copy link
Member

Choose a reason for hiding this comment

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

np, WDYT about passing just what's needed and not the whole ShipmentUIModel? this will have the advantage of avoiding nullable items as we can check for null items before triggering the navigation.

This is also related to a potential issue with the currency usage that we have in this screen and other places, I'll explain this further in the review itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my first attempt, I used separate parameters, but then I noticed I'm already using items, purchaseDate, refundableAmount and labelId from ShipmentUIModel. So, I thought it would be cleaner to use only ShipmentUIModel.

This is also related to a potential issue with the currency usage that we have in this screen and other places

If we fix that issue, we might stop using items, but it’s likely that we’ll use the shipping rates’ currency instead, which can also be part of ShipmentUIModel.

So, I thought it would be cleaner to use a single model, ShipmentUIModel. Let me know if you still think passing separate arguments would be a better approach.

Copy link
Member

Choose a reason for hiding this comment

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

As I pointed, this is just a np comment, but personally I think it's still better to pass separate items, or even better just pass the labelId of the label, and retrieve the data from the DataStores (like what we did in the old flow).

When we pass a large model to a screen, it gets saved into the SavedStateHandle, and thus increasing the chances of TransactionTooLargeException crashes, I don't think the model is that large in this case, but to me it's just a good practice that I try to follow, given these crashes were hard to fix in the past for us.

Copy link
Member

Choose a reason for hiding this comment

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

Merging this as is and revisiting this when working on the currency fix is an option too 🙂

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, that makes sense. It would be better to pass fewer arguments. I’ll do it in another PR.

@hichamboushaba
Copy link
Member

Another point, I see that the "Request a refund" button on the order details still opens the old flow, will this be handled in a separate PR?

@wpmobilebot wpmobilebot modified the milestones: 22.6, 22.7 Jun 13, 2025
@wpmobilebot
Copy link
Collaborator

Version 22.6 has now entered code-freeze, so the milestone of this PR has been updated to 22.7.

@irfano
Copy link
Contributor Author

irfano commented Jun 13, 2025

Thanks for the review, @hichamboushaba!

  • I've opened an issue for the currency problem: WOOMOB-609
  • I'll handle opening the new refund flow from the order screen in a separate PR.

@irfano irfano merged commit 98f5ebd into trunk Jun 13, 2025
17 checks passed
@irfano irfano deleted the issue/WOOMOB-370-shipping-label-refund-network branch June 13, 2025 18:01
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. Task (new)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants