forked from dzlau/stripe-supabase-saas-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stripeSetup.ts
55 lines (52 loc) · 1.66 KB
/
stripeSetup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const Stripe = require('stripe');
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY)
const PUBLIC_URL = process.env.NEXT_PUBLIC_WEBSITE_URL ? process.env.NEXT_PUBLIC_WEBSITE_URL : "http://localhost:3000"
const currencyType = 'usd'
const plans = [
{
'name': 'Basic-Test',
'price': 1000, // price in cents, use 0 for free
'features': [
// This will be used to list the features that will show up on the pricing table
{ name: 'Upto 10 users' },
{ name: 'Upto 1000 records' },
{ name: 'Upto 1000 API calls' }
]
},
{
'name': 'Pro-Test',
'price': 2000,
'features': [
{ name: 'Upto 100 users' },
{ name: 'Upto 10000 records' },
{ name: 'Upto 10000 API calls' }
]
},
{
'name': 'Enterprise-Test', 'price': 5000, features: [
{ name: 'Unlimited users' },
{ name: 'Unlimited records' },
{ name: 'Unlimited API calls' }
]
}
]
// Create a new product in Stripe
plans.forEach(async (plan) => {
const product = await stripe.products.create({
name: plan.name,
marketing_features: plan.features
});
const price = await stripe.prices.create({
product: product.id,
unit_amount: plan.price,
currency: currencyType,
});
await stripe.products.update(product.id, { 'default_price': price.id })
})
// Add webhook
stripe.webhookEndpoints.create({
enabled_events: ['customer.subscription.created',
'customer.subscription.deleted',
'customer.subscription.updated'],
url: `${PUBLIC_URL}/webhook/stripe`,
});