11import { STRIPE_KEY } from "$env/static/private"
22import type { BundleSchema , NewScriptSchema , PriceSchema } from "$lib/client/schemas"
3- import type { Bundle , Price , Scripter } from "$lib/types/collection"
3+ import type { Interval , Price , Scripter } from "$lib/types/collection"
44import type { Database } from "$lib/types/supabase"
55import type { SupabaseClient } from "@supabase/supabase-js"
66import Stripe from "stripe"
@@ -74,52 +74,44 @@ export async function createCheckoutSession(
7474 return session . url
7575}
7676
77- export async function getStripeConnectAccount ( id : string | null | undefined ) {
78- if ( ! id ) return null
77+ export async function getStripeConnectAccount ( scripter : Scripter ) {
78+ if ( scripter . id == scripter . stripe ) return null
7979 let stripeAccount : Stripe . Account | null = null
8080
8181 try {
82- stripeAccount = await stripe . accounts . retrieve ( id )
82+ stripeAccount = await stripe . accounts . retrieve ( scripter . stripe )
8383 } catch ( error ) {
8484 console . error ( "An error occurred when calling the Stripe API to create an account session" , error )
8585 }
8686
8787 return stripeAccount
8888}
8989
90- export async function getStripeConnectAccountBalance ( id : string | null | undefined ) {
91- if ( ! id ) return null
90+ export async function getStripeConnectAccountBalance ( scripter : Scripter ) {
91+ if ( scripter . id == scripter . stripe ) return null
9292 let stripeBalance : Stripe . Balance | null = null
9393 try {
94- stripeBalance = await stripe . balance . retrieve ( {
95- stripeAccount : id
96- } )
94+ stripeBalance = await stripe . balance . retrieve ( { stripeAccount : scripter . stripe } )
9795 } catch ( error ) {
9896 console . error ( "An error occurred when calling the Stripe API to create an account session" , error )
9997 }
10098
10199 return stripeBalance
102100}
103101
104- export async function getStripeSession ( account : string | null | undefined ) {
105- if ( ! account ) return null
106- let accountSession : Stripe . Response < Stripe . AccountSession > | null = null
102+ export async function getStripeSession ( scripter : Scripter ) {
103+ if ( scripter . id == scripter . stripe ) return null
104+ let session : Stripe . Response < Stripe . AccountSession > | null = null
107105
108106 try {
109- accountSession = await stripe . accountSessions . create ( {
110- account : account ,
107+ session = await stripe . accountSessions . create ( {
108+ account : scripter . stripe ,
111109 components : {
112110 payments : {
113111 enabled : true ,
114- features : {
115- refund_management : true ,
116- dispute_management : true ,
117- capture_payments : true
118- }
119- } ,
120- payouts : {
121- enabled : true
112+ features : { refund_management : true , dispute_management : true , capture_payments : true }
122113 } ,
114+ payouts : { enabled : true } ,
123115 payment_details : {
124116 enabled : true ,
125117 features : { refund_management : true , capture_payments : true , dispute_management : true }
@@ -130,7 +122,7 @@ export async function getStripeSession(account: string | null | undefined) {
130122 console . error ( "An error occurred when calling the Stripe API to create an account session" , error )
131123 }
132124
133- return accountSession ?. client_secret ?? null
125+ return session ?. client_secret ?? null
134126}
135127
136128export async function createStripeCustomer ( id : string , email : string , discord : string , username : string ) {
@@ -157,39 +149,45 @@ export async function createStripeConnectAccount(
157149 supabase : SupabaseClient ,
158150 baseURL : string ,
159151 scripter : Scripter ,
160- email : string | undefined ,
152+ email : string ,
161153 country : string
162154) {
163155 let account : Stripe . Response < Stripe . Account >
164156 let accountLink : Stripe . Response < Stripe . AccountLink >
165157
166- try {
167- account = await stripe . accounts . create ( {
168- type : "custom" ,
169- country : country ,
170- email : email ,
171- business_type : "individual" ,
172- individual : { full_name_aliases : [ scripter . id , scripter . profiles . username ] } ,
173- capabilities : {
174- card_payments : { requested : true } ,
175- link_payments : { requested : true } ,
176- transfers : { requested : true }
177- } ,
178- business_profile : {
179- mcc : "5734" ,
180- name : scripter . profiles . username ,
181- support_url : "https://waspscripts.dev/scripters/" + scripter . url ,
182- url : "https://waspscripts.dev/scripters/" + scripter . url ,
183- support_email :
"[email protected] " 184- } ,
185- metadata : { id : scripter . id , username : scripter . profiles . username } ,
186- settings : {
187- payouts : {
188- schedule : { interval : "monthly" , delay_days : 15 , monthly_anchor : 31 } ,
189- statement_descriptor : "waspscripts.dev"
190- }
158+ const profile = scripter . profiles
159+ const requested = { requested : true }
160+ const params : Stripe . AccountCreateParams = {
161+ controller : {
162+ fees : { payer : "application" } ,
163+ losses : { payments : "application" } ,
164+ stripe_dashboard : { type : "express" } ,
165+ requirement_collection : "stripe"
166+ } ,
167+ email : email ,
168+ country : country ,
169+ business_type : "individual" ,
170+ business_profile : {
171+ mcc : "5734" ,
172+ name : profile . username ,
173+ url : "https://waspscripts.dev/" ,
174+ support_url : "https://waspscripts.dev/" ,
175+ support_email :
"[email protected] " 176+ } ,
177+ individual : { full_name_aliases : [ profile . username , scripter . id , profile . discord ] } ,
178+ capabilities : { card_payments : requested , link_payments : requested , transfers : requested } ,
179+ settings : {
180+ payouts : {
181+ schedule : { interval : "monthly" , delay_days : 15 , monthly_anchor : 31 } ,
182+ statement_descriptor : "waspscripts.dev" ,
183+ debit_negative_balances : false
191184 }
192- } )
185+ } ,
186+ metadata : { id : scripter . id , discord : profile . discord , email : email }
187+ }
188+
189+ try {
190+ account = await stripe . accounts . create ( params )
193191 } catch ( err ) {
194192 console . error ( err )
195193 return
@@ -262,8 +260,6 @@ export async function updateStripeProduct(id: string, name: string) {
262260 }
263261}
264262
265- type Interval = "week" | "month" | "year"
266-
267263async function createStripePriceEx ( product : string , amount : number , interval : Interval ) {
268264 if ( amount === 0 ) return
269265 await stripe . prices
0 commit comments