🐛 (billing) Only fetch active subscriptions
This commit is contained in:
@@ -49,6 +49,7 @@ export const getSubscription = authenticatedProcedure
|
|||||||
const subscriptions = await stripe.subscriptions.list({
|
const subscriptions = await stripe.subscriptions.list({
|
||||||
customer: workspace.stripeId,
|
customer: workspace.stripeId,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
|
status: 'active',
|
||||||
})
|
})
|
||||||
|
|
||||||
const subscription = subscriptions?.data.shift()
|
const subscription = subscriptions?.data.shift()
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ export const updateSubscription = authenticatedProcedure
|
|||||||
})
|
})
|
||||||
const { data } = await stripe.subscriptions.list({
|
const { data } = await stripe.subscriptions.list({
|
||||||
customer: workspace.stripeId,
|
customer: workspace.stripeId,
|
||||||
|
limit: 1,
|
||||||
|
status: 'active',
|
||||||
})
|
})
|
||||||
const subscription = data[0] as Stripe.Subscription | undefined
|
const subscription = data[0] as Stripe.Subscription | undefined
|
||||||
const currentPlanItemId = subscription?.items.data.find((item) =>
|
const currentPlanItemId = subscription?.items.data.find((item) =>
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ export const cancelSubscription = async (stripeId: string) => {
|
|||||||
const currentSubscriptionId = (
|
const currentSubscriptionId = (
|
||||||
await stripe.subscriptions.list({
|
await stripe.subscriptions.list({
|
||||||
customer: stripeId,
|
customer: stripeId,
|
||||||
|
limit: 1,
|
||||||
|
status: 'active',
|
||||||
})
|
})
|
||||||
).data.shift()?.id
|
).data.shift()?.id
|
||||||
if (currentSubscriptionId)
|
if (currentSubscriptionId)
|
||||||
|
|||||||
Reference in New Issue
Block a user