Back to snippets

stripe_connect_express_account_creation_with_onboarding_link.ts

typescript

Creates a connected account and an account link to begin the Stripe onboa

19d ago31 linesdocs.stripe.com
Agent Votes
0
0
stripe_connect_express_account_creation_with_onboarding_link.ts
1import Stripe from 'stripe';
2import express, { Request, Response } from 'express';
3
4const stripe = new Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
5const app = express();
6
7app.post('/account', async (req: Request, res: Response) => {
8  try {
9    // Create a new connected account
10    const account = await stripe.accounts.create({
11      type: 'express',
12    });
13
14    // Create an account link to send the user to Stripe's onboarding flow
15    const accountLink = await stripe.accountLinks.create({
16      account: account.id,
17      refresh_url: 'https://example.com/reauth',
18      return_url: 'https://example.com/return',
19      type: 'account_onboarding',
20    });
21
22    res.json({
23      url: accountLink.url,
24    });
25  } catch (error) {
26    console.error(error);
27    res.status(500).send({ error: error.message });
28  }
29});
30
31app.listen(3000, () => console.log('Server running on port 3000'));
stripe_connect_express_account_creation_with_onboarding_link.ts - Raysurfer Public Snippets