The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
handle error from stripe
Kiran Kee451db6a57a
diff --git a/apps/web/lib/stripe/create-account-link.ts b/apps/web/lib/stripe/create-account-link.tsindex 87837fbd0a..78b27fdd0c 100644--- a/apps/web/lib/stripe/create-account-link.ts+++ b/apps/web/lib/stripe/create-account-link.ts@@ -2,7 +2,6 @@ import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";import { stripe } from ".";// TODO:-// Handle the errors from the stripe API// refresh_url can also be a api path that generate new account link and redirect to itexport const createAccountLink = async ({@@ -10,11 +9,17 @@ export const createAccountLink = async ({}: {stripeConnectId: string;}) => {- return await stripe.accountLinks.create({- account: stripeConnectId,- refresh_url: `${APP_DOMAIN_WITH_NGROK}/settings/payouts`,- return_url: `${APP_DOMAIN_WITH_NGROK}/settings/payouts`,- type: "account_onboarding",- collect: "eventually_due",- });+ try {+ return await stripe.accountLinks.create({+ account: stripeConnectId,+ refresh_url: `${APP_DOMAIN_WITH_NGROK}/settings/payouts`,+ return_url: `${APP_DOMAIN_WITH_NGROK}/settings/payouts`,+ type: "account_onboarding",+ collect: "eventually_due",+ });+ } catch (error) {+ throw new Error(+ `[Stripe Connect] Failed to create account link: ${error.message}.`,+ );+ }};diff --git a/apps/web/lib/stripe/create-connected-account.ts b/apps/web/lib/stripe/create-connected-account.tsindex fca5d84a34..ad2a1f10f7 100644--- a/apps/web/lib/stripe/create-connected-account.ts+++ b/apps/web/lib/stripe/create-connected-account.ts@@ -2,9 +2,6 @@ import { z } from "zod";import { stripe } from ".";import { onboardPartnerSchema } from "../zod/schemas/partners";-// TODO:-// Handle the errors from the stripe API-export const createConnectedAccount = async ({name,email,@@ -16,24 +13,30 @@ export const createConnectedAccount = async ({>) => {const [firstName, lastName] = name.split(" ");- return await stripe.accounts.create({- type: "express",- business_type: "individual",- email,- country,- individual: {- first_name: firstName,- last_name: lastName,+ try {+ return await stripe.accounts.create({+ type: "express",+ business_type: "individual",email,- phone: phoneNumber,- },- capabilities: {- transfers: {- requested: true,+ country,+ individual: {+ first_name: firstName,+ last_name: lastName,+ email,+ phone: phoneNumber,},- card_payments: {- requested: true,+ capabilities: {+ transfers: {+ requested: true,+ },+ card_payments: {+ requested: true,+ },},- },- });+ });+ } catch (error) {+ throw new Error(+ `[Stripe Connect] Failed to create connected account: ${error.message}.`,+ );+ }};diff --git a/apps/web/scripts/stripe-connect.ts b/apps/web/scripts/stripe-connect.tsindex 831fab1eab..b2b7cc1efc 100644--- a/apps/web/scripts/stripe-connect.ts+++ b/apps/web/scripts/stripe-connect.ts@@ -1,6 +1,7 @@// Stripe Connect MVPimport "dotenv-flow/config";+import { createConnectedAccount } from "@/lib/stripe/create-connected-account";import Stripe from "stripe";@@ -33,11 +34,20 @@ async function main() {// await createExpressAccount();// await createLoginLink();// await createPayout();- await createCustomer();-- // const account = await stripe.accounts.retrieve("acct_1QVHHo2Z0L3O7iWp");-- // console.log("Account", account);+ // await createCustomer();++ try {+ const account = await createConnectedAccount({+ name: "Kiran 1",+ email: "[email protected]",+ country: "US",+ phoneNumber: "1234567890",+ });++ console.log("Created connected account", account);+ } catch (error) {+ console.error(error);+ }}const createExpressAccount = async () => {