UNPKG

@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.

75 lines (74 loc) 2.94 kB
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] = "27373533-06dd-4640-994e-422e120457f7", e._sentryDebugIdIdentifier = "sentry-dbid-27373533-06dd-4640-994e-422e120457f7"); } catch (e) {} import { n as httpGet, s as useApiContext } from "./http-D1NDkBxF.js"; import { n as SettingsContext } from "./useSettingsContext-DzwVt0W0.js"; import { t as CountryCodes } from "./country-code-CX5KqMBr.js"; import { t as useCapabilities } from "./useCapabilities-BW9uTmoB.js"; import { useContext } from "preact/hooks"; import { useQuery } from "@tanstack/preact-query"; //#region src/api/configurations/useSupportedCountries.ts /** * Retrieves from the backend information about supported countries * linked to the legalEntityId * * @param id legalEntityId * @param options additional options passed to Tanstack Query, eg; refetchInterval for polling */ var getSupportedCountries = async (legalEntityId, baseUrl) => { return httpGet({ baseUrl, path: `legalEntities/${legalEntityId}/configurations/supportedCountries` }); }; var useSupportedCountries = (options) => { const { rootLegalEntityId, baseUrl } = useApiContext(); return useQuery({ queryKey: ["supportedCountries"], queryFn: () => getSupportedCountries(rootLegalEntityId.value, baseUrl.value), ...options }); }; //#endregion //#region src/context/SettingsContext/useSetting.ts var useSetting = (settingName) => { const { getSetting } = useContext(SettingsContext); return getSetting(settingName); }; //#endregion //#region src/hooks/useAllowedCountries.ts var businessAccountCountries = [ CountryCodes.Austria, CountryCodes.Belgium, CountryCodes.Croatia, CountryCodes.Cyprus, CountryCodes.Estonia, CountryCodes.Finland, CountryCodes.France, CountryCodes.Germany, CountryCodes.Greece, CountryCodes.Ireland, CountryCodes.Italy, CountryCodes.Latvia, CountryCodes.Lithuania, CountryCodes.Luxembourg, CountryCodes.Malta, CountryCodes.Netherlands, CountryCodes.Portugal, CountryCodes.Slovakia, CountryCodes.Slovenia, CountryCodes.Spain, CountryCodes.UnitedKingdom, CountryCodes.UnitedStates ]; var useAllowedCountries = () => { const isLimitCountryBusinessAccountCustomersEnabled = Object.keys(useCapabilities() ?? {}).includes("issueBankAccount"); const acceptedCountriesSetting = useSetting("acceptedCountries"); const { data } = useSupportedCountries({ enabled: !acceptedCountriesSetting }); const allowedCountries = acceptedCountriesSetting ?? data?.countries; if (!allowedCountries) return; return isLimitCountryBusinessAccountCustomersEnabled ? businessAccountCountries.filter((country) => allowedCountries.includes(country)) : allowedCountries; }; //#endregion export { useSetting as n, useAllowedCountries as t };