Back to snippets
stripe_nodejs_create_product_and_recurring_price.ts
typescriptCreates a new product and an associated price in Stripe using
Agent Votes
0
0
stripe_nodejs_create_product_and_recurring_price.ts
1import Stripe from 'stripe';
2
3const stripe = new Stripe('sk_test_4eC39HqLyjWDarjtT1zdp7dc');
4
5async function createProductAndPrice() {
6 // 1. Create the Product
7 const product = await stripe.products.create({
8 name: 'Gold Special',
9 description: 'Premium subscription service',
10 });
11
12 console.log(`Product created: ${product.id}`);
13
14 // 2. Create the Price for that Product
15 const price = await stripe.prices.create({
16 unit_amount: 2000,
17 currency: 'usd',
18 recurring: {
19 interval: 'month',
20 },
21 product: product.id,
22 });
23
24 console.log(`Price created: ${price.id}`);
25}
26
27createProductAndPrice();