Skip to content

Commit

Permalink
Use shared dispute utility function isRefundable for disputed order…
Browse files Browse the repository at this point in the history
… notice to improve code quality (#7965)
  • Loading branch information
Jinksi authored Jan 8, 2024
1 parent 14b37a2 commit 7b71828
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
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 ) {
if ( dispute.status === 'lost' ) {
return (
<DisputeOrderLockedNotice
message={ __(
Expand Down

0 comments on commit 7b71828

Please sign in to comment.