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 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | 263x 46x 46x 46x 263x 99x 99x 99x 806x 2x 263x 3x 3x 3x 3x 263x 5x 5x 5x 5x 5x 5x 5x 5x 5x 3x 2x 1x 1x 263x 188x 188x 188x 188x 188x 188x 188x 188x 188x 188x 188x 188x 188x 106x 82x 188x 158x 30x 263x 544x 544x 544x 263x 40x 40x 40x 40x 40x 263x 544x 544x 544x 544x 544x 544x 544x 544x 544x 544x 544x 544x 544x 544x 263x 263x 920x 919x 1x 918x 918x 918x 918x 263x 1663x 1663x 1663x 1663x 1663x 263x 578x 577x 577x 577x 263x 152x 263x 2x 3x 2x 1x 2x 263x 263x 788x 788x 80x 708x 708x 76x 632x | import { format } from "date-fns";
import { capitalizeFirstLetter } from "@common/Table/helpers";
import {
Transaction,
SourceAccount,
Method,
ParsedTransaction,
FeeItem,
TransactionTableRowParsed,
TransactionTableRow,
} from "./transactions.types";
import { palette } from "@palette";
import { TransactionData } from "./data";
import { parseAmount } from "@utils/index";
import { isEmpty } from "lodash";
import { TransferTableRow } from "@components/Tranfers/utils";
import { feesArray, moveFundsArray } from "./transactions.types";
import { checkPortals } from "@utils/routing";
import { acquirerTransactionStatuses } from "@shared/GiveFilter/constants";
import { mapTransactionStatus } from "@features/TransactionPanel/utils";
import { CHARGEBACK_FEE, CHARGEBACK_REFUND_FEE } from "@constants/constants";
import {
TTransaction,
TTransactionType,
} from "@features/TransactionPanel/types";
import { DISPLAY_TYPE } from "@features/TransactionPanel/shared.types";
export const sourceAccountParser = ({
sourceAccount,
customer,
}: Transaction) => {
const type = sourceAccount.type as keyof SourceAccount;
const isUser = type === "user";
return {
email: isUser ? sourceAccount?.user?.email || "" : customer?.email || "",
firstName: isUser
? sourceAccount?.user?.firstName
? capitalizeFirstLetter(sourceAccount?.user?.firstName)
: ""
: sourceAccount?.merchant?.name || "",
lastName: sourceAccount?.user?.lastName
? capitalizeFirstLetter(sourceAccount?.user?.lastName)
: "",
name: sourceAccount?.merchant?.name || "",
phoneNumber: isUser
? sourceAccount?.user?.phoneNumber || ""
: sourceAccount?.merchant?.phoneNumber || "",
slug: sourceAccount?.merchant?.slug || "",
type: sourceAccount?.merchant?.type || "",
parentName: sourceAccount?.merchant?.parentName || "",
parentAccID: sourceAccount?.merchant?.parentAccID || "",
deletedAt: sourceAccount?.merchant?.deletedAt || null,
parentDeletedAt: sourceAccount?.merchant?.parentDeletedAt || null,
imageURL: sourceAccount?.merchant?.imageURL || "",
};
};
export const sourceMethodParser = ({ sourceMethod }: Transaction) => {
const type = sourceMethod?.type as keyof Method;
const isCard = type === "card";
return {
id: sourceMethod?.bankAccount?.id || "",
name: sourceMethod?.bankAccount?.name || "",
type: sourceMethod?.bankAccount?.type || "",
nickname: sourceMethod?.bankAccount?.nickname || "",
bankName: sourceMethod?.bankAccount?.bankName || "",
numberLast4: isCard
? sourceMethod?.card?.numberLast4 || ""
: sourceMethod?.bankAccount?.numberLast4 || "",
brand: sourceMethod?.card?.brand || "",
cardholderName: sourceMethod?.card?.cardholderName || "",
expiryMonth: sourceMethod?.card?.expiryMonth || 0,
expiryYear: sourceMethod?.card?.expiryYear || 0,
isDebit: sourceMethod?.card?.isDebit || false,
};
};
export function formatDate(
timestamp: number,
dateFormat = "MMMM dd yyyy HH:mm",
) {
return format(new Date(timestamp), dateFormat);
}
export function getSourceAccount(
row?: TransactionTableRow | ParsedTransaction | TTransaction,
) {
return {
...row?.customer,
fullName: `${row?.sourceAccount?.user?.firstName} ${row?.sourceAccount?.user?.lastName}`,
card: row?.sourceMethod?.method,
email: row?.customer?.email,
};
}
export const textColor = (row: any, baseColor: any) => {
const isPending = row?.displayStatus === "Pending";
const isVoided = row?.displayStatus === "Voided";
const isAuthorized = row?.displayStatus === "Authorized";
return isPending || isVoided || isAuthorized
? palette.neutral[60]
: baseColor;
};
export const getOriginalChargedAmount = (row: any, data = false) => {
const cost = row?.cost;
const charged = row?.charged;
const fees = row?.fees;
const transactionType = row?.transactionType;
const isPreChargebackRefund = transactionType === "pre_chargeback_refund";
const isChargeback = transactionType === "chargeback";
const isTransfer = transactionType === "transfer";
const usedFee = isChargeback ? CHARGEBACK_FEE : CHARGEBACK_REFUND_FEE;
if (isChargeback || isPreChargebackRefund)
return data ? cost : charged - usedFee;
else if (isTransfer) {
return Number(charged ?? 0) - Number(fees ?? 0);
} else return charged;
};
export const getAmountFormatAndStyle = (row: any) => {
const { isAcquirerPortal } = checkPortals();
const isPending = row?.displayStatus === "Pending";
const isVoided = row?.displayStatus === "Voided";
const isAuthorized = row?.displayStatus === "Authorized";
const isTransfer = row?.displayType === "Money Transfer";
const isVoidedOrAuthorizedOrPending = isVoided || isAuthorized || isPending;
const isAcquirerProcessing = isAcquirerPortal && !isTransfer;
const isError = row?.displayStatus === "Error";
let amount = row?.balanceAdjustment;
Iif (isTransfer && isError) {
amount = 0;
}
const formattedAmount = parseAmount(amount);
const finalAmount = (() => {
if (isAcquirerProcessing) {
return isVoidedOrAuthorizedOrPending
? parseAmount(0)
: `+${formattedAmount}`;
}
return isVoided ? formattedAmount : `+${formattedAmount}`;
})();
if (amount > 0)
return {
amount: finalAmount,
style: {
color: isVoidedOrAuthorizedOrPending
? palette.gray[200]
: palette.success.main,
},
};
return {
amount: formattedAmount,
style: {
color: isPending ? palette.gray[200] : "inherit",
},
};
};
export const mapCardType = (type: string, isDebit: boolean) => {
Eif (type === "card") {
Iif (isDebit) {
return "Debit Card";
} else {
return "Credit Card";
}
}
return type;
};
// display type based on document:
// - https://docs.google.com/document/d/1DIff9joKzQ7Xr2dUmFf_Xa1ZqtU5wDcuH6aynVyUk18/edit#
const getDisplayType = (row: ParsedTransaction) => {
const { type, sourceMethod, destinationMethod } = row;
switch (type) {
case "transfer":
return DISPLAY_TYPE.MONEY_TRANSFER;
case "purchase":
Eif (sourceMethod?.type === "card") {
Iif (sourceMethod.card?.isDebit) return DISPLAY_TYPE.DEBIT_CARD;
return DISPLAY_TYPE.CREDIT_CARD;
}
return;
case "refund":
case "chargeback":
case "pre_chargeback_refund":
if (destinationMethod?.type === "card") {
if (destinationMethod.card?.isDebit) return DISPLAY_TYPE.DEBIT_CARD;
return DISPLAY_TYPE.CREDIT_CARD;
}
return;
case "reserve_deposit":
return DISPLAY_TYPE.RESERVE_DEPOSIT;
case "reserve_release":
return DISPLAY_TYPE.RESERVE_RELEASE;
default:
return "";
}
};
export const parseRow = (
row: ParsedTransaction,
byHundred = true,
): TransactionTableRowParsed => {
const customerFirstname = row?.customer?.firstName
? capitalizeFirstLetter(row.customer.firstName)
: "";
const customerLastname = row?.customer?.lastName
? capitalizeFirstLetter(row.customer.lastName)
: "";
const factor =
row?.type === "chargeback" ||
row?.type === "refund" ||
row?.type === "transfer"
? -1
: 1;
const isDestinationAccUsed = row?.destinationAccount?.type === "user";
const cardToUse = isDestinationAccUsed
? row?.destinationMethod?.card
: row?.sourceMethod?.card;
// for /transaction paymentMethodSnapshot obj was added while for /transactions-basic not yet
// this check is left as a fallback, to use the old flow if the new obj is undefined
const card =
row?.paymentMethodSnapshot?.card === undefined
? cardToUse
: row?.paymentMethodSnapshot?.card;
const cardType = card?.brand;
const cardDigits = card?.numberLast4;
const cardholderName = card?.cardholderName;
const formattedLabel = getDisplayStatusPortal(row, true);
const devidedBy = byHundred ? 100 : 1;
const isTransfer = row?.type === "transfer";
const merchantName = isTransfer
? row?.sourceAccount?.merchant?.name
: row?.merchantName;
return {
...row,
createdAtTimestamp: row?.createdAt,
amount: (row?.cost / devidedBy) * factor,
endingBalance: row?.endingBalance ? row?.endingBalance / devidedBy : 0,
balanceAdjustment: row?.balanceAdjustment
? row?.balanceAdjustment / devidedBy
: 0,
inflow: row?.inflow / devidedBy,
outflow: row?.outflow / devidedBy,
fees: row?.fees / devidedBy,
cost: row?.cost / devidedBy,
charged: row?.charged / devidedBy,
sourceAccount: row?.sourceAccount,
recipientAccountName: row?.destinationMethod?.bankAccount?.name,
sourceMethod: row?.sourceMethod,
id: row?.id,
title: `${capitalizeFirstLetter(
row?.sourceAccount?.user?.firstName,
)} ${capitalizeFirstLetter(row?.sourceAccount?.user?.lastName)}`,
date: row?.createdAt,
time: formatDate(row?.createdAt * 1000, "MMM. dd yyyy HH:mm"),
type: mapCardType(
row?.sourceMethod.type,
row?.sourceMethod.method?.isDebit ?? false,
) as TTransactionType,
detailedDescription: row?.description?.split(","),
customerName: `${customerFirstname} ${customerLastname}`,
status: formattedLabel, // use correct label here to avoid replacing it in +50 files
paymentDetails: {
nameOnCard: `${capitalizeFirstLetter(
row?.sourceAccount.user?.firstName,
)} ${capitalizeFirstLetter(row?.sourceAccount.user?.lastName)}`,
merchantTaxId: row?.id,
},
originalTransactionID: row?.originalTransactionID,
firstCheckedAt: row?.firstCheckedAt,
firstCheckedBy: row?.firstCheckedBy,
transactionType: row?.type,
isBlocked: row?.isBlocked,
blockedReason: row?.blockedReason,
originalTransactionIsBlocked: row?.originalTransactionIsBlocked,
accID: row?.id,
cardType,
timeV2: row?.createdAt,
cardDigits,
reversalState: row?.reversalState,
cardholderName,
isGrayedOut: row?.isPending,
merchantName:
merchantName ||
(isDestinationAccUsed //for transactio-base endpoint we need this check to use the correct name
? row?.dstAccMerchantName
: row?.srcAccMerchantName),
parentName:
row?.parentName ||
(isDestinationAccUsed //for transactio-base endpoint we need this check to use the correct name
? row?.dstParentName
: row?.srcParentName),
displayType: (row?.displayType || getDisplayType(row)) as string,
};
};
export const parseSettlmentRow = (row: TransactionTableRow) => {
const regex = /^(.+?),\s*([a-zA-Z]+)\s*(\d{4})$/;
const match = row?.description?.match(regex);
const nameOnCard = match?.[1] ?? null;
const cardType = match?.[2] ?? null;
const cardDigits = match?.[3] ?? null;
const detailedDescription = [nameOnCard, cardType, cardDigits];
return {
...row,
transactionType: row?.type,
cardDigits,
cardType,
detailedDescription,
timeV2: row?.settlementDate,
};
};
type TStatus = {
displayStatus: string;
};
export const getStatus = (rowData: TransactionTableRow): TStatus => {
if (isEmpty(rowData)) return { displayStatus: "" };
if (
rowData?.displayType === "Money Transfer" &&
rowData?.processingState === "failed"
) {
return { displayStatus: "Error" };
}
Iif (feesArray.includes(rowData?.transactionType || ""))
return { displayStatus: rowData?.processingState };
Iif (
rowData?.displayStatus === "Move Funds" &&
rowData?.processingState === "settled"
)
return { displayStatus: "Sent" };
const status = getDisplayStatusPortal(rowData);
return { displayStatus: status };
};
export const getDisplayStatusPortal = (
item: any,
isOriginalType = false,
): string => {
const { pathname } = window.location;
const isAcquirerPortal = pathname.startsWith("/acquirer");
const usedType = isOriginalType
? item.type
: item?.transactionType || item?.transactionTypeName || item?.type;
const label = mapTransactionStatus(
usedType || "",
item?.processingState || item?.processingSatetName || "",
item?.isQuarantined,
);
return !isAcquirerPortal && acquirerTransactionStatuses.includes(label)
? "Processing"
: label;
};
export const getType = (rowData: TransactionData | TransactionTableRow) => {
if (rowData?.status === "Chargeback Reversal") return rowData.type;
Iif (feesArray.includes(rowData?.transactionType || "")) return "Fees";
Iif (moveFundsArray.includes(rowData?.transactionType || ""))
return "Money Transfer";
return rowData.displayType;
};
export const parseTransfer = (data: TransferTableRow) => {
return {
createdAtTimestamp: data.createdAt,
amount: data.cost / 100,
endingBalance: data.endingBalance ? data?.endingBalance / 100 : 0,
fees: data.fees / 100,
cost: data.cost / 100,
charged: data.charged / 100,
id: data.objID,
date: data.createdAt,
time: formatDate(data.createdAt * 1000, "MMM. dd yyyy HH:mm"),
status: data.displayStatus,
transactionType: data.transactionTypeName,
balanceAdjustment: data?.balanceAdjustment
? data?.balanceAdjustment / 100
: 0,
errorReason: data?.errorReason,
declinedReason: data?.declinedReason,
canceledReason: data?.canceledReason,
merchantName: data?.merchAccName,
recipientAccountName: data?.recipientAccountName,
parentName: data?.parentAccName,
displayType: "Money Transfer",
displayStatus: data?.displayStatus,
processingState: data?.processingSatetName,
updatedAt: data?.updatedAt,
description: data?.description,
destinationAccount: {
id: data?.merchAccID,
merchant: {
name: data?.merchAccName,
parentName: data?.parentAccName,
parentAccID: data?.parentAccID,
deletedAt: data?.merchantDeletedAt,
parentDeletedAt: data?.parentDeletedAt,
type: data?.merchAccType,
},
},
destinationMethod: {
bankAccount: {
bankName: data?.recipientAccountBankName,
numberLast4: data?.recipientAccountNumberLast4,
RoutingNumber: data?.recipientAccountRoutingNumber,
},
},
sourceAccount: {
id: data?.merchAccID,
user: {
type: data?.merchAccType,
},
},
merchant: {
accID: data?.merchAccID,
name: data?.merchAccName,
},
parentAccID: data?.parentAccID,
merchAccID: data?.merchAccID,
};
};
export const accumulateFees = (
feeItems: FeeItem[],
condition: (cond: FeeItem) => boolean,
) => {
const accumulated = feeItems?.reduce((acc: number, curr: FeeItem) => {
if (condition(curr)) {
return acc + curr.price / 100;
}
return acc;
}, 0);
return parseAmount(accumulated || 0);
};
const TRANSFER_DESCRIPTIONS_BY_KEY = {
reserve_release: {
merchant: "Reserve Funds Released",
provider: "Reserve to Available Transfer",
},
reserve_deposit: {
merchant: "Held in Reserve from Available",
provider: "Available to Reserve Transfer",
},
} as const;
export const getFormattedDescription = (
detailedDescription: string,
type: string | undefined,
isMerchantPortal: boolean,
formatSendMoney?: boolean,
description?: string,
) => {
const portal = isMerchantPortal ? "merchant" : "provider";
if (type && type in TRANSFER_DESCRIPTIONS_BY_KEY) {
return TRANSFER_DESCRIPTIONS_BY_KEY[
type as keyof typeof TRANSFER_DESCRIPTIONS_BY_KEY
][portal];
}
Iif (type === "move_funds" && Boolean(description)) {
return description || "";
}
if (formatSendMoney && detailedDescription) {
return (
detailedDescription
?.replace(/\*/g, "•")
.replace("SENT MONEY TO", "Sent Money to") || ""
);
}
return detailedDescription;
};
|