Skip to content

Commit

Permalink
add commercial registration endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
UgurGumushan committed Sep 17, 2024
1 parent ef4e075 commit 81d83ea
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down
32 changes: 32 additions & 0 deletions src/fixtures/businesses.ts
Original file line number Diff line number Diff line change
@@ -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",
],
},
];
144 changes: 144 additions & 0 deletions src/routes/commercialRegistrations.ts
Original file line number Diff line number Diff line change
@@ -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<SearchByNameResponseBody | ModelNotFoundError>
) => {
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<SearchByNameResponseBody | ModelNotFoundError>
) => {
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);
}
};

0 comments on commit 81d83ea

Please sign in to comment.