所以我正在尝试创建一个将于 2020 年 10 月 10 日取消的月度订阅
我传递了这样一个对象:
return stripe.subscriptions.create ({
customer: customer.id,
items: [{plan: plan.id}],
expand: ["latest_invoice.payment_intent"],
cancel_at: new Date('2020-10-10').getTime()
}
但是在Stripe dashboard上,订阅是这样的:
而且我不明白我需要如何发送订阅取消日期才能在我想要的日期取消订阅 在此先感谢您的帮助!
最佳答案
JS
Date.getTime()
方法返回以毫秒为单位的时间。 stripe api 期望时间以秒为单位。
毫秒到秒的简单转换是:
Time in milliseconds / 1000 = Time in seconds
您的代码应该是:
const cancelAt = (new Date('2020-10-10').getTime()) / 1000;
return stripe.subscriptions.create ({
customer: customer.id,
items: [{plan: plan.id}],
expand: ["latest_invoice.payment_intent"],
cancel_at: cancelAt
}
关于javascript - Stripe 订阅 - 如何格式化 cancel_at 日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59519640/