Skip to content

Commit

Permalink
Prefill with business name and type if they exist, change email domai…
Browse files Browse the repository at this point in the history
…ns (#177)

* turn off eac for custom

* prettier

* little things

* use switch

* unreacheble

* remove unreachable
  • Loading branch information
jojo-stripe authored Jul 15, 2024
1 parent 3031353 commit 5e06b40
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
6 changes: 3 additions & 3 deletions app/(auth)/business/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};

Expand Down Expand Up @@ -269,7 +269,7 @@ export default function BusinessDetailsForm({email}: {email: string}) {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: {
businessType: 'independent_salon',
businessType: 'individual',
businessName: '',
country: 'US',
stripeDashboardType: 'none',
Expand Down
1 change: 1 addition & 0 deletions app/api/setup_accounts/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export async function POST() {
},
confirm: true,
payment_method: 'pm_card_createDispute',
receipt_email: '[email protected]',
},
{
stripeAccount: accountId,
Expand Down
2 changes: 1 addition & 1 deletion app/components/QuickstartButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 14 additions & 0 deletions lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -381,10 +382,23 @@ export const authOptions: AuthOptions = {
console.log('Could not find an existing user for the email', email);
return null;
}
let businessType;
switch (credentials?.businessType) {
case 'company':
case 'individual':
businessType =
credentials?.businessType as Stripe.AccountCreateParams.BusinessType;
default:
businessType = undefined; // We default to undefined so user can pick the business type during onboarding
}

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,
Expand Down
6 changes: 1 addition & 5 deletions types/account.ts
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down

0 comments on commit 5e06b40

Please sign in to comment.