我正在创造产品
const product = await stripe.products.create({
name: 'Charge for messages',
});
然后是价格
const price = await stripe.prices.create({
unit_amount: parseInt(item.amount),
currency: 'usd',
product: product.id,
});
然后我有结账环节
const session = await stripe.checkout.sessions.create({
mode: 'payment',
customer: item.stripe_customer_id,
line_items: [
{
price: price.id,
quantity: 1,
},
],
payment_intent_data: {
description: 'Extra messages'
},
success_url: `${process.env.FRONTEND_URL}/dashboard/invoices?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${process.env.FRONTEND_URL}`,
});
当用户完成付款时,我在 webhook 上收到 payment_intend.succed 事件,但发票为空。如何在发票中包含发票 ID?
您可以在创建结帐会话时传递
invoice_creation
参数来创建发票
您可以找到文档
const session = await stripe.checkout.sessions.create({
mode: 'payment',
invoice_creation: {enabled: true},
customer: item.stripe_customer_id,
line_items: [
{
price: price.id,
quantity: 1,
},
],
payment_intent_data: {
description: 'Extra messages'
},
success_url: `${process.env.FRONTEND_URL}/dashboard/invoices?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${process.env.FRONTEND_URL}`,
});