Skip to content

Commit bb5b26b

Browse files
committed
fix: improved stipe account creation performance
1 parent cf4a0d0 commit bb5b26b

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/lib/server/stripe.server.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export async function createCheckoutSession(
9797

9898
export async function createAccount(baseURL: string, scripter: Scripter, email: string, country: string) {
9999
let account: Stripe.Response<Stripe.Account>
100-
let accountLink: Stripe.Response<Stripe.AccountLink>
101100

102101
const profile = scripter.profiles
103102
const requested = { requested: true }
@@ -141,29 +140,31 @@ export async function createAccount(baseURL: string, scripter: Scripter, email:
141140

142141
const promises = await Promise.all([
143142
supabaseAdmin.schema("profiles").from("scripters").update({ stripe: account.id }).eq("id", scripter.id),
144-
supabaseAdmin.schema("profiles").from("balances").update({ stripe: account.id }).eq("id", scripter.id)
143+
supabaseAdmin.schema("profiles").from("balances").update({ stripe: account.id }).eq("id", scripter.id),
144+
stripe.accountLinks
145+
.create({
146+
account: account.id,
147+
refresh_url: baseURL + "/dashboard/",
148+
return_url: baseURL + "/dashboard/",
149+
type: "account_onboarding"
150+
})
151+
.catch((err) => {
152+
console.error("Stripe accountLinks.create failed:", err)
153+
return null
154+
})
145155
])
146156

147-
for (let i = 0; i < promises.length; i++) {
148-
if (promises[i].error) {
149-
console.error(promises[i].error)
150-
return
151-
}
157+
if (promises[0].error) {
158+
console.error(promises[0].error)
159+
return
152160
}
153161

154-
try {
155-
accountLink = await stripe.accountLinks.create({
156-
account: account.id,
157-
refresh_url: baseURL + "/dashboard/",
158-
return_url: baseURL + "/dashboard/",
159-
type: "account_onboarding"
160-
})
161-
} catch (err) {
162-
console.error(err)
162+
if (promises[1].error) {
163+
console.error(promises[1].error)
163164
return
164165
}
165166

166-
return accountLink.url
167+
return promises[2]?.url
167168
}
168169

169170
export async function getOnboardingLink(baseURL: string, scripter: Scripter) {

0 commit comments

Comments
 (0)