From 81d83ea37941abe6678556a8cd29ed5f10cfe80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20G=C3=BCm=C3=BC=C5=9Fhan?= Date: Tue, 17 Sep 2024 18:36:09 +0300 Subject: [PATCH] add commercial registration endpoints --- src/app.ts | 13 +++ src/fixtures/businesses.ts | 32 ++++++ src/routes/commercialRegistrations.ts | 144 ++++++++++++++++++++++++++ 3 files changed, 189 insertions(+) create mode 100644 src/fixtures/businesses.ts create mode 100644 src/routes/commercialRegistrations.ts diff --git a/src/app.ts b/src/app.ts index cd6870b36b..bf1a6e1b9b 100644 --- a/src/app.ts +++ b/src/app.ts @@ -42,6 +42,7 @@ import { shouldReturnJSON } from "./helpers"; import { CardStatus } from "./helpers/types"; import { createStripeCustomerIfNotExistsMiddleware } from "./helpers/stripe"; import * as questionsAPI from "./routes/questions"; +import { find, searchByName } from "./routes/commercialRegistrations"; const app = express(); const fileUpload = multer(); @@ -849,6 +850,18 @@ router.get( safeRequestHandler(accountOpeningRequestAPI.retrieveAccountOpeningRequest) ); +// COMMERCIAL REGISTRATIONS + +router.get( + "/commercial_registrations/search_by_name", + safeRequestHandler(searchByName) +); + +/** + * This endpoint has an associated cost per request. Contact your Partner Manager for more information. + */ +router.get("/commercial_registrations/find", safeRequestHandler(find)); + app.post( "/__BACKOFFICE__/createMaps", safeRequestHandler(backofficeAPI.createMaps) diff --git a/src/fixtures/businesses.ts b/src/fixtures/businesses.ts new file mode 100644 index 0000000000..643d27c99a --- /dev/null +++ b/src/fixtures/businesses.ts @@ -0,0 +1,32 @@ +import { Business } from "../routes/commercialRegistrations"; + +export const businesses: Business[] = [ + { + name: "FLOOR 13 GmbH", + address: { + country: "DE", + postal_code: "86919", + city: "Utting a.Ammersee", + line_1: "Seestraße 9", + line_2: "", + }, + legal_form: "GMBH", + tax_country: "DE", + registration_number: "HRB 198673", + registration_issuer: "AMTSGERICHT MÜNCHEN", + registration_date: "2012-05-09", + registry_updated_at: "2015-11-17", + legal_representatives: [ + { + first_name: "Stefan", + last_name: "Schneider", + }, + ], + commercial_registry_industry_key: [ + "66190 - Sonstige mit Finanzdienstleistungen verbundene Tätigkeiten", + "70109 - Sonstige Verwaltung und Führung von Unternehmen und Betrieben", + "70220 - Unternehmensberatung", + "73110 - Werbeagenturen", + ], + }, +]; diff --git a/src/routes/commercialRegistrations.ts b/src/routes/commercialRegistrations.ts new file mode 100644 index 0000000000..c6231e274f --- /dev/null +++ b/src/routes/commercialRegistrations.ts @@ -0,0 +1,144 @@ +import type { Request, Response } from "express"; +import { businesses } from "../fixtures/businesses"; + +export type SearchByNameResponseBody = { + name: string; + registration_number: string; + /** + * Only required for companies in Germany + */ + registration_issuer?: string; +}; + +export type Country = string | "DE"; +export type LegalForm = string | "GMBH"; + +export type BusinessAddress = { + country: Country; + postal_code: string; + city: string; + line_1: string; + line_2: string; +}; + +export type SearchByNameQuery = { + country: string; + name: string; +}; + +export type LegalRepresentative = { + first_name: string; + last_name: string; +}; + +/** + * This is used for samples + */ +export type Business = { + name: string; + address: BusinessAddress; + legal_form: LegalForm; + tax_country: Country; + registration_number: string; + registration_issuer: string; + /** + * YYYY-MM_DD + */ + registration_date: string; + /** + * YYYY-MM_DD + */ + registry_updated_at: string; + legal_representatives: LegalRepresentative[]; + commercial_registry_industry_key: string[]; +}; + +export type findQuery = { + registration_number: string; + registration_issuer: string; +}; + +export type ModelNotFoundError = { + title: string | "Model Not Found"; + status: string | "404"; + id: string; + detail: string; + code: string | "model_not_found"; +}; + +/** + * Note: This endpoint may be used free of charge. + * + * Returns some business as if it exists + * Returns a mock business if more than 2 characters are provided for country and name + */ +export const searchByName = async ( + req: Request<{}, {}, {}, SearchByNameQuery>, + res: Response +) => { + const { country = "DE", name } = req.query; + const foundBusiness = businesses.find( + (business) => business.name === name && business.address.country === country + ); + const highEffort = String(country).length + String(name).length > 2; + + if (foundBusiness) { + return res.status(200).send(foundBusiness); + } else if (highEffort) { + const mockBusiness: Business = { + ...businesses[0], + name, + address: { ...businesses[0].address, country }, + }; + return res.status(200).send(mockBusiness); + } else { + const errorResponse: ModelNotFoundError = { + title: "Model Not Found", + status: "404", + code: "model_not_found", + detail: "someString", + id: "someString", + }; + return res.status(404).send(errorResponse); + } +}; + +/** + * @see {@link https://docs.solarisgroup.com/guides/kyc/bkyc/#automatic-data-collection-optional} + * Notes: + * This endpoint has an associated cost per request. Contact your Partner Manager for more information. + * For companies in Germany, you must add AMTSGERICHT before the value of the registration_issuer, e.g., AMTSGERICHT MÜNCHEN. + */ +export const find = ( + req: Request<{}, {}, {}, findQuery>, + res: Response +) => { + const { registration_number, registration_issuer } = req.query; + const foundBusiness = businesses.find( + (business) => + business.registration_number === registration_number && + business.registration_issuer === registration_issuer + ); + + const highEffort = + String(registration_number).length + String(registration_issuer).length > 2; + if (foundBusiness) { + return res.status(200).send(foundBusiness); + } else if (highEffort) { + const mockBusiness: Business = { + ...businesses[0], + registration_number, + registration_issuer, + }; + return res.status(200).send(mockBusiness); + } else { + const errorResponse: ModelNotFoundError = { + title: "Model Not Found", + status: "404", + code: "model_not_found", + detail: "someString", + id: "someString", + }; + return res.status(404).send(errorResponse); + } +};