Skip to content

Commit

Permalink
Specify a value for external_account_collection (#115)
Browse files Browse the repository at this point in the history
* Specify external_account_collection in FurEver

* Specify a value for external_account_collection
  • Loading branch information
jorgea-stripe authored Apr 26, 2024
1 parent 9ccfec1 commit 2f1288f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
10 changes: 5 additions & 5 deletions client/components/CompleteProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type FormValues = {
salonName: string;
salonLicense: string;
salonSpecialty: string;
accountConfiguration: string;
accountConfig: string;
};

const FormControl = ({children}: {children: React.ReactNode}) => (
Expand Down Expand Up @@ -83,7 +83,7 @@ export const CompleteProfile = () => {
salonName: '',
salonLicense: 'LINC123',
salonSpecialty: 'dogs',
accountConfiguration: 'no_dashboard_soll',
accountConfig: 'no_dashboard_soll',
});
const [searchParams] = useSearchParams();
const {mutate, isLoading, error} = useCreateStripeAccount();
Expand Down Expand Up @@ -348,12 +348,12 @@ export const CompleteProfile = () => {
<FormBlock>
<SelectInput
type="select"
name="accountConfiguration"
value={formValues.accountConfiguration}
name="accountConfig"
value={formValues.accountConfig}
onChange={(event) =>
setFormValues((prev) => ({
...prev,
accountConfiguration: event.target.value,
accountConfig: event.target.value,
}))
}
>
Expand Down
8 changes: 4 additions & 4 deletions client/routes/Onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {StripeConnectDebugUtils} from '../components/StripeConnectDebugUtils';
import {ConnectAccountOnboarding} from '@stripe/react-connect-js';

const useOnboarded = () => {
const {refetch, stripeAccount} = useSession();
const {refetch, user} = useSession();
const navigate = useNavigate();
const {search} = useLocation();

Expand All @@ -27,7 +27,7 @@ const useOnboarded = () => {
if (onboarded) {
refetch();
navigate(`/reservations${search}`);
} else if (stripeAccount?.type !== 'custom') {
} else if (user?.accountConfig === 'no_dashboard_poll') {
navigate(0);
}
});
Expand All @@ -36,7 +36,7 @@ const useOnboarded = () => {
export const Onboarding = () => {
const {search} = useLocation();
const {mutate, error} = useOnboarded();
const {stripeAccount} = useSession();
const {user} = useSession();
const navigate = useNavigate();

return (
Expand All @@ -62,7 +62,7 @@ export const Onboarding = () => {
'Onboarding exited! We redirect the user to the next page...'
);
mutate();
if (stripeAccount?.type === 'custom') {
if (user?.accountConfig === 'no_dashboard_poll') {
navigate(`/bankaccountform${search}`);
}
}}
Expand Down
4 changes: 2 additions & 2 deletions client/routes/RouteHandlers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export const CustomGatedRoute = ({
children: React.ReactNode;
}): JSX.Element => {
const {search} = useLocation();
const {stripeAccount} = useSession();
if (stripeAccount?.type !== 'custom') {
const {user} = useSession();
if (user?.accountConfig !== 'no_dashboard_poll') {
return <Navigate to={`/reservations${search}`} replace />;
}
return <>{children}</>;
Expand Down
30 changes: 22 additions & 8 deletions server/routes/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ const createPaymentIntentForNonCardPayments = async (
}
};

function getAccountParams(
accountConfiguration: string
): Stripe.AccountCreateParams {
function getAccountParams(accountConfig: string): Stripe.AccountCreateParams {
let type: Stripe.Account.Type | undefined = undefined;
let capabilities: Stripe.AccountCreateParams.Capabilities | undefined = {
card_payments: {
Expand All @@ -171,7 +169,7 @@ function getAccountParams(
},
};
let controller: Stripe.AccountCreateParams.Controller | undefined = undefined;
switch (accountConfiguration) {
switch (accountConfig) {
case 'no_dashboard_poll':
controller = {
losses: {
Expand Down Expand Up @@ -216,7 +214,7 @@ function getAccountParams(
};
break;
default:
throw new Error('Invalid account configuration:' + accountConfiguration);
throw new Error('Invalid account configuration:' + accountConfig);
}

return {
Expand All @@ -238,7 +236,7 @@ interface Test extends Request {
app.post('/create-account', userRequired, async (req, res) => {
try {
const user = req.user!;
user.set(req.body); // Try to update the logged-in salon using the newly entered profile data
user.set(req.body); // Update the logged-in salon using the newly entered profile data
await user.save();

let accountId = user.stripeAccountId;
Expand All @@ -249,7 +247,7 @@ app.post('/create-account', userRequired, async (req, res) => {
}

const shouldPrefill = req.body.prefill;
const accountConfiguration = req.body.accountConfiguration;
const accountConfig = req.body.accountConfig;

// Create a Stripe account for this user if one does not exist already
if (accountId == undefined) {
Expand All @@ -267,7 +265,7 @@ app.post('/create-account', userRequired, async (req, res) => {
});
}

const accountConfigParams = getAccountParams(accountConfiguration);
const accountConfigParams = getAccountParams(accountConfig);

// Define the parameters to create a new Stripe account with
let accountParams: Stripe.AccountCreateParams = {
Expand Down Expand Up @@ -427,17 +425,32 @@ function getStripeAccountId(req: any) {
*/
app.post('/account_session', stripeAccountRequired, async (req, res) => {
try {
const user = req.user!;

// FurEver enables external account collection for all accounts except ones where the platform owns requirements collection (otherwise known as custom)
const external_account_collection =
user.accountConfig !== 'no_dashboard_poll';

// This should contain a list of all components used in FurEver
const accountSessionComponentsParams: Stripe.AccountSessionCreateParams.Components =
{
account_management: {
enabled: true,
features: {
external_account_collection,
},
},
account_onboarding: {
enabled: true,
features: {
external_account_collection,
},
},
notification_banner: {
enabled: true,
features: {
external_account_collection,
},
},
payments: {
enabled: true,
Expand All @@ -456,6 +469,7 @@ app.post('/account_session', stripeAccountRequired, async (req, res) => {
enabled: true,
features: {
money_movement: true,
external_account_collection,
},
},
financial_account_transactions: {
Expand Down
1 change: 1 addition & 0 deletions types/express.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ declare global {
firstName: string;
lastName: string;
stripeAccountId: string;
accountConfig: string;

// MongoDB methods
isModified: (field: string) => boolean;
Expand Down

0 comments on commit 2f1288f

Please sign in to comment.