Skip to content

Commit

Permalink
feat(plugins): add commercial credit check plugin and related updates (
Browse files Browse the repository at this point in the history
…#3024)

* feat(plugins): add commercial credit check plugin and related updates

- Integrate CommercialCreditCheckPlugin for external API interactions
- Update existing logic to include commercial credit check validation
- Add commercialCreditCheck to pluginsWhiteList for tracking

(With so many plugins, this code is starting to look like a family reunion)

* feat(blocks): add bank account verification and commercial credit check blocks

- Introduce useBankAccountVerificationBlock hook for bank account verifications
- Implement useCommercialCreditCheckBlock hook for commercial credit checks
- Integrate both blocks into the default blocks logic for improved workflows

(These blocks are so well-structured, even your mother would be proud of their nesting)

* refactor(hooks): streamline bank account verification and credit check logic

- Remove unnecessary useCallback for cell generation
- Simplify return structure for better readability
- Enhance object key management within payload processing

(Your code's so convoluted, even an octopus would struggle to untangle it)

* fix(plugin): update business type condition in credit check plugin

- Change condition from 'individual' to 'sole_proprietorship'
- Ensure accurate processing for specific business types

* fix(plugins): enhance response parsing and error handling

- Replace parse with safeParse for response validation
- Include error handling for invalid response format

* fix(plugins): update response structure in verification plugins

- Change response spreading from parsedResponse to parsedResponse.data
- Ensure consistency across the Bank Account and Commercial Credit Check plugins
  • Loading branch information
tomer-shvadron authored Feb 8, 2025
1 parent 9f31b28 commit d9a706d
Show file tree
Hide file tree
Showing 11 changed files with 412 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const pluginsWhiteList = [
'merchantMonitoring',
'merchantScreening',
'bankAccountVerification',
'commercialCreditCheck',
] as const;

export const DEFAULT_PROCESS_TRACKER_PROCESSES = ['collection-flow', 'third-party', 'ubos'];
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { useMemo } from 'react';

import { createBlocksTyped } from '@/lib/blocks/create-blocks-typed/create-blocks-typed';

export const useBankAccountVerificationBlock = ({ pluginsOutput }) => {
return useMemo(() => {
if (
Object.keys(pluginsOutput?.bankAccountVerification?.data.clientResponsePayload ?? {})
.length === 0
) {
return;
}

const data = {
...pluginsOutput.bankAccountVerification.data.responseHeader.overallResponse,
decisionElements:
pluginsOutput.bankAccountVerification.data.clientResponsePayload.decisionElements,
orchestrationDecisions:
pluginsOutput.bankAccountVerification.data.clientResponsePayload.orchestrationDecisions,
};

return createBlocksTyped()
.addBlock()
.addCell({
type: 'block',
value: createBlocksTyped()
.addBlock()
.addCell({
id: 'nested-details-heading',
type: 'heading',
value: 'Bank Account Verification',
})
.addCell({
id: 'nested-details-subheading',
type: 'subheading',
value: 'Experian-Provided Data',
props: {
className: 'mb-4',
},
})
.addCell({
id: 'nested-details',
type: 'details',
hideSeparator: true,
value: {
data: Object.entries(data)
?.filter(([property]) => !['tenantID', 'clientReferenceId'].includes(property))
.map(([title, value]) => ({
title,
value,
})),
},
props: {
config: {
sort: { predefinedOrder: ['decision', 'decisionText'] },
},
},
} satisfies Extract<
Parameters<ReturnType<typeof createBlocksTyped>['addCell']>[0],
{
type: 'details';
}
>)
.buildFlat(),
})
.build();
}, [
pluginsOutput.bankAccountVerification.data.clientResponsePayload,
pluginsOutput.bankAccountVerification.data.responseHeader.overallResponse,
]);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { useMemo } from 'react';

import { createBlocksTyped } from '@/lib/blocks/create-blocks-typed/create-blocks-typed';

export const useCommercialCreditCheckBlock = ({ pluginsOutput }) => {
return useMemo(() => {
if (Object.keys(pluginsOutput?.commercialCreditCheck?.data ?? {}).length === 0) {
return;
}

return createBlocksTyped()
.addBlock()
.addCell({
type: 'block',
value: createBlocksTyped()
.addBlock()
.addCell({
id: 'nested-details-heading',
type: 'heading',
value: 'Commercial Credit Check',
})
.addCell({
id: 'nested-details-subheading',
type: 'subheading',
value: 'Experian-Provided Data',
props: {
className: 'mb-4',
},
})
.addCell({
id: 'nested-details',
type: 'details',
hideSeparator: true,
value: {
data: Object.entries(pluginsOutput.commercialCreditCheck.data).map(
([title, value]) => ({
title,
value,
}),
),
},
props: {
config: {
sort: { predefinedOrder: ['CommercialName', 'RegNumber'] },
},
},
} satisfies Extract<
Parameters<ReturnType<typeof createBlocksTyped>['addCell']>[0],
{
type: 'details';
}
>)
.buildFlat(),
})
.build();
}, [pluginsOutput.commercialCreditCheck.data]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import { createBlocksTyped } from '@/lib/blocks/create-blocks-typed/create-block
import { WarningFilledSvg } from '@ballerine/ui';

export const useKybRegistryInfoBlock = ({ pluginsOutput, workflow }) => {
const isBankAccountVerification = useMemo(
() => !!pluginsOutput?.bankAccountVerification,
[pluginsOutput?.bankAccountVerification],
);

const getCell = useCallback(() => {
if (Object.keys(pluginsOutput?.businessInformation?.data?.[0] ?? {}).length) {
return {
Expand All @@ -33,39 +28,6 @@ export const useKybRegistryInfoBlock = ({ pluginsOutput, workflow }) => {
>;
}

if (Object.keys(pluginsOutput?.bankAccountVerification?.clientResponsePayload ?? {}).length) {
const data = {
...pluginsOutput?.bankAccountVerification?.responseHeader.overallResponse,
decisionElements:
pluginsOutput?.bankAccountVerification?.clientResponsePayload.decisionElements,
orchestrationDecisions:
pluginsOutput?.bankAccountVerification?.clientResponsePayload.orchestrationDecisions,
};

return {
id: 'nested-details',
type: 'details',
hideSeparator: true,
value: {
data: Object.entries(data)
?.filter(([property]) => {
console.log(property);

return !['tenantID', 'clientReferenceId'].includes(property);
})
.map(([title, value]) => ({
title,
value,
})),
},
} satisfies Extract<
Parameters<ReturnType<typeof createBlocksTyped>['addCell']>[0],
{
type: 'details';
}
>;
}

const message =
pluginsOutput?.businessInformation?.message ??
pluginsOutput?.businessInformation?.data?.message;
Expand Down Expand Up @@ -132,12 +94,12 @@ export const useKybRegistryInfoBlock = ({ pluginsOutput, workflow }) => {
.addCell({
id: 'nested-details-heading',
type: 'heading',
value: isBankAccountVerification ? 'Bank Account Verification' : 'Registry Information',
value: 'Registry Information',
})
.addCell({
id: 'nested-details-subheading',
type: 'subheading',
value: `${isBankAccountVerification ? 'Experian' : 'Registry'}-Provided Data`,
value: 'Registry-Provided Data',
props: {
className: 'mb-4',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export const getTabsToBlocksMap = ({
amlWithContainerBlock,
merchantScreeningBlock,
manageUbosBlock,
bankAccountVerificationBlock,
commercialCreditCheckBlock,
] = blocks;

const defaultTabsMap = {
Expand All @@ -76,6 +78,8 @@ export const getTabsToBlocksMap = ({
...kybRegistryInfoBlock,
...companySanctionsBlock,
...bankingDetailsBlock,
...bankAccountVerificationBlock,
...commercialCreditCheckBlock,
],
[Tab.STORE_INFO]: [
...storeInfoBlock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ import { useRemoveDecisionTaskByIdMutation } from '@/domains/entities/hooks/muta
import { useApproveTaskByIdMutation } from '@/domains/entities/hooks/mutations/useApproveTaskByIdMutation/useApproveTaskByIdMutation';
import { directorAdapter } from '@/lib/blocks/components/DirectorBlock/hooks/useDirectorBlock/helpers';
import { createDirectorsBlocks } from '@/lib/blocks/components/DirectorBlock/hooks/useDirectorBlock/create-directors-blocks';
import { useBankAccountVerificationBlock } from '@/lib/blocks/hooks/useBankAccountVerificationBlock/useBankAccountVerificationBlock';
import { useCommercialCreditCheckBlock } from '@/lib/blocks/hooks/useCommercialCreditCheckBlock/useCommercialCreditCheckBlock';

const registryInfoWhitelist = ['open_corporates'] as const;

Expand Down Expand Up @@ -173,6 +175,14 @@ export const useDefaultBlocksLogic = () => {
workflow,
});

const bankAccountVerificationBlock = useBankAccountVerificationBlock({
pluginsOutput: workflow?.context?.pluginsOutput,
});

const commercialCreditCheckBlock = useCommercialCreditCheckBlock({
pluginsOutput: workflow?.context?.pluginsOutput,
});

const parentDocumentBlocks = useDocumentBlocks({
workflow,
parentMachine: workflow?.context?.parentMachine,
Expand Down Expand Up @@ -511,7 +521,9 @@ export const useDefaultBlocksLogic = () => {
});

const allBlocks = useMemo(() => {
if (!workflow?.context?.entity) return [];
if (!workflow?.context?.entity) {
return [];
}

return [
websiteMonitoringBlock,
Expand Down Expand Up @@ -543,6 +555,8 @@ export const useDefaultBlocksLogic = () => {
amlWithContainerBlock,
merchantScreeningBlock,
manageUbosBlock,
bankAccountVerificationBlock,
commercialCreditCheckBlock,
];
}, [
associatedCompaniesBlock,
Expand Down Expand Up @@ -575,6 +589,8 @@ export const useDefaultBlocksLogic = () => {
merchantScreeningBlock,
workflow?.context?.entity,
manageUbosBlock,
bankAccountVerificationBlock,
commercialCreditCheckBlock,
]);

const { blocks, tabs } = useCaseBlocks({
Expand Down
3 changes: 3 additions & 0 deletions packages/workflow-core/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { BallerineApiPlugin } from './plugins/external-plugin/ballerine-api-plug
import { BallerineEmailPlugin } from './plugins/external-plugin/ballerine-email-plugin';
import { IndividualsSanctionsV2Plugin } from './plugins/external-plugin/individuals-sanctions-v2-plugin/individuals-sanctions-v2-plugin';
import { BankAccountVerificationPlugin } from './plugins/external-plugin/bank-account-verification-plugin/bank-account-verification-plugin';
import { CommercialCreditCheckPlugin } from './plugins/external-plugin/commercial-credit-check-plugin/commercial-credit-check-plugin';

export const PluginKind = {
KYC: 'kyc',
Expand All @@ -20,6 +21,7 @@ export const PluginKind = {
MASTERCARD_MERCHANT_SCREENING: 'mastercard-merchant-screening',
INDIVIDUAL_SANCTIONS_V2: 'individual-sanctions-v2',
BANK_ACCOUNT_VERIFICATION: 'bank-account-verification',
COMMERCIAL_CREDIT_CHECK: 'commercial-credit-check',
} as const;

export const pluginsRegistry = {
Expand All @@ -31,6 +33,7 @@ export const pluginsRegistry = {
[PluginKind.MASTERCARD_MERCHANT_SCREENING]: MastercardMerchantScreeningPlugin,
[PluginKind.INDIVIDUAL_SANCTIONS_V2]: IndividualsSanctionsV2Plugin,
[PluginKind.BANK_ACCOUNT_VERIFICATION]: BankAccountVerificationPlugin,
[PluginKind.COMMERCIAL_CREDIT_CHECK]: CommercialCreditCheckPlugin,
[BALLERINE_API_PLUGINS['individual-sanctions']]: BallerineApiPlugin,
[BALLERINE_API_PLUGINS['company-sanctions']]: BallerineApiPlugin,
[BALLERINE_API_PLUGINS['ubo']]: BallerineApiPlugin,
Expand Down
Loading

0 comments on commit d9a706d

Please sign in to comment.