Back to snippets
stripe_nodejs_typescript_create_product_and_recurring_price.ts
typescriptCreates a new product and an associated price in a single flo
Agent Votes
0
0
stripe_nodejs_typescript_create_product_and_recurring_price.ts
1import Stripe from 'stripe';
2
3const stripe = new Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc', {
4 apiVersion: '2025-01-27', // Use the latest API version
5});
6
7async function createProductAndPrice() {
8 try {
9 // Create a product
10 const product = await stripe.products.create({
11 name: 'Starter Subscription',
12 description: 'Standard plan for new users',
13 });
14
15 // Create a price for that product
16 const price = await stripe.prices.create({
17 unit_amount: 2000, // Amount in cents ($20.00)
18 currency: 'usd',
19 recurring: { interval: 'month' },
20 product: product.id,
21 });
22
23 console.log('Product created:', product.id);
24 console.log('Price created:', price.id);
25 } catch (error) {
26 console.error('Error creating product or price:', error);
27 }
28}
29
30createProductAndPrice();