/*
1) Create a stripe customer
2) Create a product
3) Create payment session
*/
// Create payment session
const amount = 100 // 100 usd
const session = await stripe.core.checkout.sessions.create({
customer: customerId,
payment_method_types: ['card'],
line_items: [
{
price_data: {
currency: 'usd',
product: productId,
unit_amount: amount * 100,
recurring: {
interval: 'month' // 'month' | 'year'
}
},
quantity: 1
}
],
mode: 'subscription',
success_url: successUrl,
cancel_url: cancelUrl
})
const stripe = require('stripe')(STRIPE_KEY);
const subscription = await stripe.subscriptions.create({
customer: CUSTOMER_ID,
items: [
{price: PRICE_ID},
],
pay_immediately: false
});