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 | 23x 397x 289x 289x 289x 289x 2211x 289x 289x 289x 289x 397x 12x 12x 12x 397x 277x 277x 1634x 277x 23x 23x 23x 397x | import { TPrimaryAccountHolder } from "@components/Merchants/MerchantPreview/data.types";
import { getStatusKeysByValues } from "@components/Merchants/MerchantPreview/helpers/parsers";
import { MINIMUM_TRANSFER_BALANCE_USD } from "@constants/constants";
import {
MERCHANT_NOT_ALLOWED__TO_ADD_BANK_ACCOUNTS_SIDEPANEL_MESSAGE,
MERCHANT_NOT_ALLOWED__TO_TRANSFER_MONEY_SIDEPANEL_MESSAGE,
MERCHANT_NOT_ALLOWED_TO_PROCESS_MONEY_SIDEPANEL_MESSAGE,
} from "@constants/stringConstants";
import { isMerchantInvited } from "@features/Merchants/MerchantsTable/utils";
import { isMoreThan24HoursAgo } from "@utils/index";
interface MoneyTransferValidationData {
statusName?: string;
hasApprovedBankAccount?: boolean;
businessProfileStatus?: string;
submerchantAllowedToTransfer?: boolean;
riskCriticalAt?: number | null;
availableBalance?: number;
canTransferMoney?: boolean;
canProcessMoney?: boolean;
hasMID?: boolean;
isDeleted?: boolean;
}
interface ValidationRule {
condition: boolean;
message: string;
isFallbackMessage?: boolean;
}
interface BankAccountValidationData {
isAddingBankAccountAllowed?: boolean;
moneyTransferData: MoneyTransferValidationData;
}
type MoneyTransferValidationDataWithMember = MoneyTransferValidationData & {
memberStatus?: string;
isOnApprovalDelay?: boolean;
};
type BankWithApprovedDelay = BankAccountValidationData & {
isOnApprovalDelay?: boolean;
};
export const useMoneyTransferValidation = () => {
const getNotAllowedMoneyTransferReason = (
data: MoneyTransferValidationDataWithMember,
lowerCaseReason = false,
isProvider = false,
): string => {
const {
statusName,
hasApprovedBankAccount,
submerchantAllowedToTransfer,
riskCriticalAt,
availableBalance,
canTransferMoney,
businessProfileStatus,
memberStatus,
isOnApprovalDelay,
} = data;
const entity = isProvider ? "Provider" : "Merchant";
Iif (
getStatusKeysByValues([
"KYB",
"Underwriting",
"Invited",
"Invite sent",
"Ready for Review",
"Declined",
]).includes(statusName || "") ||
isMerchantInvited(memberStatus) ||
isOnApprovalDelay
)
return "";
const rules: ValidationRule[] = [
{
condition: statusName === "declined",
message: `${entity} Account is Declined`,
},
{
condition: statusName === "suspended",
message: `${entity} Account is Suspended`,
},
{
condition: statusName !== "approved",
message: `${entity} Account is Not Approved yet`,
},
{
condition: !hasApprovedBankAccount,
message: `${entity} has no approved Bank Account`,
},
{
condition: businessProfileStatus === "Suspended",
message: `${entity} Business Profile is Suspended`,
},
{
condition:
Boolean(businessProfileStatus) &&
businessProfileStatus !== "Approved",
message: `${entity} Business Profile is Not Approved`,
},
{
condition: !submerchantAllowedToTransfer,
message: `${entity} Money Transfers are disabled by acquirer${
isProvider ? "" : " or provider"
}`,
},
{
condition: isMoreThan24HoursAgo(riskCriticalAt || 0) && !isProvider,
message: `Merchant Risk Level has been Critical for more than 24 hours`,
},
{
condition: (availableBalance || 0) < MINIMUM_TRANSFER_BALANCE_USD,
message: `${entity}'s Available Balance is less than ${MINIMUM_TRANSFER_BALANCE_USD} USD`,
},
{
condition: !canTransferMoney,
message: `${entity} is unable to transfer money.`,
isFallbackMessage: !canTransferMoney,
},
];
const match = rules.find((rule) => rule.condition);
Iif (!match) return "";
const isFallbackMessage = match?.isFallbackMessage;
const message =
lowerCaseReason && !isFallbackMessage
? match.message.toLowerCase().replace("usd", "USD")
: match.message;
return isFallbackMessage
? message
: `${MERCHANT_NOT_ALLOWED__TO_TRANSFER_MONEY_SIDEPANEL_MESSAGE} ${message}.`;
};
/**
* Generate combined validation message for both bank account and money transfer restrictions
*/
const getBankAccountCombinedBannerMessage = (
data: BankWithApprovedDelay,
pah?: TPrimaryAccountHolder,
): string => {
const notAllowedToAddBAMessage = !data.isAddingBankAccountAllowed
? `${MERCHANT_NOT_ALLOWED__TO_ADD_BANK_ACCOUNTS_SIDEPANEL_MESSAGE}\n`
: "";
const notAlloweMoneyTransferReason = getNotAllowedMoneyTransferReason({
...data.moneyTransferData,
memberStatus: pah?.memberStatus,
isOnApprovalDelay: data?.isOnApprovalDelay,
});
return `${notAllowedToAddBAMessage} ${notAlloweMoneyTransferReason}`.trim();
};
const getNotAllowedMoneyProcessReason = (
data: MoneyTransferValidationData,
): string => {
const { canProcessMoney, statusName, businessProfileStatus, hasMID } = data;
const rules: ValidationRule[] = [
{
condition: Boolean(statusName) && statusName === "suspended",
message: "merchant account is suspended",
},
{
condition: Boolean(statusName) && statusName !== "approved",
message: "merchant account is not approved yet",
},
{
condition: businessProfileStatus === "Suspended",
message: "merchant business profile is suspended",
},
{
condition:
Boolean(businessProfileStatus) &&
businessProfileStatus !== "Approved",
message: "merchant business profile is not approved",
},
{
condition: !hasMID,
message: "merchant has MID issue",
},
{
condition: !canProcessMoney,
message: "Merchant is unable to process money.",
isFallbackMessage: !canProcessMoney,
},
];
const match = rules.find((rule) => rule.condition);
if (!match) return "";
const isFallbackMessage = match.isFallbackMessage;
const message = match.message
? `${MERCHANT_NOT_ALLOWED_TO_PROCESS_MONEY_SIDEPANEL_MESSAGE} ${match.message}`
: "";
return isFallbackMessage ? match.message : message;
};
return {
getNotAllowedMoneyTransferReason,
getBankAccountCombinedBannerMessage,
getNotAllowedMoneyProcessReason,
};
};
|