-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de0b105
commit 2abce89
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { PrismaClient } from '@typebot.io/prisma' | ||
import { promptAndSetEnvironment } from './utils' | ||
import { Stripe } from 'stripe' | ||
|
||
const checkSubscriptionsStatus = async () => { | ||
await promptAndSetEnvironment() | ||
const prisma = new PrismaClient() | ||
|
||
const workspacesWithPaidPlan = await prisma.workspace.findMany({ | ||
where: { | ||
plan: { | ||
in: ['PRO', 'STARTER', 'CUSTOM'], | ||
}, | ||
}, | ||
}) | ||
|
||
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!, { | ||
apiVersion: '2022-11-15', | ||
}) | ||
|
||
let activeSubscriptions = 0 | ||
for (const workspace of workspacesWithPaidPlan) { | ||
if (!workspace.stripeId) { | ||
console.log('No stripe ID', workspace.id) | ||
continue | ||
} | ||
const customer = await stripe.customers.retrieve(workspace.stripeId) | ||
const subscription = ( | ||
await stripe.subscriptions.list({ | ||
customer: customer.id, | ||
}) | ||
).data.at(0) | ||
if (!subscription) { | ||
console.log('No subscription', workspace.id) | ||
continue | ||
} | ||
if (subscription.status === 'active') { | ||
activeSubscriptions++ | ||
continue | ||
} | ||
console.log(`${workspace.id} - ${workspace.name} - ${subscription.status}`) | ||
} | ||
console.log('Active subscriptions', activeSubscriptions) | ||
} | ||
|
||
checkSubscriptionsStatus() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters