diff --git a/changelog/fix-7960-transaction-refund-eligible-disputes-only b/changelog/fix-7960-transaction-refund-eligible-disputes-only new file mode 100644 index 00000000000..e35c11107f7 --- /dev/null +++ b/changelog/fix-7960-transaction-refund-eligible-disputes-only @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Hide the transaction details refund menu for ineligble disputed transactions diff --git a/client/disputes/utils.ts b/client/disputes/utils.ts index 6e5acf2f437..d4cb2fc52d1 100644 --- a/client/disputes/utils.ts +++ b/client/disputes/utils.ts @@ -72,6 +72,11 @@ export const isInquiry = ( dispute: Pick< Dispute, 'status' > ): boolean => { return dispute.status.startsWith( 'warning' ); }; +export const isRefundable = ( status: DisputeStatus ): boolean => { + // Refundable dispute statuses are one of `warning_needs_response`, `warning_under_review`, `warning_closed` or `won`. + return isInquiry( { status } ) || 'won' === status; +}; + /** * Returns the dispute fee balance transaction for a dispute if it exists * and the deduction has not been reversed. diff --git a/client/payment-details/summary/index.tsx b/client/payment-details/summary/index.tsx index 607bacb5f0a..58db34e8da3 100644 --- a/client/payment-details/summary/index.tsx +++ b/client/payment-details/summary/index.tsx @@ -48,6 +48,7 @@ import DisputeStatusChip from 'components/dispute-status-chip'; import { getDisputeFeeFormatted, isAwaitingResponse, + isRefundable, } from 'wcpay/disputes/utils'; import { useAuthorization } from 'wcpay/data'; import CaptureAuthorizationButton from 'wcpay/components/capture-authorization-button'; @@ -208,6 +209,15 @@ const PaymentDetailsSummary: React.FC< PaymentDetailsSummaryProps > = ( { const disputeFee = charge.dispute && getDisputeFeeFormatted( charge.dispute ); + // If this transaction is disputed, check if it is refundable. + const isDisputeRefundable = charge.dispute + ? isRefundable( charge.dispute.status ) + : true; + + // Control menu only shows refund actions for now. In the future, it may show other actions. + const showControlMenu = + charge.captured && ! charge.refunded && isDisputeRefundable; + // Use the balance_transaction fee if available. If not (e.g. authorized but not captured), use the application_fee_amount. const transactionFee = charge.balance_transaction ? { @@ -484,7 +494,7 @@ const PaymentDetailsSummary: React.FC< PaymentDetailsSummaryProps > = ( {
- { ! charge?.refunded && charge?.captured && ( + { showControlMenu && ( { screen.getByRole( 'button', { name: /Accept dispute/, } ); + + // Refund menu is not rendered + expect( + screen.queryByRole( 'button', { + name: /Translation actions/i, + } ) + ).toBeNull(); } ); test( 'renders the information of a disputed charge when the store/charge currency differ', () => { @@ -684,6 +691,11 @@ describe( 'PaymentDetailsSummary', () => { name: /Accept/i, } ) ).toBeNull(); + + // Refund menu is rendered + screen.getByRole( 'button', { + name: /Translation actions/i, + } ); } ); test( 'correctly renders dispute details for "under_review" disputes', () => { @@ -712,6 +724,13 @@ describe( 'PaymentDetailsSummary', () => { name: /Accept/i, } ) ).toBeNull(); + + // Refund menu is not rendered + expect( + screen.queryByRole( 'button', { + name: /Translation actions/i, + } ) + ).toBeNull(); } ); test( 'correctly renders dispute details for "accepted" disputes', () => { @@ -744,6 +763,13 @@ describe( 'PaymentDetailsSummary', () => { name: /Accept/i, } ) ).toBeNull(); + + // Refund menu is not rendered + expect( + screen.queryByRole( 'button', { + name: /Translation actions/i, + } ) + ).toBeNull(); } ); test( 'correctly renders dispute details for "lost" disputes', () => { @@ -777,6 +803,13 @@ describe( 'PaymentDetailsSummary', () => { name: /Accept/i, } ) ).toBeNull(); + + // Refund menu is not rendered + expect( + screen.queryByRole( 'button', { + name: /Translation actions/i, + } ) + ).toBeNull(); } ); test( 'correctly renders dispute details for "warning_needs_response" inquiry disputes', () => { @@ -807,6 +840,11 @@ describe( 'PaymentDetailsSummary', () => { screen.getByRole( 'button', { name: /Issue refund/i, } ); + + // Refund menu is rendered + screen.getByRole( 'button', { + name: /Translation actions/i, + } ); } ); test( 'correctly renders dispute details for "warning_under_review" inquiry disputes', () => { @@ -834,6 +872,11 @@ describe( 'PaymentDetailsSummary', () => { name: /Accept/i, } ) ).toBeNull(); + + // Refund menu is rendered + screen.getByRole( 'button', { + name: /Translation actions/i, + } ); } ); test( 'correctly renders dispute details for "warning_closed" inquiry disputes', () => { @@ -862,6 +905,11 @@ describe( 'PaymentDetailsSummary', () => { name: /Accept/i, } ) ).toBeNull(); + + // Refund menu is rendered + screen.getByRole( 'button', { + name: /Translation actions/i, + } ); } ); describe( 'order missing notice', () => {