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

Use shared dispute utility function isRefundable for disputed order notice to improve code quality #7965

Merged
merged 14 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/dev-refactor-order-dispute-refundable-util
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Significance: patch
Type: dev
Comment: Not user-facing: refactors the refund eligibility logic for disputed orders
10 changes: 3 additions & 7 deletions client/components/disputed-order-notice/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getDetailsURL } from 'wcpay/components/details-link';
import {
isAwaitingResponse,
isInquiry,
isRefundable,
isUnderReview,
} from 'wcpay/disputes/utils';
import { useCharge } from 'wcpay/data';
Expand All @@ -30,10 +31,7 @@ const DisputedOrderNoticeHandler = ( { chargeId, onDisableOrderRefund } ) => {
if ( ! charge?.dispute ) {
return;
}
// Refunds are only allowed if the dispute is an inquiry or if it's won.
const isRefundable =
isInquiry( dispute ) || [ 'won' ].includes( dispute.status );
if ( ! isRefundable ) {
if ( ! isRefundable( dispute.status ) ) {
onDisableOrderRefund( dispute.status );
}
}, [ charge, onDisableOrderRefund ] );
Expand All @@ -42,8 +40,6 @@ const DisputedOrderNoticeHandler = ( { chargeId, onDisableOrderRefund } ) => {
if ( ! charge?.dispute ) {
return null;
}
const isRefundable =
isInquiry( dispute ) || [ 'won' ].includes( dispute.status );

// Special case the dispute "under review" notice which is much simpler.
// (And return early.)
Expand All @@ -66,7 +62,7 @@ const DisputedOrderNoticeHandler = ( { chargeId, onDisableOrderRefund } ) => {
// This may be dead code. Leaving in for now as this is consistent with
// the logic before this PR.
// https://github.com/Automattic/woocommerce-payments/pull/7557
if ( dispute.status === 'lost' && ! isRefundable ) {
Copy link
Member Author

@Jinksi Jinksi Jan 3, 2024

Choose a reason for hiding this comment

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

isRefundable is redundant here since isRefundable('lost') will always be false if dispute.status === 'lost'.

if ( dispute.status === 'lost' ) {
return (
<DisputeOrderLockedNotice
message={ __(
Expand Down
Loading