|
1 | | -import { STRIPE_KEY } from "$env/static/private" |
| 1 | +import { FIXER_API_KEY, STRIPE_KEY } from "$env/static/private" |
2 | 2 | import type { BundleSchema, NewScriptSchema, PriceSchema } from "$lib/client/schemas" |
3 | 3 | import type { Interval, Price, Scripter } from "$lib/types/collection" |
4 | 4 | import type { Database } from "$lib/types/supabase" |
5 | 5 | import type { SupabaseClient } from "@supabase/supabase-js" |
6 | 6 | import Stripe from "stripe" |
7 | 7 |
|
| 8 | +//@ts-ignore |
| 9 | +export const stripe = new Stripe(STRIPE_KEY, { apiVersion: "2025-08-27.basil", typescript: true }) |
8 | 10 |
|
9 | 11 | export async function createCustomer(id: string, email: string, discord: string, username: string) { |
10 | 12 | let customer: Stripe.Customer |
@@ -141,22 +143,23 @@ export async function createAccount( |
141 | 143 | return |
142 | 144 | } |
143 | 145 |
|
144 | | - const { error: err } = await supabase |
145 | | - .schema("profiles") |
146 | | - .from("scripters") |
147 | | - .update({ stripe: account.id }) |
148 | | - .eq("id", scripter.id) |
| 146 | + const promises = await Promise.all([ |
| 147 | + supabase.schema("profiles").from("scripters").update({ stripe: account.id }).eq("id", scripter.id), |
| 148 | + supabase.schema("profiles").from("balances").update({ stripe: account.id }).eq("id", scripter.id) |
| 149 | + ]) |
149 | 150 |
|
150 | | - if (err) { |
151 | | - console.error(err) |
152 | | - return |
| 151 | + for (let i = 0; i < promises.length; i++) { |
| 152 | + if (promises[i].error) { |
| 153 | + console.error(promises[i].error) |
| 154 | + return |
| 155 | + } |
153 | 156 | } |
154 | 157 |
|
155 | 158 | try { |
156 | 159 | accountLink = await stripe.accountLinks.create({ |
157 | 160 | account: account.id, |
158 | | - refresh_url: baseURL + "/api/stripe/connect/reauth", |
159 | | - return_url: baseURL + "/api/stripe/connect/return", |
| 161 | + refresh_url: baseURL + "/dashboard/", |
| 162 | + return_url: baseURL + "/dashboard/", |
160 | 163 | type: "account_onboarding" |
161 | 164 | }) |
162 | 165 | } catch (err) { |
@@ -350,3 +353,5 @@ export async function createScriptProduct(script: NewScriptSchema, name: string, |
350 | 353 |
|
351 | 354 | await Promise.all(stripePromises) |
352 | 355 | } |
| 356 | + |
| 357 | +export async function convertCurrency(from: string, to: string, amount: number) {} |
0 commit comments