@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.
412 lines (411 loc) • 20.3 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] = "e5c4ca74-8bbc-4b04-a069-e222129dc928", e._sentryDebugIdIdentifier = "sentry-dbid-e5c4ca74-8bbc-4b04-a069-e222129dc928");
} catch (e) {}
import { i as Typography, n as addResourceBundles, o as createLogger, r as useTranslation } from "./translation-BFxyJ1c5.js";
import { a as stylesheets, i as useI18nContext, n as EmbedShell, t as resolveEnvironment } from "./resolveEnvironment-UWosxArO.js";
import { r as Loader, t as Button } from "./Button-oj6H8OrC.js";
import { n as httpGet, s as useApiContext } from "./http-D1NDkBxF.js";
import { r as cloneObject, u as entriesOf } from "./useAnalyticsContext-BVFDMrVE.js";
import { t as _rolldown_dynamic_import_helper_default } from "./_rolldown_dynamic_import_helper-rq_tsyLP.js";
import { r as TaskStatuses } from "./taskStatus-C7XU4UIF.js";
import { t as useDataset } from "./useDataset-ZHrWhmsh.js";
import { n as datasetUtilities, t as datasetIdentifier } from "./datasetUtil-Zd4TCTDn.js";
import { t as Alert } from "./Alert-C6gL3JIt.js";
import { n as getCapabilityProblems } from "./processCapabilities-DlZY9-Jc.js";
import { t as Card } from "./Card-vYndix5Y.js";
import { t as useToastContext } from "./useToastContext-CYgfHjSb.js";
import { t as useDeleteTransferInstrument } from "./useDeleteTransferInstrument-BwCQ-6Hm.js";
import { t as VerificationErrorAlert } from "./VerificationErrorAlert-DR3lTJhB.js";
import { t as Modal } from "./Modal-CioQJ7Q7.js";
import { t as Confirm } from "./Confirm-B6TWSuab.js";
import { t as StructuredList } from "./StructuredList-w0Z2zLTk.js";
import { t as emitAdyenSdkEvent } from "./emitEvent-Cdd95HOT.js";
import { t as Tag } from "./Tag-BhU73i1R.js";
import { n as statusToTag, t as EmbeddedStatus } from "./EmbeddedStatus-C0cKHgzR.js";
import { n as useTransferInstrument, t as mapTransferInstrumentToPayoutAccount } from "./mapTransferInstrumentToPayoutAccount--CQmg2ha.js";
import { t as currencyByCountry } from "./types-qnPNJzLh.js";
import { t as DetailViewLayout } from "./DetailViewLayout-Dd5YzmcW.js";
import register from "preact-custom-element";
import { useRef, useState } from "preact/hooks";
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
import { useQuery } from "@tanstack/preact-query";
//#region src/api/transferInstruments/useTransferInstruments.ts
var getTransferInstruments = async (legalEntityId, baseUrl) => {
return httpGet({
baseUrl,
path: `legalEntities/${legalEntityId}/transferInstruments`
});
};
/**
* Gets a list of transfer instruments associated with a legal entity
* @param options additional options passed to Tanstack Query, eg; refetchInterval for polling
*/
var useTransferInstruments = (options) => {
const { rootLegalEntityId, baseUrl } = useApiContext();
return useQuery({
queryKey: ["transferInstruments"],
queryFn: () => getTransferInstruments(rootLegalEntityId.value, baseUrl.value),
...options
});
};
//#endregion
//#region src/components/EmbeddedDropins/ManageTransferInstrumentComponent/ManageTransferInstrumentOverviewItemModal/ManageTransferInstrumentOverviewItemModal.tsx
function ManageTransferInstrumentOverviewItemModal({ status, transferInstrument, onEdit, onClose, onRemove, onInitiateRemove }) {
const { i18n } = useI18nContext();
const { t } = useTranslation("ui");
const [confirmOpen, setConfirmOpen] = useState(false);
const datasetUtils = datasetUtilities(i18n.locale);
const isReviewInProgress = status === "PROCESSING";
const showEditButton = !transferInstrument?.bankAccount.trustedSource;
const problems = transferInstrument ? getCapabilityProblems(transferInstrument, transferInstrument.bankAccount.countryCode) : {};
const formatDataForStructuredList = (data) => {
const summaryData = cloneObject(data);
if (!summaryData.payoutAccountDetails) return [];
if (summaryData.payoutVerificationMethod?.bankCountry) {
summaryData.payoutAccountDetails.bankCountry = datasetUtils.getCountryName(summaryData.payoutVerificationMethod.bankCountry);
summaryData.payoutAccountDetails.currency = currencyByCountry[summaryData.payoutVerificationMethod.bankCountry]?.[0];
}
delete summaryData.payoutAccountDetails.transferInstrumentId;
return entriesOf(summaryData.payoutAccountDetails).map(([key, value]) => ({
term: i18n.get(key),
details: value
}));
};
const getStatusTag = () => {
const statusTagProps = statusToTag(TaskStatuses[status], t);
if (!statusTagProps) return;
return /* @__PURE__ */ jsx(Tag, {
variant: statusTagProps.variant,
children: statusTagProps.text
});
};
const getPayoutDetailSummary = (ti) => {
const mappedTI = formatDataForStructuredList(mapTransferInstrumentToPayoutAccount(ti));
const statusTag = getStatusTag();
mappedTI.push({
term: i18n.get("status"),
details: statusTag
});
return mappedTI;
};
const getStructuredLists = () => {
if (!transferInstrument) return [];
const summaries = [];
summaries.push(getPayoutDetailSummary(transferInstrument));
if (transferInstrument.documentDetails) summaries.push([
{
term: i18n.get("verificationMethod"),
details: i18n.get("documentUpload")
},
{
term: i18n.get("documentType"),
details: i18n.get(transferInstrument.documentDetails[0]?.type)
},
{
term: i18n.get("documentName"),
details: transferInstrument.documentDetails[0]?.fileName
}
]);
return summaries;
};
const handleRemove = async () => {
await onRemove(transferInstrument.id);
onClose();
};
const handleDeleteClick = async () => {
if (onInitiateRemove) {
if (onInitiateRemove()) await handleRemove();
} else setConfirmOpen(true);
};
const actions = /* @__PURE__ */ jsxs(Fragment, { children: [transferInstrument && showEditButton && /* @__PURE__ */ jsx(Button, {
onClick: () => onEdit(transferInstrument.id),
disabled: isReviewInProgress,
children: i18n.get("edit")
}), /* @__PURE__ */ jsx(Button, {
variant: "secondary",
onClick: handleDeleteClick,
disabled: isReviewInProgress,
children: i18n.get("delete")
})] });
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Modal, {
onClose,
ariaLabel: i18n.get("bankAccount"),
inset: true,
children: !transferInstrument ? /* @__PURE__ */ jsx(Loader, {}) : /* @__PURE__ */ jsxs(DetailViewLayout, {
title: i18n.get("bankAccount"),
actions,
compact: true,
children: [!!problems.BankAccount?.[transferInstrument.id]?.verificationErrors && /* @__PURE__ */ jsx(VerificationErrorAlert, {
problems: problems.BankAccount?.[transferInstrument.id],
children: /* @__PURE__ */ jsx(Button, {
variant: "link",
onClick: () => onEdit(transferInstrument.id),
children: i18n.get("editDetails")
})
}), getStructuredLists().map((listItems) => /* @__PURE__ */ jsx(Card, {
variant: "secondary",
children: /* @__PURE__ */ jsx(StructuredList, { items: listItems })
}, listItems))]
})
}), confirmOpen && /* @__PURE__ */ jsx(Confirm, {
title: i18n.get("areYouSureYouWantToDeleteThisBankAccount"),
onConfirm: handleRemove,
confirmText: i18n.get("delete"),
onCancel: () => setConfirmOpen(false),
critical: true
})] });
}
//#endregion
//#region src/components/EmbeddedDropins/ManageTransferInstrumentComponent/ManageTransferInstrumentOverviewItem/ManageTransferInstrumentOverviewItem.tsx
function ManageTransferInstrumentOverviewItem({ transferInstrumentReference, onEdit, onRemove, onInitiateRemove }) {
const { i18n } = useI18nContext();
const { status, transferInstrument: transferInstrumentRef } = transferInstrumentReference;
const [fetchedTi, setFetchedTi] = useState(false);
const [modalOpen, setModalOpen] = useState(false);
const { data: transferInstrument } = useTransferInstrument(transferInstrumentRef.id, { enabled: fetchedTi });
const isDetailsRequired = status === "DETAILS_REQUIRED";
const accountIdentifier = transferInstrumentRef.accountIdentifier?.replaceAll("*", "•");
const handleClick = () => {
if (!fetchedTi) setFetchedTi(true);
if (isDetailsRequired) {
onEdit(transferInstrumentRef.id);
return;
}
setModalOpen(true);
};
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(EmbeddedStatus, {
status: TaskStatuses[status],
className: "adyen-kyc-manage-ti-overview-item",
iconName: "bank",
title: accountIdentifier,
subtitle: i18n.get("bankAccount"),
onClick: handleClick,
actionIndicator: isDetailsRequired ? { text: i18n.get("continue") } : void 0,
"aria-label": `${i18n.get("bankAccount")} ${accountIdentifier}`
}), modalOpen && /* @__PURE__ */ jsx(ManageTransferInstrumentOverviewItemModal, {
transferInstrument,
onEdit,
onRemove,
onInitiateRemove,
onClose: () => setModalOpen(false),
status
})] });
}
//#endregion
//#region src/components/EmbeddedDropins/ManageTransferInstrumentComponent/ManageTransferInstrumentOverview/ManageTransferInstrumentOverview.tsx
function ManageTransferInstrumentOverview({ transferInstrumentReferences, legalEntityId, onEdit, onAdd, onRemove, onInitiateRemove }) {
const { i18n } = useI18nContext();
const transferInstrumentListEle = transferInstrumentReferences?.map((transferInstrumentRef) => {
if (!transferInstrumentRef?.transferInstrument?.id || !transferInstrumentRef.status) return;
return /* @__PURE__ */ jsx(ManageTransferInstrumentOverviewItem, {
transferInstrumentReference: transferInstrumentRef,
onEdit,
onRemove,
onInitiateRemove
}, transferInstrumentRef.transferInstrument?.id);
});
return /* @__PURE__ */ jsxs("section", {
className: "adyen-kyc-manage-ti-overview",
children: [transferInstrumentListEle, /* @__PURE__ */ jsx(EmbeddedStatus, {
title: i18n.get("addBankAccount"),
iconName: "plus",
light: true,
onClick: () => onAdd(legalEntityId),
"aria-label": i18n.get("addBankAccount")
})]
});
}
//#endregion
//#region src/components/EmbeddedDropins/ManageTransferInstrumentComponent/ManageTransferInstrumentComponent.tsx
var REFETCH_INTERVAL = 3e3;
var logger = createLogger();
function ManageTransferInstrumentComponent({ legalEntityId, onAdd, onEdit, onInitiateRemove, onRemoveSuccess }) {
const { rootLegalEntityId: currentLegalEntityId } = useApiContext();
currentLegalEntityId.value = legalEntityId;
const { i18n } = useI18nContext();
const { i18n: i18next } = useTranslation(["common", "banking"]);
const { showToast } = useToastContext();
const { mutateAsync: deleteTransferInstrument } = useDeleteTransferInstrument();
addResourceBundles(i18next, [
{
ns: "common",
importFn: (lang) => _rolldown_dynamic_import_helper_default(/* @__PURE__ */ Object.assign({
"../../../language/locales/bg-BG.json": () => import("./bg-BG-COHRuTI-.js"),
"../../../language/locales/cs-CZ.json": () => import("./cs-CZ-CmcYZLZp.js"),
"../../../language/locales/da-DK.json": () => import("./da-DK-C_oe1bpM.js"),
"../../../language/locales/de-DE.json": () => import("./de-DE-CMc1Fpfl.js"),
"../../../language/locales/el-GR.json": () => import("./el-GR-Bv2QgmVV.js"),
"../../../language/locales/en-US.instructions.json": () => import("./en-US.instructions-DJharl6b.js"),
"../../../language/locales/en-US.json": () => import("./en-US-cJAmQhFR.js").then((n) => n.n),
"../../../language/locales/es-ES.json": () => import("./es-ES-DtlXpZ_5.js"),
"../../../language/locales/et-EE.json": () => import("./et-EE-PTcJ2hRW.js"),
"../../../language/locales/fi-FI.json": () => import("./fi-FI-C1Ns3CEo.js"),
"../../../language/locales/fr-FR.json": () => import("./fr-FR-DgPRYmmJ.js"),
"../../../language/locales/hr-HR.json": () => import("./hr-HR-BQfjrcPC.js"),
"../../../language/locales/hu-HU.json": () => import("./hu-HU-DfYPelYo.js"),
"../../../language/locales/it-IT.json": () => import("./it-IT-cnETv3Cg.js"),
"../../../language/locales/ja-JP.json": () => import("./ja-JP-D0gz56Ni.js"),
"../../../language/locales/lt-LT.json": () => import("./lt-LT-Bbh9MWxc.js"),
"../../../language/locales/lv-LV.json": () => import("./lv-LV-C8fqHR2g.js"),
"../../../language/locales/nl-NL.json": () => import("./nl-NL-CQSu4iNn.js"),
"../../../language/locales/no-NO.json": () => import("./no-NO-C0DXekH-.js"),
"../../../language/locales/pl-PL.json": () => import("./pl-PL-10KUcobm.js"),
"../../../language/locales/pt-BR.json": () => import("./pt-BR-DWKF33yP.js"),
"../../../language/locales/pt-PT.json": () => import("./pt-PT-CjIFIi4R.js"),
"../../../language/locales/ro-RO.json": () => import("./ro-RO-DQFRJwp8.js"),
"../../../language/locales/sk-SK.json": () => import("./sk-SK-BfoXFhAL.js"),
"../../../language/locales/sl-SI.json": () => import("./sl-SI-CyIN1sc5.js"),
"../../../language/locales/sv-SE.json": () => import("./sv-SE-Xh17T6yC.js")
}), `../../../language/locales/${lang}.json`, 6)
},
{
ns: "ui",
importFn: (lang) => _rolldown_dynamic_import_helper_default(/* @__PURE__ */ Object.assign({
"../../ui/language/bg-BG.json": () => import("./bg-BG-BUBUyZgz.js"),
"../../ui/language/cs-CZ.json": () => import("./cs-CZ-BFJyFYpX.js"),
"../../ui/language/da-DK.json": () => import("./da-DK-BNvIcL59.js"),
"../../ui/language/de-DE.json": () => import("./de-DE-B8Eby_UK.js"),
"../../ui/language/el-GR.json": () => import("./el-GR-DYmDnzZe.js"),
"../../ui/language/en-US.json": () => import("./en-US-Mma5wIWL.js"),
"../../ui/language/es-ES.json": () => import("./es-ES-DLBRDQJZ.js"),
"../../ui/language/et-EE.json": () => import("./et-EE-C_Z4PWda.js"),
"../../ui/language/fi-FI.json": () => import("./fi-FI-azwPyx-k.js"),
"../../ui/language/fr-FR.json": () => import("./fr-FR-CzdHSH04.js"),
"../../ui/language/hr-HR.json": () => import("./hr-HR-C7Hp8OgD.js"),
"../../ui/language/hu-HU.json": () => import("./hu-HU-B34uBEZ9.js"),
"../../ui/language/it-IT.json": () => import("./it-IT-BCqVu72_.js"),
"../../ui/language/ja-JP.json": () => import("./ja-JP-C7_6K98B.js"),
"../../ui/language/lt-LT.json": () => import("./lt-LT-BhzsTniu.js"),
"../../ui/language/lv-LV.json": () => import("./lv-LV-B6yxwa6Z.js"),
"../../ui/language/nl-NL.json": () => import("./nl-NL-4iZ44kzK.js"),
"../../ui/language/no-NO.json": () => import("./no-NO-BSJ1rjY4.js"),
"../../ui/language/pl-PL.json": () => import("./pl-PL-BHjlKdWC.js"),
"../../ui/language/pt-BR.json": () => import("./pt-BR-BMIZHo3V.js"),
"../../ui/language/pt-PT.json": () => import("./pt-PT-s_KcBKav.js"),
"../../ui/language/ro-RO.json": () => import("./ro-RO-DsFmqo3p.js"),
"../../ui/language/sk-SK.json": () => import("./sk-SK-BspZv60l.js"),
"../../ui/language/sl-SI.json": () => import("./sl-SI-D26FDPwq.js"),
"../../ui/language/sv-SE.json": () => import("./sv-SE-JKGeqd9J.js")
}), `../../ui/language/${lang}.json`, 5)
},
{
ns: "banking",
importFn: (lang) => _rolldown_dynamic_import_helper_default(/* @__PURE__ */ Object.assign({
"../../BankAccount/language/bg-BG.json": () => import("./bg-BG-Bayyn2Vj.js"),
"../../BankAccount/language/cs-CZ.json": () => import("./cs-CZ-DlGWvcHs.js"),
"../../BankAccount/language/da-DK.json": () => import("./da-DK-FIY6i3zy.js"),
"../../BankAccount/language/de-DE.json": () => import("./de-DE-DLQs11Hz.js"),
"../../BankAccount/language/el-GR.json": () => import("./el-GR-no-mXzHz.js"),
"../../BankAccount/language/en-US.json": () => import("./en-US-f2kgWe84.js"),
"../../BankAccount/language/es-ES.json": () => import("./es-ES-BUSxmdKa.js"),
"../../BankAccount/language/et-EE.json": () => import("./et-EE-9bkSuMa4.js"),
"../../BankAccount/language/fi-FI.json": () => import("./fi-FI-whtJ_DRy.js"),
"../../BankAccount/language/fr-FR.json": () => import("./fr-FR-SabLrXSF.js"),
"../../BankAccount/language/hr-HR.json": () => import("./hr-HR-C7vNP6kG.js"),
"../../BankAccount/language/hu-HU.json": () => import("./hu-HU-DBqKyuYs.js"),
"../../BankAccount/language/it-IT.json": () => import("./it-IT-jTdy1a4s.js"),
"../../BankAccount/language/ja-JP.json": () => import("./ja-JP-qs4tLgRF.js"),
"../../BankAccount/language/lt-LT.json": () => import("./lt-LT-BCqnP7r6.js"),
"../../BankAccount/language/lv-LV.json": () => import("./lv-LV-BEtE7iP6.js"),
"../../BankAccount/language/nl-NL.json": () => import("./nl-NL-HAKt4Uc5.js"),
"../../BankAccount/language/no-NO.json": () => import("./no-NO-ChSdsuYY.js"),
"../../BankAccount/language/pl-PL.json": () => import("./pl-PL-YNg08-Ol.js"),
"../../BankAccount/language/pt-BR.json": () => import("./pt-BR-BnDcVpJT.js"),
"../../BankAccount/language/pt-PT.json": () => import("./pt-PT-tt1J0yv6.js"),
"../../BankAccount/language/ro-RO.json": () => import("./ro-RO-CRHBNotW.js"),
"../../BankAccount/language/sk-SK.json": () => import("./sk-SK-BJxKfous.js"),
"../../BankAccount/language/sl-SI.json": () => import("./sl-SI-B9zMw3uZ.js"),
"../../BankAccount/language/sv-SE.json": () => import("./sv-SE-BgyicZrq.js")
}), `../../BankAccount/language/${lang}.json`, 5)
}
]);
const { data: transferInstrumentReferences, isLoading, isError } = useTransferInstruments({
refetchOnMount: "always",
refetchInterval: (query) => query.state.data?.every(({ status }) => status === "FINISHED") ? 0 : REFETCH_INTERVAL
});
useDataset(datasetIdentifier.country);
const onRemove = async (transferInstrumentId) => {
try {
await deleteTransferInstrument(transferInstrumentId);
onRemoveSuccess?.(transferInstrumentId, legalEntityId);
} catch (e) {
showToast({
label: i18n.get("thereWasAnErrorTryAgain"),
variant: "error"
});
logger.error(e);
}
};
const render = () => {
if (isLoading) return /* @__PURE__ */ jsx(EmbeddedStatus, { loading: true });
if (isError) return /* @__PURE__ */ jsx(Alert, {
title: i18n.get("sorryAnErrorOccurred"),
variant: "error"
});
return /* @__PURE__ */ jsxs(Fragment, { children: [!transferInstrumentReferences?.length && /* @__PURE__ */ jsxs("div", {
className: "adyen-kyc-u-margin-bottom-12",
children: [/* @__PURE__ */ jsx(Typography, {
el: "h1",
variant: "title-l",
children: i18n.get("bankDetails")
}), /* @__PURE__ */ jsx(Typography, { children: i18n.get("addMissingBankDetails") })]
}), /* @__PURE__ */ jsx(ManageTransferInstrumentOverview, {
transferInstrumentReferences,
onEdit: (transferInstrumentId) => onEdit(transferInstrumentId, legalEntityId),
onRemove,
onInitiateRemove,
onAdd,
legalEntityId
})] });
};
return /* @__PURE__ */ jsx("div", {
className: "adyen-kyc-manage-transfer-instrument",
children: render()
});
}
//#endregion
//#region src/embeds/transfer-instrument-management/adyen-transfer-instrument-management.tsx
var AdyenManageTransferInstruments = ({ rootlegalentityid, fetchToken, environment, locale, settings = {}, experiments = {} }) => {
const eventEmitterRef = useRef(null);
const handleOnAdd = (rootLegalEntityId) => {
emitAdyenSdkEvent(eventEmitterRef, "add", rootLegalEntityId);
};
const handleOnEdit = (transferInstrumentId) => {
emitAdyenSdkEvent(eventEmitterRef, "edit", transferInstrumentId);
};
const handleOnRemove = (transferInstrumentId) => {
emitAdyenSdkEvent(eventEmitterRef, "remove", transferInstrumentId);
};
return /* @__PURE__ */ jsx("div", {
ref: eventEmitterRef,
style: "width:100%;",
children: /* @__PURE__ */ jsx(EmbedShell, {
componentName: "adyen-transfer-instrument-management",
rootLegalEntityId: rootlegalentityid,
settings,
features: experiments,
getSdkToken: fetchToken,
locale,
baseUrl: resolveEnvironment(environment),
children: /* @__PURE__ */ jsx(ManageTransferInstrumentComponent, {
legalEntityId: rootlegalentityid,
onAdd: handleOnAdd,
onEdit: handleOnEdit,
onRemoveSuccess: handleOnRemove
})
})
});
};
register(AdyenManageTransferInstruments, "adyen-transfer-instrument-management", [
"rootlegalentityid",
"fetchToken",
"environment",
"locale",
"settings",
"experiments"
], {
shadow: true,
adoptedStyleSheets: stylesheets
});
//#endregion