Skip to content

Commit

Permalink
Only show transaction refund menu if dispute is refundable
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinksi committed Jan 3, 2024
1 parent 2d61468 commit b864c62
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion client/payment-details/summary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -208,6 +209,14 @@ const PaymentDetailsSummary: React.FC< PaymentDetailsSummaryProps > = ( {
const disputeFee =
charge.dispute && getDisputeFeeFormatted( charge.dispute );

// If this transaction is disputed, check if it is refundable. If not, we should hide the refund menu.
const isDisputeRefundable = charge.dispute
? isRefundable( charge.dispute.status )
: true;

const showRefundMenu =
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
? {
Expand Down Expand Up @@ -484,7 +493,7 @@ const PaymentDetailsSummary: React.FC< PaymentDetailsSummaryProps > = ( {
</div>
</div>
<div className="payment-details__refund-controls">
{ ! charge?.refunded && charge?.captured && (
{ showRefundMenu && (
<Loadable
isLoading={ isLoading }
placeholder={ moreVertical }
Expand Down

0 comments on commit b864c62

Please sign in to comment.