Skip to content

Commit 22a77a0

Browse files
committed
fix: read notes
fixed an issue where people that had a huge amount of subscriptions couldn't cancel some of them because they couldn't all be loaded and the server assumed they were trying to cancel a sub that wasn't theirs
1 parent 2e349e9 commit 22a77a0

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

src/routes/subscriptions/+page.server.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,12 @@ export const actions = {
176176
)
177177
}
178178

179-
const customer = await stripe.customers.retrieve(profile.stripe, {
180-
expand: ["subscriptions"]
181-
})
179+
const stripePromises = await Promise.all([
180+
stripe.customers.retrieve(profile.stripe),
181+
stripe.subscriptions.retrieve(subscriptionID)
182+
])
182183

184+
const customer = stripePromises[0]
183185
if (customer.deleted) {
184186
return setError(
185187
form,
@@ -188,22 +190,9 @@ export const actions = {
188190
)
189191
}
190192

191-
if (!customer.subscriptions) {
192-
return setError(form, "", "You don't have any subscription to cancel.")
193-
}
194-
195-
const subscriptions = customer.subscriptions.data.filter((sub) => sub.status === "active")
196-
if (subscriptions.length === 0) {
197-
return setError(
198-
form,
199-
"",
200-
"You don't have any subscription active. Refresh the page, if this keeps happening, please contact [email protected]"
201-
)
202-
}
203-
204-
const subscription = subscriptions.find((subscription) => subscription.id === subscriptionID)
193+
const subscription = stripePromises[1]
205194

206-
if (!subscription) {
195+
if (subscription.customer !== profile.stripe) {
207196
return setError(
208197
form,
209198
"",

0 commit comments

Comments
 (0)