diff --git a/_base/src/pages/api/onboard.ts b/_base/src/pages/api/onboard.ts index 77402576..206e87c7 100644 --- a/_base/src/pages/api/onboard.ts +++ b/_base/src/pages/api/onboard.ts @@ -3,12 +3,15 @@ import Stripe from "stripe"; import { apiResponse } from "src/types/api-response"; import FinancialProduct from "src/types/financial-product"; -import { - CountryConfigMap, - SupportedCountry, -} from "src/utils/account-management-helpers"; +import { CountryConfigMap } from "src/utils/account-management-helpers"; import { handlerMapping } from "src/utils/api-helpers"; -import { isDemoMode, TOS_ACCEPTANCE } from "src/utils/demo-helpers"; +import { + isDemoMode, + TOS_ACCEPTANCE, + getStaticFakeCompanyTaxIdNumberByCountry, + getStaticFakePhoneByCountry, + getStaticFakeAddressByCountry, +} from "src/utils/demo-helpers"; import { createAccountOnboardingUrl } from "src/utils/onboarding-helpers"; import { getSessionForServerSide } from "src/utils/session-helpers"; import stripeClient from "src/utils/stripe-loader"; @@ -80,26 +83,11 @@ const onboard = async (req: NextApiRequest, res: NextApiResponse) => { }, company: { name: businessName, - // Fake business TIN: https://stripe.com/docs/connect/testing#test-business-tax-ids - tax_id: "000000000", + tax_id: getStaticFakeCompanyTaxIdNumberByCountry(country), }, individual: { address: { - // This value causes the address to be verified in testmode: https://stripe.com/docs/connect/testing#test-verification-addresses - line1: "address_full_match", - // @if financialProduct==embedded-finance - ...(country === SupportedCountry.US && { - city: "South San Francisco", - state: "CA", - postal_code: "94080", - }), - // @endif - // @if financialProduct==expense-management - ...(country === SupportedCountry.UK && { - city: "London", - postal_code: "WC32 4AP", - }), - // @endif + ...getStaticFakeAddressByCountry(country), country: country.toString(), }, // These values together cause the DOB to be verified in testmode: https://stripe.com/docs/connect/testing#test-dobs @@ -111,8 +99,7 @@ const onboard = async (req: NextApiRequest, res: NextApiResponse) => { email: email, first_name: "John", last_name: "Smith", - // Fake phone number: https://docs.stripe.com/connect/testing#using-oauth - phone: "000-000-0000", + phone: getStaticFakePhoneByCountry(country), }, ...(skipOnboarding && { tos_acceptance: TOS_ACCEPTANCE }), // Faking Terms of Service acceptances diff --git a/_base/src/utils/demo-helpers.ts b/_base/src/utils/demo-helpers.ts index 17ab8ea4..0e42fbff 100644 --- a/_base/src/utils/demo-helpers.ts +++ b/_base/src/utils/demo-helpers.ts @@ -65,6 +65,170 @@ export const LocalizedFakerMap: Record = { // @endif }; +// These are a hardcoded list of company tax ID numbers for each country that Stripe will accept as a valid test number +// Stripe docs for test company tax ID numbers: https://stripe.com/docs/connect/testing#test-business-tax-ids +export const getStaticFakeCompanyTaxIdNumberByCountry = ( + country: SupportedCountry, +): string => { + switch (country) { + // @if financialProduct==expense-management + case SupportedCountry.AT: + case SupportedCountry.BE: + case SupportedCountry.CY: + case SupportedCountry.EE: + case SupportedCountry.ES: + case SupportedCountry.FI: + case SupportedCountry.FR: + case SupportedCountry.GR: + case SupportedCountry.HR: + case SupportedCountry.IE: + case SupportedCountry.IT: + case SupportedCountry.LT: + case SupportedCountry.LU: + case SupportedCountry.LV: + case SupportedCountry.MT: + case SupportedCountry.NL: + case SupportedCountry.PT: + case SupportedCountry.SI: + case SupportedCountry.SK: + case SupportedCountry.UK: + return "000000000"; // All other EEA countries besides Germany + case SupportedCountry.DE: + return "HRA000000000"; // Germany + // @endif + // @if financialProduct==embedded-finance + case SupportedCountry.US: + return "000000000"; // United States + // @endif + default: + throw new Error( + `Fake phone number generation not implemented for country: ${country}`, + ); + } +}; + +// These are a hardcoded list of fake phone numbers for each country that Stripe will accept as a valid test number +// Stripe docs for test phone numbers: https://docs.stripe.com/connect/testing#using-oauth +export const getStaticFakePhoneByCountry = ( + country: SupportedCountry, +): string => { + const faker = LocalizedFakerMap[country] as Faker; + + switch (country) { + // @if financialProduct==expense-management + case SupportedCountry.AT: + return faker.phone.number("+43(#)000 0000"); // Austria + case SupportedCountry.BE: + return faker.phone.number("+32(0)00 00 00 00"); // Belgium + case SupportedCountry.CY: + return faker.phone.number("+357(9)0 000 000"); // Cyprus + case SupportedCountry.DE: + return faker.phone.number("+49(0)0000 00000"); // Germany + case SupportedCountry.EE: + return faker.phone.number("+372 000 0000"); // Estonia + case SupportedCountry.ES: + return faker.phone.number("+34(91)000 0000"); // Spain + case SupportedCountry.FI: + return faker.phone.number("+358(0)00 000 0000"); // Finland + case SupportedCountry.FR: + return faker.phone.number("+33(0)00 00 00 00"); // France + case SupportedCountry.GR: + return faker.phone.number("+30(0)000 0000 000"); // Greece + case SupportedCountry.HR: + return faker.phone.number("+385 43 000 000"); // Croatia + case SupportedCountry.IE: + return faker.phone.number("+353(0)00 000 0000"); // Ireland + case SupportedCountry.IT: + return faker.phone.number("+39(000) 000 0000"); // Italy + case SupportedCountry.LT: + return faker.phone.number("+370(0)00 000000"); // Lithuania + case SupportedCountry.LU: + return faker.phone.number("+352 000 000"); // Luxeumburg + case SupportedCountry.LV: + return faker.phone.number("+371(2) 000 0000"); // Latvia + case SupportedCountry.MT: + return faker.phone.number("+356 0000 0000"); // Malta + case SupportedCountry.NL: + return faker.phone.number("+31 (06) 0000 0000"); // Netherland + case SupportedCountry.PT: + return faker.phone.number("+351 200 000 000"); // Portugal + case SupportedCountry.SI: + return faker.phone.number("+386(0)000 00 00"); // Slovenia + case SupportedCountry.SK: + return faker.phone.number("+386(0)000 00 00"); // Slovakia + case SupportedCountry.UK: + return faker.phone.number("07000000000"); // United Kingdom + // @endif + // @if financialProduct==embedded-finance + case SupportedCountry.US: + return faker.phone.number("000-000-0000"); // United States + // @endif + default: + throw new Error( + `Fake phone number generation not implemented for country: ${country}`, + ); + } +}; + +export const getFakePhoneByCountry = (country: SupportedCountry): string => { + const faker = LocalizedFakerMap[country] as Faker; + + switch (country) { + // @if financialProduct==expense-management + case SupportedCountry.AT: + return faker.phone.number("+43(#)### ####"); // Austria + case SupportedCountry.BE: + return faker.phone.number("+32(#)## ## ## ##"); // Belgium + case SupportedCountry.CY: + return faker.phone.number("+357(9)# ### ###"); // Cyprus + case SupportedCountry.DE: + return faker.phone.number("+49(#)#### #####"); // Germany + case SupportedCountry.EE: + return faker.phone.number("+372 ### ####"); // Estonia + case SupportedCountry.ES: + return faker.phone.number("+34(91)### ####"); // Spain + case SupportedCountry.FI: + return faker.phone.number("+358(#)## ### ####"); // Finland + case SupportedCountry.FR: + return faker.phone.number("+33(#)## ## ## ##"); // France + case SupportedCountry.GR: + return faker.phone.number("+30(#)### #### ###"); // Greece + case SupportedCountry.HR: + return faker.phone.number("+385 43 ### ###"); // Croatia + case SupportedCountry.IE: + return faker.phone.number("+353(#)## ### ####"); // Ireland + case SupportedCountry.IT: + return faker.phone.number("+39(###) ### ####"); // Italy + case SupportedCountry.LT: + return faker.phone.number("+370(#)## ######"); // Lithuania + case SupportedCountry.LU: + return faker.phone.number("+352 ### ###"); // Luxeumburg + case SupportedCountry.LV: + return faker.phone.number("+371(2) ### ####"); // Latvia + case SupportedCountry.MT: + return faker.phone.number("+356 #### ####"); // Malta + case SupportedCountry.NL: + return faker.phone.number("+31 (06) #### ####"); // Netherland + case SupportedCountry.PT: + return faker.phone.number("+351 2## ### ###"); // Portugal + case SupportedCountry.SI: + return faker.phone.number("+386(#)### ## ##"); // Slovenia + case SupportedCountry.SK: + return faker.phone.number("+386(#)### ## ##"); // Slovakia + case SupportedCountry.UK: + return faker.phone.number("07#########"); // United Kingdom + // @endif + // @if financialProduct==embedded-finance + case SupportedCountry.US: + return faker.phone.number("###-###-####"); // United States + // @endif + default: + throw new Error( + `Fake phone number generation not implemented for country: ${country}`, + ); + } +}; + type FakeAddress = { address1: string; city: string; @@ -72,21 +236,152 @@ type FakeAddress = { postalCode: string; }; -export const getFakePhoneByCountry = (country: SupportedCountry): string => { - const faker = LocalizedFakerMap[country] as Faker; - +// These are a hardcoded list of addresses in each supported country so that we can test them each out for the demo +// Stripe docs for test addresses: https://stripe.com/docs/connect/testing#test-verification-addresses +export const getStaticFakeAddressByCountry = ( + country: SupportedCountry, +): FakeAddress => { switch (country) { // @if financialProduct==expense-management + case SupportedCountry.AT: + return { + address1: "address_full_match", + city: "NOT AVAILABLE", + postal_code: "NOT AVAILABLE", + }; + case SupportedCountry.BE: + return { + address1: "address_full_match", + city: "Brussel", + postal_code: "1000", + }; + case SupportedCountry.CY: + return { + address1: "address_full_match", + city: "NOT AVAILABLE", + postal_code: "NOT AVAILABLE", + }; + case SupportedCountry.DE: + return { + address1: "address_full_match", + city: "Berlin", + postal_code: "10115", + }; + case SupportedCountry.EE: + return { + address1: "address_full_match", + city: "NOT AVAILABLE", + postal_code: "NOT AVAILABLE", + }; + case SupportedCountry.ES: + return { + address1: "address_full_match", + city: "Madrid", + postal_code: "28001", + }; + case SupportedCountry.FI: + return { + address1: "address_full_match", + city: "Helsinki", + postal_code: "00100", + }; + case SupportedCountry.FR: + return { + address1: "address_full_match", + city: "Paris", + postal_code: "75001", + }; + case SupportedCountry.GR: + return { + address1: "address_full_match", + city: "NOT AVAILABLE", + postal_code: "NOT AVAILABLE", + }; + case SupportedCountry.HR: + return { + address1: "address_full_match", + city: "NOT AVAILABLE", + postal_code: "NOT AVAILABLE", + }; + case SupportedCountry.IE: + return { + address1: "address_full_match", + city: "NOT AVAILABLE", + postal_code: "NOT AVAILABLE", + }; + case SupportedCountry.IT: + return { + address1: "address_full_match", + city: "NOT AVAILABLE", + postal_code: "NOT AVAILABLE", + }; + case SupportedCountry.LT: + return { + address1: "address_full_match", + city: "NOT AVAILABLE", + postal_code: "NOT AVAILABLE", + }; + case SupportedCountry.LU: + return { + address1: "address_full_match", + city: "Luxemburg", + postal_code: "1111", + }; + case SupportedCountry.LV: + return { + address1: "address_full_match", + city: "NOT AVAILABLE", + postal_code: "NOT AVAILABLE", + }; + case SupportedCountry.MT: + return { + address1: "address_full_match", + city: "NOT AVAILABLE", + postal_code: "NOT AVAILABLE", + }; + case SupportedCountry.NL: + return { + address1: "address_full_match", + city: "Amsterdam", + postal_code: "1008 DG", + }; + case SupportedCountry.PT: + return { + address1: "address_full_match", + city: "Lisbon", + postal_code: "1000", + }; + case SupportedCountry.SI: + return { + address1: "address_full_match", + city: "NOT AVAILABLE", + postal_code: "NOT AVAILABLE", + }; + case SupportedCountry.SK: + return { + address1: "address_full_match", + city: "NOT AVAILABLE", + postal_code: "NOT AVAILABLE", + }; case SupportedCountry.UK: - return faker.phone.number("07#########"); // UK phone number format + return { + address1: "address_full_match", + city: "London", + postal_code: "WC32 4AP", + }; // @endif // @if financialProduct==embedded-finance case SupportedCountry.US: - return faker.phone.number("###-###-####"); // US phone number format + return { + address1: "address_full_match", + city: "South San Francisco", + state: "CA", + postal_code: "94080", + }; // @endif default: throw new Error( - `Fake phone number generation not implemented for country: ${country}`, + `Fake address generation not implemented for country: ${country}`, ); } }; @@ -98,6 +393,26 @@ export const getFakeAddressByCountry = ( switch (country) { // @if financialProduct==expense-management + case SupportedCountry.AT: + case SupportedCountry.BE: + case SupportedCountry.CY: + case SupportedCountry.DE: + case SupportedCountry.EE: + case SupportedCountry.ES: + case SupportedCountry.FI: + case SupportedCountry.FR: + case SupportedCountry.GR: + case SupportedCountry.HR: + case SupportedCountry.IE: + case SupportedCountry.IT: + case SupportedCountry.LT: + case SupportedCountry.LU: + case SupportedCountry.LV: + case SupportedCountry.MT: + case SupportedCountry.NL: + case SupportedCountry.PT: + case SupportedCountry.SI: + case SupportedCountry.SK: case SupportedCountry.UK: return { address1: faker.location.streetAddress(),