@adyen/kyc-components
Version:
This guide assumes that you have already an account with Adyen. A legalEntity needs to be created, and you need to have a `legalEntityId` to instatiate a Component.
83 lines (82 loc) • 3.69 kB
JavaScript
try {
let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack;
n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "c32dcda7-be76-44cd-a22e-407ac014c185", e._sentryDebugIdIdentifier = "sentry-dbid-c32dcda7-be76-44cd-a22e-407ac014c185");
} catch (e) {}
import { t as getLegalEntityCountry } from "./getLegalEntityCountry-C6bSV6sB.js";
import { p as TaskTypes } from "./entityAssociationUtil-BEzUdPbm.js";
import { n as isEuCountry, r as isHkSgCountry } from "./country-COrdWGaq.js";
//#region src/utils/birthDateUtils.tsx
/**
* Calculates the age of a person based on their birthdate.
* @param birthdate - The birthdate of the person in 'YYYY-MM-DD' format.
* @returns The age of the person in years.
*/
var getAgeToday = (birthdate) => {
const today = /* @__PURE__ */ new Date();
const todayMonth = today.getMonth();
const todayDay = today.getDate();
const bdDate = new Date(birthdate);
const bdMonth = bdDate.getMonth();
const yearDifference = today.getFullYear() - bdDate.getFullYear();
if (todayMonth > bdMonth) return yearDifference;
if (todayMonth === bdMonth && todayDay >= bdDate.getUTCDate()) return yearDifference;
return yearDifference - 1;
};
/**
* Returns the age range for a legal representative based on the country.
* @param country - The country code.
* @returns An object with min and max age, or undefined if not applicable.
*/
var getAgeRangeForLegalRepresentative = (country) => {
if (!country || isHkSgCountry(country)) return;
if (isEuCountry(country)) return {
min: 16,
max: 18
};
return {
min: 13,
max: 18
};
};
/**
* Checks if a person is under the required age for KYC based on their birthdate and country.
* @param birthDate - The birthdate of the person.
* @param country - The country of residence.
* @returns True if the person is under the required age, false otherwise.
*/
var isPersonUnderAge = (birthDate, country) => {
if (!birthDate || !country) return false;
const ageRange = getAgeRangeForLegalRepresentative(country);
if (!ageRange) return false;
return isAgeWithinRange(getAgeToday(birthDate), ageRange);
};
/**
* Determines if a legal representative is needed based on age, country, and task type.
* @param birthDate - The birthdate of the person.
* @param country - The country of residence.
* @param taskType - The type of task being performed.
* @returns True if a legal representative is needed, false otherwise.
*/
var isLegalRepresentativeNeeded = (birthDate, country, taskType) => {
if (taskType === TaskTypes.LEGAL_REPRESENTATIVE_DETAILS) return false;
return isPersonUnderAge(birthDate, country);
};
/**
* Checks if an age is within a given range.
* @param age - The age to check.
* @param ageRange - An object with min and max age.
* @returns True if the age is within the range, false otherwise.
*/
var isAgeWithinRange = (age, ageRange) => ageRange.min <= age && age < ageRange.max;
/**
* Checks if a legal entity requires a legal representative based on the individual's age.
* @param legalEntity - The existing legal entity.
* @returns True if a legal representative is required, false otherwise.
*/
var doesLegalEntityRequiresLegalRepresentative = (legalEntity) => {
if (!legalEntity || !legalEntity?.individual) return false;
const birthDate = legalEntity?.individual?.birthData?.dateOfBirth;
return isPersonUnderAge(birthDate, getLegalEntityCountry(legalEntity));
};
//#endregion
export { isLegalRepresentativeNeeded as i, getAgeRangeForLegalRepresentative as n, getAgeToday as r, doesLegalEntityRequiresLegalRepresentative as t };