Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | 1x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 3x 1x 20x 1x | import { useFormatDateInTimezone } from "@utils/date.helpers";
import { DisputeDataset, DisputeSecondPanel } from "../types";
import { parseAmount } from "@utils/index";
import { cardIconsMap } from "@features/MerchantPortal/ManageMoney/ManageMoneyTable.atoms";
import BoolIcon from "@features/GiveRiskProfile/Details/BoolIcon";
import { MspMatch } from "@components/Disputes/utils/data.types";
import { CURRENCY } from "@constants/constants";
import RiskLevelProgress from "@features/TransactionPanel/components/RiskLevelProgress";
import { InfoIcon } from "@phosphor-icons/react";
import { useAppTheme } from "@theme/v2/Provider";
import NiceModal, { useModal } from "@ebay/nice-modal-react";
import DisputeBinModal from "@components/Disputes/GiveDisputePanel/modals/DisputeBinModal";
import { useGetFeatureFlagValues } from "FeatureFlags/useGetFeatureFlagValues";
import {
GIVE_DISPUTE_PANEL,
MERCHANT_PREVIEW_PANEL_MODAL,
} from "modals/modal_names";
import { getCaseTypeInfo } from "@components/Disputes/utils";
import { processorMap } from "@features/Merchants/MerchantSidePanel/constants";
import { getDisputeReasonCode } from "@components/Disputes/DisputeTable/utils";
export const usePanelDetails = ({
data,
setSecondPanelType,
}: {
data: DisputeDataset;
setSecondPanelType: (type: DisputeSecondPanel) => void;
}) => {
const { formatInTimezone } = useFormatDateInTimezone();
const { isPurchaseVerificationEnabled, isMerchantProcessorEnabled } =
useGetFeatureFlagValues();
const { palette } = useAppTheme();
const { dispute } = data || {};
const { hide, show, args } = useModal(GIVE_DISPUTE_PANEL);
const {
merchant,
mspExternalCaseNumber,
lastCase,
statusActionDisplayName,
cardholder,
originalTransaction,
binInfo,
createdAt,
processorName,
mspReasonCode,
preChargebackRefundTransaction,
chargebackTransaction,
reason,
} = dispute || {};
const { binNumber, cardType, cardCategory, issuerBankName, country } =
binInfo || {};
const { nameOnCard, cardBrand, cardNumberLast4 } = cardholder || {};
const {
billingDescriptor,
mspAVSMatch,
mspCVVMatch,
charged,
fees,
id,
ipRiskLevel,
} = originalTransaction || {};
const cardsMap = cardIconsMap();
const isWorldpay = processorName === "worldpay" && isMerchantProcessorEnabled;
const isChargeback = Boolean(chargebackTransaction);
const isNoAVSMatch = mspAVSMatch === MspMatch.NOT_PROVIDED;
const isNoCVVMatch = mspCVVMatch === MspMatch.NOT_PROVIDED;
const isPurchaseVerificationOn = true; // Todo: use correct field from BE ex: merchant?.purchaseVerification
const showPurchaseConfirmation =
isPurchaseVerificationEnabled && isPurchaseVerificationOn;
const openMerchantPanel = () => {
hide();
NiceModal.show(MERCHANT_PREVIEW_PANEL_MODAL, {
id: merchant?.accID,
onCloseCallback: () => show(args),
});
};
const { code: disputeCode, reason: disputeReason } =
getDisputeReasonCode(reason);
const isRDRRefund = Boolean(preChargebackRefundTransaction);
const { label: typeLable } = getCaseTypeInfo(dispute || {});
const sections = [
{
title: "Case Summary",
component: (
<RiskLevelProgress
data-testid="dispute-panel-risk"
level={ipRiskLevel}
sx={{ pb: 0 }}
onClick={() => setSecondPanelType("risk")}
/>
),
listData: [
{
label: "Merchant",
value: {
name: merchant?.name,
onClick: () => openMerchantPanel(),
},
},
{
label: "Merchant ID",
value: merchant?.accID,
disableParseAmount: true,
},
...(isMerchantProcessorEnabled
? [
{
label: "Processor",
value: processorName ? processorMap[processorName] : "-",
},
]
: []),
{
label: "Dispute Type",
value: typeLable || "-",
},
{
label: "Internal Case ID",
value: lastCase?.id || "-",
},
{
label: "External Case ID",
value: mspExternalCaseNumber || "-",
},
{
label: "Reason",
value: (isRDRRefund ? disputeReason : lastCase?.reason) || "-",
},
{
label: "Reason Code",
value: (isRDRRefund ? disputeCode : mspReasonCode) || "-",
},
{
label: "Action Required",
value: statusActionDisplayName || "-",
},
{
label: "Deadline",
value: lastCase?.responseDueAt
? formatInTimezone(lastCase?.responseDueAt, "MMM. dd, yyyy")
: "-",
},
],
},
{
title: "Payment Details",
listData: [
{
label: "Name on Card",
value: nameOnCard || "-",
},
{
label: "Card Brand",
icon: cardsMap[cardBrand as keyof typeof cardsMap],
value: cardNameMap[cardBrand as keyof typeof cardNameMap],
},
{
label: "Card Number",
value: `•••• ${cardNumberLast4}`,
},
{
label: "Billing Descriptor",
value: `GIV*${billingDescriptor}`,
},
...(showPurchaseConfirmation
? [{ label: "Purchase Confirmation", value: "Email OTP" }]
: []),
{
label: "Bank",
value: {
name: issuerBankName || binNumber,
onClick: () =>
NiceModal.show(DisputeBinModal, {
issuerBankName: issuerBankName,
cardBrand: cardBrand,
cardType: cardType,
cardCategory: cardCategory,
country: country,
}),
},
testId: "dispute-summary-clickable-item",
startIcon: <InfoIcon size={20} color={palette.text.secondary} />,
tooltipMessage:
"BIN data identifies the card’s issuing bank and type, helpful in fraud detection",
},
{
label: "AVS Match",
value: isNoAVSMatch ? "Not Provided" : mspAVSMatch,
icon: isNoAVSMatch ? undefined : (
<BoolIcon positive={mspAVSMatch === MspMatch.MATCHED} />
),
startIcon: <InfoIcon size={20} color={palette.text.secondary} />,
tooltipMessage:
"AVS verifies if the billing address matches the cardholder’s record with the issuer",
},
{
label: "CVV Match",
value: isNoCVVMatch ? "Not Provided" : mspCVVMatch,
icon: isNoCVVMatch ? undefined : (
<BoolIcon positive={mspCVVMatch === MspMatch.MATCHED} />
),
startIcon: <InfoIcon size={20} color={palette.text.secondary} />,
tooltipMessage:
"CVV is the 3-digit code used for validating card-not-present payments (4-digits for AMEX)",
},
{
label: "Date Created",
value: formatInTimezone(createdAt, "MMM dd, yyyy, hh:mm"),
},
{
label: "Total Amount",
value: `${parseAmount(charged / 100)} ${CURRENCY}`,
},
{
label: "Fee Total",
value: `${parseAmount(fees / 100)} ${CURRENCY}`,
bold: true,
},
],
},
{
type: "customer",
title: "",
listData: [],
},
{
title: "Transaction ID",
listData: [
{
label: "ID",
value: id,
},
],
},
];
return { sections, isWorldpay, isChargeback };
};
const cardNameMap = {
amex: "American Express",
discover: "Discover",
mastercard: "Mastercard",
visa: "Visa",
};
|