From 7b7182896d9c423ab77a4c2359c559a47aee4b8f Mon Sep 17 00:00:00 2001 From: Eric Jinks <3147296+Jinksi@users.noreply.github.com> Date: Tue, 9 Jan 2024 09:58:43 +1000 Subject: [PATCH] Use shared dispute utility function `isRefundable` for disputed order notice to improve code quality (#7965) --- changelog/dev-refactor-order-dispute-refundable-util | 3 +++ client/components/disputed-order-notice/index.js | 10 +++------- 2 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 changelog/dev-refactor-order-dispute-refundable-util diff --git a/changelog/dev-refactor-order-dispute-refundable-util b/changelog/dev-refactor-order-dispute-refundable-util new file mode 100644 index 00000000000..276e36cdcb8 --- /dev/null +++ b/changelog/dev-refactor-order-dispute-refundable-util @@ -0,0 +1,3 @@ +Significance: patch +Type: dev +Comment: Not user-facing: refactors the refund eligibility logic for disputed orders diff --git a/client/components/disputed-order-notice/index.js b/client/components/disputed-order-notice/index.js index 13ea7af71e5..dce0fb2b77f 100644 --- a/client/components/disputed-order-notice/index.js +++ b/client/components/disputed-order-notice/index.js @@ -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'; @@ -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 ] ); @@ -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.) @@ -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 (