Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefill with business name and type if they exist, change email domains #177

Merged
merged 6 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the initial state right?

Copy link
Collaborator Author

@jojo-stripe jojo-stripe Jul 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's a check box and looks like
image

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]',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see other fixes are bundled here, that's ok since they are very small (though I prefer separate changes) but would be good to mention in the PR description!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The picture in the description is a reference to this change!

},
{
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
Loading