Skip to content

Commit d2211ea

Browse files
committed
fix: read notes
- stripe onboarding should be finished, still need some testing but should be finished - certain dynamic images have a simplified setup now
1 parent d03a40d commit d2211ea

File tree

18 files changed

+1808
-1987
lines changed

18 files changed

+1808
-1987
lines changed

src/lib/client/supabase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export async function getScripter(supabase: SupabaseClient, slug: string) {
9393
.schema("profiles")
9494
.from("scripters")
9595
.select(
96-
`id, stripe, realname, description, content, url, github, paypal, content, profiles (username, avatar)`
96+
`id, stripe, realname, description, content, url, github, paypal, content, profiles (username, discord, avatar)`
9797
)
9898
.eq(UUID_V4_REGEX.test(slug) ? "id" : "url", slug)
9999
.single<Scripter>()

src/lib/components/NewScriptCard.svelte

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,16 @@
33
import type { ScriptMetaData, ScriptPublic } from "$lib/types/collection"
44
import { cropString, encodeSEO, scriptCategories, scriptStatus, scriptTypes } from "$lib/utils"
55
import { Tooltip } from "@skeletonlabs/skeleton-svelte"
6-
import { onMount } from "svelte"
76
87
let {
98
script,
109
metadata,
1110
customCover = $bindable(undefined)
1211
}: { script: ScriptPublic; metadata: ScriptMetaData; customCover: string | undefined } = $props()
1312
14-
let imgLink = $state(customCover ?? "/cover.jpg")
13+
let imgLink = $derived(customCover ?? "/cover.jpg")
1514
const username = page.data.profile?.username ?? "USERNAME"
1615
17-
$effect(() => {
18-
imgLink = customCover ?? "/cover.jpg"
19-
})
20-
21-
onMount(async () => {
22-
if (imgLink !== "") {
23-
const response = await fetch(imgLink)
24-
if (response.status != 200) imgLink = "/cover.jpg"
25-
} else imgLink = "/cover.jpg"
26-
})
27-
2816
const categoriesTooltip: boolean[] = $state(new Array(metadata.categories.length).fill(false))
2917
let status = $state(false)
3018
let type = $state(false)

src/lib/components/ScriptCard.svelte

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,13 @@
44
import type { Script } from "$lib/types/collection"
55
import { cropString, encodeSEO, scriptCategories, scriptStatus, scriptTypes } from "$lib/utils"
66
import { Tooltip } from "@skeletonlabs/skeleton-svelte"
7-
import { onMount } from "svelte"
87
98
let { script, customCover, link }: { script: Script; customCover?: string; link?: string } = $props()
109
11-
let imgLink = $state(
10+
let imgLink = $derived(
1211
customCover ?? PUBLIC_SUPABASE_URL + "/storage/v1/object/public/imgs/scripts/" + script.id + "/cover.jpg"
1312
)
1413
15-
$effect(() => {
16-
imgLink =
17-
customCover ??
18-
PUBLIC_SUPABASE_URL + "/storage/v1/object/public/imgs/scripts/" + script.id + "/cover.jpg"
19-
})
20-
21-
$effect(() => {
22-
imgLink = PUBLIC_SUPABASE_URL + "/storage/v1/object/public/imgs/scripts/" + script.id + "/cover.jpg"
23-
})
24-
25-
onMount(async () => {
26-
if (imgLink !== "") {
27-
const response = await fetch(imgLink)
28-
if (response.status != 200) imgLink = "/cover.jpg"
29-
} else imgLink = "/cover.jpg"
30-
})
31-
3214
const categoriesTooltip: boolean[] = $state(new Array(script?.metadata.categories.length).fill(false))
3315
let status = $state(false)
3416
let type = $state(false)

src/lib/server/stripe.server.ts

Lines changed: 48 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { STRIPE_KEY } from "$env/static/private"
22
import 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"
44
import type { Database } from "$lib/types/supabase"
55
import type { SupabaseClient } from "@supabase/supabase-js"
66
import 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

136128
export 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-
267263
async function createStripePriceEx(product: string, amount: number, interval: Interval) {
268264
if (amount === 0) return
269265
await stripe.prices

src/lib/server/supabase.server.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ export async function doLogin(supabase: SupabaseClient, origin: string, searchPa
3030
redirect(303, data.url)
3131
}
3232

33-
export async function updateScriptFile(file: File) {
34-
let fileString = await file.text()
35-
return new File([fileString], file.name, { type: "text/plain" })
36-
}
37-
3833
export async function uploadFile(supabase: SupabaseClient, bucket: string, path: string, file: File) {
3934
const contentType = path.endsWith(".jpg") || path.endsWith(".jpeg") ? "image/jpeg" : undefined
4035

src/lib/types/collection.ts

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface ScripterBase {
2222
url: string
2323
profiles: {
2424
username: string
25+
discord: string
2526
avatar: string
2627
}
2728
}
@@ -32,11 +33,11 @@ export interface SimpleScripter {
3233
}
3334

3435
export interface Scripter extends ScripterBase {
35-
id: string
36-
stripe: string | undefined
37-
github: string | undefined
38-
paypal: string | undefined
39-
content: string | undefined
36+
id: Database["profiles"]["Tables"]["scripters"]["Row"]["id"]
37+
stripe: Database["profiles"]["Tables"]["scripters"]["Row"]["stripe"]
38+
github: Database["profiles"]["Tables"]["scripters"]["Row"]["github"]
39+
paypal: Database["profiles"]["Tables"]["scripters"]["Row"]["paypal"]
40+
content: Database["profiles"]["Tables"]["scripters"]["Row"]["content"]
4041
}
4142

4243
export interface ScripterProfile {
@@ -143,32 +144,6 @@ export interface ScriptSimple {
143144
metadata: { type: TScriptTypes }
144145
}
145146

146-
export interface ScriptFeatured {
147-
scripts: {
148-
url: string
149-
title: string
150-
description: string
151-
tooltip_emojis: string
152-
protected: {
153-
username: string
154-
avatar: string
155-
}
156-
}
157-
}
158-
159-
export interface CheckboxType {
160-
id: number
161-
name: string
162-
emoji: string
163-
main: boolean
164-
checked: boolean
165-
}
166-
167-
export interface Tooltip {
168-
name: string
169-
emoji: string
170-
}
171-
172147
export interface ProductData {
173148
id: string
174149
user_id: string
@@ -238,11 +213,4 @@ export interface ScriptProduct {
238213
active: boolean
239214
}
240215

241-
export interface Category {
242-
name: string
243-
emoji: string
244-
}
245-
246-
export interface SubCategory extends Category {
247-
category: string
248-
}
216+
export type Interval = "week" | "month" | "year"

0 commit comments

Comments
 (0)