From ff179085aecbb9309c95b7d2db3600f40a59ac78 Mon Sep 17 00:00:00 2001 From: Joanna Li Date: Thu, 11 Jul 2024 17:07:43 -0700 Subject: [PATCH 1/6] turn off eac for custom --- app/api/account_session/route.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/api/account_session/route.ts b/app/api/account_session/route.ts index 9a24bb1e..1223e43c 100644 --- a/app/api/account_session/route.ts +++ b/app/api/account_session/route.ts @@ -108,6 +108,7 @@ export async function POST(req: NextRequest) { }, }, // Connect +<<<<<<< HEAD account_management: { enabled: true, features: {external_account_collection: !isCustom}, @@ -123,6 +124,14 @@ export async function POST(req: NextRequest) { enabled: true, features: {external_account_collection: !isCustom}, }, +======= + account_management: {enabled: true, features:{external_account_collection: !isCustom}}, + account_onboarding: {enabled: true, features:{external_account_collection: !isCustom}}, + // @ts-ignore + payment_method_settings: {enabled: true}, + documents: {enabled: true}, + notification_banner: {enabled: true, features:{external_account_collection: !isCustom}}, +>>>>>>> 67f4d0e (turn off eac for custom) capital_overview: { enabled: true, }, From d5f9dca334eba221a3d3c53456b091561dd2c034 Mon Sep 17 00:00:00 2001 From: Joanna Li Date: Thu, 11 Jul 2024 17:08:03 -0700 Subject: [PATCH 2/6] prettier --- app/api/account_session/route.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/api/account_session/route.ts b/app/api/account_session/route.ts index 1223e43c..9a24bb1e 100644 --- a/app/api/account_session/route.ts +++ b/app/api/account_session/route.ts @@ -108,7 +108,6 @@ export async function POST(req: NextRequest) { }, }, // Connect -<<<<<<< HEAD account_management: { enabled: true, features: {external_account_collection: !isCustom}, @@ -124,14 +123,6 @@ export async function POST(req: NextRequest) { enabled: true, features: {external_account_collection: !isCustom}, }, -======= - account_management: {enabled: true, features:{external_account_collection: !isCustom}}, - account_onboarding: {enabled: true, features:{external_account_collection: !isCustom}}, - // @ts-ignore - payment_method_settings: {enabled: true}, - documents: {enabled: true}, - notification_banner: {enabled: true, features:{external_account_collection: !isCustom}}, ->>>>>>> 67f4d0e (turn off eac for custom) capital_overview: { enabled: true, }, From d027774c502f42055f83dc5176bb37992d6b5221 Mon Sep 17 00:00:00 2001 From: Joanna Li Date: Thu, 11 Jul 2024 17:48:30 -0700 Subject: [PATCH 3/6] little things --- app/(auth)/business/form.tsx | 6 +++--- app/api/setup_accounts/route.ts | 1 + app/components/QuickstartButton.tsx | 2 +- lib/auth.ts | 14 ++++++++++++++ types/account.ts | 6 +----- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/(auth)/business/form.tsx b/app/(auth)/business/form.tsx index 894b378f..396fd7bd 100644 --- a/app/(auth)/business/form.tsx +++ b/app/(auth)/business/form.tsx @@ -36,8 +36,8 @@ import { import type {FeePayer, StripeDashboardType} from '@/types/account'; const businessTypeLabels = { - independent_salon: 'Independent salon', - chain_of_salons: 'Chain of salons', + individual: 'Independent salon', + company: 'Chain of salons', other: 'Other', }; @@ -269,7 +269,7 @@ export default function BusinessDetailsForm({email}: {email: string}) { const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { - businessType: 'independent_salon', + businessType: 'individual', businessName: '', country: 'US', stripeDashboardType: 'none', diff --git a/app/api/setup_accounts/route.ts b/app/api/setup_accounts/route.ts index c87b7082..07f4ede7 100644 --- a/app/api/setup_accounts/route.ts +++ b/app/api/setup_accounts/route.ts @@ -63,6 +63,7 @@ export async function POST() { }, confirm: true, payment_method: 'pm_card_createDispute', + receipt_email: 'dispute_test@stripe.com', }, { stripeAccount: accountId, diff --git a/app/components/QuickstartButton.tsx b/app/components/QuickstartButton.tsx index e7f672ed..49f5abee 100644 --- a/app/components/QuickstartButton.tsx +++ b/app/components/QuickstartButton.tsx @@ -191,7 +191,7 @@ const QuickstartButton = () => { const passwordWords = generate({exactly: 2, minLength: 5, maxLength: 12}); await signIn('createprefilledaccount', { - email: `${salonName}_${emailNumber}@stripe.com`, + email: `${salonName}_${emailNumber}@furever.com`, password: `${passwordWords[0]}-${passwordWords[1]}-${passwordNumber}`, businessName: salonName, callbackUrl: '/home?shownux=true', diff --git a/lib/auth.ts b/lib/auth.ts index c2b126c3..040b1ed0 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -4,6 +4,7 @@ import dbConnect from '@/lib/dbConnect'; import Salon from '../app/models/salon'; import {stripe} from '@/lib/stripe'; import {resolveControllerParams} from './utils'; +import Stripe from 'stripe'; function getRandomInt(min: number, max: number) { return Math.floor(Math.random() * (max - min + 1)) + min; @@ -381,10 +382,23 @@ export const authOptions: AuthOptions = { console.log('Could not find an existing user for the email', email); return null; } + let businessType = undefined; + + if ( + credentials?.businessType === 'company' || + credentials?.businessType === 'individual' + ) { + businessType = + credentials?.businessType as Stripe.AccountCreateParams.BusinessType; + } console.log('Creating stripe account for the email', email); const account = await stripe.accounts.create({ country: credentials?.country || 'US', + business_type: businessType, + business_profile: { + name: credentials?.businessName || 'Furever Pet Salon', + }, email: email, controller: resolveControllerParams({ feePayer: credentials.feePayer, diff --git a/types/account.ts b/types/account.ts index 40990d7a..69cb0e27 100644 --- a/types/account.ts +++ b/types/account.ts @@ -1,8 +1,4 @@ -export const businessTypes = [ - 'independent_salon', - 'chain_of_salons', - 'other', -] as const; +export const businessTypes = ['individual', 'company', 'other'] as const; export type BusinessType = (typeof businessTypes)[number]; export const countries = [ From 4353bc58c1611a07fe9913f163c9e10c1ee9d192 Mon Sep 17 00:00:00 2001 From: Joanna Li Date: Thu, 11 Jul 2024 18:13:57 -0700 Subject: [PATCH 4/6] use switch --- lib/auth.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/auth.ts b/lib/auth.ts index 040b1ed0..e7cf0109 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -10,6 +10,10 @@ function getRandomInt(min: number, max: number) { return Math.floor(Math.random() * (max - min + 1)) + min; } +function assertUnreachable(option: string) { + console.error(`Did not find a valid option for ${option}`); +} + export const authOptions: AuthOptions = { session: { strategy: 'jwt', @@ -382,14 +386,14 @@ export const authOptions: AuthOptions = { console.log('Could not find an existing user for the email', email); return null; } - let businessType = undefined; - - if ( - credentials?.businessType === 'company' || - credentials?.businessType === 'individual' - ) { - businessType = - credentials?.businessType as Stripe.AccountCreateParams.BusinessType; + let businessType: Stripe.Account.BusinessType; + switch (credentials?.businessType) { + case 'company': + case 'individual': + businessType = credentials?.businessType; + default: + assertUnreachable(credentials?.businessType); + businessType = 'individual'; // We default to individual, but rely on TS to catch missing cases } console.log('Creating stripe account for the email', email); From 5805f71ef071eab4aed5f04e5e436e3df5658d21 Mon Sep 17 00:00:00 2001 From: Joanna Li Date: Thu, 11 Jul 2024 18:49:04 -0700 Subject: [PATCH 5/6] unreacheble --- lib/auth.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/auth.ts b/lib/auth.ts index e7cf0109..04522ea4 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -10,8 +10,11 @@ function getRandomInt(min: number, max: number) { return Math.floor(Math.random() * (max - min + 1)) + min; } -function assertUnreachable(option: string) { - console.error(`Did not find a valid option for ${option}`); +function assertUnreachable(x: never | undefined, message?: string) { + console.error( + message ?? 'Thing that should never be set is set', + JSON.parse(JSON.stringify(x)) + ); } export const authOptions: AuthOptions = { From c59c91cb250f5c29d81a001e0709277c16798ea8 Mon Sep 17 00:00:00 2001 From: Joanna Li Date: Fri, 12 Jul 2024 15:51:29 -0700 Subject: [PATCH 6/6] remove unreachable --- lib/auth.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lib/auth.ts b/lib/auth.ts index 04522ea4..09ac1cfd 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -10,13 +10,6 @@ function getRandomInt(min: number, max: number) { return Math.floor(Math.random() * (max - min + 1)) + min; } -function assertUnreachable(x: never | undefined, message?: string) { - console.error( - message ?? 'Thing that should never be set is set', - JSON.parse(JSON.stringify(x)) - ); -} - export const authOptions: AuthOptions = { session: { strategy: 'jwt', @@ -389,14 +382,14 @@ export const authOptions: AuthOptions = { console.log('Could not find an existing user for the email', email); return null; } - let businessType: Stripe.Account.BusinessType; + let businessType; switch (credentials?.businessType) { case 'company': case 'individual': - businessType = credentials?.businessType; + businessType = + credentials?.businessType as Stripe.AccountCreateParams.BusinessType; default: - assertUnreachable(credentials?.businessType); - businessType = 'individual'; // We default to individual, but rely on TS to catch missing cases + businessType = undefined; // We default to undefined so user can pick the business type during onboarding } console.log('Creating stripe account for the email', email);