我正在实现Stripe订阅功能,但在创建结账会话时,我无法在API文档中找到如何指定订阅持续时间的信息。以下是我目前的代码:
我正在尝试创建一个订阅服务,客户每月支付24个月的费用。我使用答案中建议的“订阅计划”,确实创建出了这样一个24个月的订阅服务。但是,当创建新的结帐时,在支付成功的情况下,它会创建一项为期12个月的订阅服务......最终,我有了两个订阅服务。一个是通过订阅计划创建的(24个月,预期的那个),另一个是订阅服务(12个月)。是否有办法将此订阅计划传递给结帐,以便不会创建2个订阅服务?
const customer = await stripe.customers.create({
description: "My First Test Customer (created for API docs)",
email: "some.email@gmail.com",
address: {
city: 'Toronto',
country: 'CA',
line1: "Some Address",
line2: "Some unit number",
postal_code: "M5G0V1",
state: "ON",
},
name: "Some Name",
phone: "Some Number",
});
const price = await stripe.prices.create({
unit_amount: 599,
currency: 'cad',
recurring: {interval: 'month', interval_count: '1'},
product: 'prod_KZfHFK4nfCqlGS',
});
const subscriptionSchedule = await stripe.subscriptionSchedules.create({
customer: customer.id,
start_date: 'now',
end_behavior: 'cancel',
phases: [
{
items: [
{
price: price.id,
quantity: 1,
},
],
iterations: 24,
},
],
});
console.log(subscriptionSchedule);
const session = await stripe.checkout.sessions.create({
success_url: 'http://localhost:8080/stripeSessionSuccessHook',
cancel_url: 'http://localhost:8080/stripeSessionCancelHook',
payment_method_types: ['card'],
customer: customer.id,
line_items: [
{price: price.id, quantity: 1},
],
mode: 'subscription',
});
我正在尝试创建一个订阅服务,客户每月支付24个月的费用。我使用答案中建议的“订阅计划”,确实创建出了这样一个24个月的订阅服务。但是,当创建新的结帐时,在支付成功的情况下,它会创建一项为期12个月的订阅服务......最终,我有了两个订阅服务。一个是通过订阅计划创建的(24个月,预期的那个),另一个是订阅服务(12个月)。是否有办法将此订阅计划传递给结帐,以便不会创建2个订阅服务?