-
Notifications
You must be signed in to change notification settings - Fork 138
[Woo POS][Refunds] Create full refund #15135
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
base: trunk
Are you sure you want to change the base?
Conversation
…t state changes during processing
Generated by 🚫 Danger |
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements full refund functionality in the Woo POS by adding refund processing capabilities, new UI states for handling loading/success/error scenarios, and calculation logic for refund amounts including taxes. The implementation follows a happy path refund flow where all items in an order can be refunded at once.
Key changes include:
- Addition of refund calculation utilities (subtotal, tax, and item grouping)
- Integration with WCRefundStore API to create refunds
- New state machine transitions for processing, success, and error states
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
RefundRequestItem.kt |
Made refundTotal and refundTax fields nullable with default null values to support optional refund data |
WooPosRefundViewModel.kt |
Added refund processing logic, state management for Processing/Success/Error states, and changed data source method from getOrderById to refreshOrderById |
WooPosRefundState.kt |
Added Processing, RefundSuccess, and RefundError states to handle refund operation lifecycle |
WooPosIssueRefundDialog.kt |
Added UI handling for Processing state with loading indicator and RefundSuccess/RefundError states with appropriate content |
WooPosGroupRefundItems.kt |
New utility class to group refundable items by order item ID and calculate refund totals and taxes |
WooPosCalculateRefundTax.kt |
New utility class to calculate proportional tax amounts for refunded items |
WooPosCalculateRefundSubtotal.kt |
New utility class to calculate refund subtotals by summing unit prices |
WooPosRefundableItem.kt |
Removed lineTotal and lineTax computed properties (calculation moved to dedicated utilities) |
WooPosRefundViewModelTest.kt |
Updated all test mocks to use refreshOrderById instead of getOrderById and added new dependencies to test setup |
WooPosGroupRefundItemsTest.kt |
Comprehensive test coverage for item grouping logic including edge cases |
WooPosCalculateRefundTaxTest.kt |
Test coverage for tax calculation including partial and full refunds |
WooPosCalculateRefundSubtotalTest.kt |
Test coverage for subtotal calculation with various item combinations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
.../fluxc-plugin/src/main/kotlin/org/wordpress/android/fluxc/model/refunds/RefundRequestItem.kt
Outdated
Show resolved
Hide resolved
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosRefundViewModel.kt
Outdated
Show resolved
Hide resolved
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosRefundViewModel.kt
Show resolved
Hide resolved
...ommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosCalculateRefundTax.kt
Outdated
Show resolved
Hide resolved
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosRefundViewModel.kt
Show resolved
Hide resolved
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosRefundViewModel.kt
Show resolved
Hide resolved
...ce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosCalculateRefundSubtotal.kt
Outdated
Show resolved
Hide resolved
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosGroupRefundItems.kt
Outdated
Show resolved
Hide resolved
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosRefundViewModel.kt
Show resolved
Hide resolved
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosRefundViewModel.kt
Show resolved
Hide resolved
|
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
…or empty item lists
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## trunk #15135 +/- ##
============================================
+ Coverage 38.65% 38.67% +0.02%
- Complexity 10513 10534 +21
============================================
Files 2189 2192 +3
Lines 124277 124450 +173
Branches 17170 17199 +29
============================================
+ Hits 48039 48137 +98
- Misses 71397 71457 +60
- Partials 4841 4856 +15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
...ommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosCalculateRefundTax.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @samiuelson!
I found some potential issues. Some of them are likely not bugs, but simply parts of the feature that aren't implemented yet.
- The refund total was one cent off. There is a chance the same happens even in store management or even wpadmin, I haven't tested that.
I was able to replicate this on another order on my store:

-
It seems even when I do a full refund, the order remains in
Completedstatus instead ofRefunded. -
Edit Reasonbutton doesn't do anything. -
I noticed there is a cross/close icon on the 'processing refund' dialog - it doesn't do anything.
-
The refund VM seems to survive so when it's in a certain state (failed/success) I can't get it out of it:
Screen.Recording.2026-01-06.at.12.05.28.mov
- Some orders simply say 'Invalid refund amount`:
Request
{
"path": "/wc/v3/orders/5413/refunds/\u0026_method\u003dpost",
"json": "true",
"body": "{\"reason\":\"\",\"amount\":\"1.311835\",\"api_refund\":\"false\",\"line_items\":[{\"id\":6892,\"quantity\":1,\"refund_tax\":[{\"refund_total\":0.11,\"id\":3}],\"refund_total\":1.201835}],\"restock_items\":true}"
}
Response
{
"error": "woocommerce_rest_cannot_create_order_refund",
"message": "Invalid refund amount."
}
...ommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosCalculateRefundTax.kt
Outdated
Show resolved
Hide resolved
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosGroupRefundItems.kt
Outdated
Show resolved
Hide resolved
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosRefundViewModel.kt
Outdated
Show resolved
Hide resolved
* Add validation for order items in refund calculations * Use same original Order.Item for both taxes and refund total calculation
|
Thanks for catching these, @malinajirka! 🙇
I could reproduce that in my store. The issue should have been fixed with: 2672896 and 3271365.
This seems to be related to 1. If the refund is not full (e.g., refund amount is off by 0.01 the order is not marked
This will be implemented in next iteration: WOOMOB-1775
Thanks, noted; I will address in next PR: WOOMOB-1952
Thanks, noted; I will fix this in another PR: WOOMOB-1951
Thanks for providing more context! I could reproduce that in my store and believe it's been fixed with: 2672896 and 3271365. In case you encounter such bug in the future, please add me to the store so I can debug it further 🙇. |
malinajirka
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @samiuelson! They look good and some of the issues are gone. However, I'm still able to reproduce the 'one cent off' issue (it more or less works in the store management part of the app). See the attached video with voice description of what's happening.
Screen.Recording.2026-01-08.at.11.36.11.mov
The order detail is not refreshed on successful refund (even refund which doesn't end up in the one cent off issue). This is reproduced and mentioned in the video as well.
I'm reproducing this on https://site-for-woocommerce12a3fasdf45dfs6789.mystagingwebsite.com/ with three Apple Ring products in the order. You are admin on the site. Let me know if I can help somehow.
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/orders/WooPosGroupRefundItems.kt
Outdated
Show resolved
Hide resolved
Thanks so much for providing a reproducible scenario, @malinajirka. I investigated the discrepancies and found out they are caused by the
Order refreshing after the refund is going to be implemented as a separate task: WOOMOB-1955 |
|
Version |
|
Thanks @samiuelson! If it would be possible, I think it'd be great to add specific tests for every bug we fix - just to ensure, we don't re-introduce them later. Ideally, the test would even mention the The fix works for the Apple Ring, however, I'm still able to reproduce similar rounding issues. If I recall correctly, there is a setting in Core somewhere which says whether items should be rounded per unit vs per row in the order. It's a random guess, but it could perhaps be related? You should be able to reproduce these issues on my store except of the first one(https://site-for-woocommerce12a3fasdf45dfs6789.mystagingwebsite.com/): This one might not be easy to reproduce - I think it might be related to the fact that the missing item has been trashed/deleted from the store. Screen.Recording.2026-01-09.at.14.17.43.movScreen.Recording.2026-01-09.at.14.19.59.movScreen.Recording.2026-01-09.at.14.21.44.mov |
|
One more thing that could be related - there is a |
WOOMOB-1855
Description
This PR allows creating a full refund in Woo POS in a happy path refund scenario.
💡 The UI of the loading states, error, and success states is not in scope of this PR-it will be updated in the next iteration.
Test Steps
a) order containing a single item
b) order containing multiple items
c) order containing multiple quantities of the same item
Images/gif
demo-19-dec.mp4
RELEASE-NOTES.txtif necessary. Use the "[Internal]" label for non-user-facing changes.