/*
Create customer account
*/
const customer = await stripe.customers.create({
email: user.email, // optional
name: `${user.first_name} ${user.last_name}`, // optional
metadata: {
user_id: 'foo' // Or anything else
}
})
/*
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
})