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 | /**
* Enterprise Validation Module
*
* Centralized validation schemas for acquirer enterprise (provider) creation and management.
*
* @module validation/enterprise
*/
import * as Yup from "yup";
import { matchIsValidTel } from "mui-tel-input";
import {
MERCHANT_PROVIDER_MAX_CHARS,
PROVIDER_PERMALINK_FIELD,
} from "@constants/constants";
import { createStreetAddressValidator } from "@validation/address/streetValidator";
import { buildZipSchema } from "@validation/address/zipValidator";
import { createStateValidator } from "@validation/address/stateValidator";
import { createCountryValidator } from "@validation/address/countryValidator";
import { createCityValidation } from "@validation/address/cityValidator";
import { createUrlValidator, createTaxIdValidator } from "@validation/fields";
import { TinType } from "@validation/types";
/**
* Enterprise creation schema
* Used in CreateEnterprise flow for acquirer portal
*/
export const getEntrepriseCreateSchema = () => {
const enterprise_info = {
enterpriseID: Yup.string(),
enterprise_name: Yup.string()
.required("Name is required")
.matches(
/^[a-zA-Z0-9,.'\s]+$/,
"Provider name should not contain special characters",
)
.max(
MERCHANT_PROVIDER_MAX_CHARS,
`Provider Name can not contain more than ${MERCHANT_PROVIDER_MAX_CHARS} characters`,
)
.trim(),
enterprise_slug: Yup.string().required(
`${PROVIDER_PERMALINK_FIELD} can’t be empty`,
),
avatar_url: Yup.mixed<File | null>(),
description: Yup.string(),
category: Yup.string(),
enterprise_classification: Yup.string(),
servicedPhoneNumber: Yup.string().when({
is: (exists: string) => !!exists,
then: (schema) =>
schema.test(
"is-valid-number",
"Please enter a valid phone number",
function (value) {
const phoneNumber = value as string;
return matchIsValidTel(phoneNumber);
},
),
}),
website_url: createUrlValidator({ required: false }),
hasServiceCountries: Yup.boolean(),
servicedCountries: Yup.string().when("hasServiceCountries", {
is: true,
then: Yup.string().required("At least one serviced country is required"),
}),
};
const businessProfile = {
isLinkBusinessProfile: Yup.boolean(),
linkedBusinessProfile: Yup.number(),
businessType: Yup.string(),
ownershipType: Yup.string(),
legalName: Yup.string(),
DBA: Yup.string(),
tinType: Yup.mixed<TinType>().oneOf(["ssn", "ein", null]),
ssn: Yup.string().when("tinType", {
is: "ssn",
then: createTaxIdValidator({ type: "SSN", required: false }),
}),
taxID: Yup.string().when("tinType", {
is: "ein",
then: Yup.string()
.required(`EIN is required`)
.test("valid-ein", `Please enter a valid EIN`, function (value) {
if (!value) return false;
return value.replace(/(\s|-)/g, "").length === 9;
}),
}),
businessOpenedAt: Yup.string(),
contactPhone: Yup.string(),
address: Yup.object({
country: createCountryValidator({ nullable: false }),
city: createCityValidation(),
address: createStreetAddressValidator(),
state: createStateValidator(),
zip: buildZipSchema({ allowNull: false }),
}),
};
const primary_account_holder = {
email: Yup.string(),
};
const businessOwners = {
files: Yup.array().nullable(),
firstName: Yup.string(),
lastName: Yup.string(),
email: Yup.string(),
ownership: Yup.string(),
ssn: Yup.string(),
dob: Yup.string().nullable(),
phone: Yup.string(),
isBusinessAddress: Yup.boolean(),
address: Yup.object().shape({
country: createCountryValidator({ nullable: false }),
line1: createStreetAddressValidator({ required: false }),
city: createCityValidation(),
state: createStateValidator(),
zip: buildZipSchema(),
}),
};
const schema = Yup.object({
enterprise_info: Yup.object(enterprise_info),
primary_account_holder: Yup.object(primary_account_holder),
businessProfile: Yup.object(businessProfile),
businessOwners: Yup.array().of(Yup.object(businessOwners)),
});
return schema;
};
|