node.js - Stripe –“无效的时间戳:未来不能超过五年”
问题描述
我正在使用 Node.js Stripe 包,我想向客户添加一个新订阅,该订阅将在 30 秒后到期。这是我的代码:
var toCreate = {
customer: 'customer_id',
items: [{
plan: 'plan_id'
}],
coupon: 'coupon_code',
}
stripe.customers.create({xyz: 'This will give an error with the server time in the header'}).then(success => {},
error => {
var seconds = 30;
toCreate.trial_end = new Date(error.raw.headers.date).getTime() + (seconds * 1000);
console.log('End time', toCreate.trial_end);
return stripe.subscriptions.create(toCreate).then(successful => {
console.log(successful)
}, error => {
console.log(error)
})
})
该代码故意创建错误以获取准确的服务器时间,然后进行实际stripe.subscriptions.create
调用。
当我打电话时stripe.subscriptions.create
,Stripe 给了我这个错误:
无效的时间戳:不能超过未来五年
在这种情况下,我的代码给出的时间戳是1535104976000
. 它包含在错误消息标题中:
date: 'Fri, 24 Aug 2018 10:02:27 GMT'
转换为一个纪元,即1535104947000
.
所以,我的时间绝对不会比他们早5年!地球上发生了什么?
解决方案
似乎它与时间戳有关。PHP 时间戳以秒为单位,而 JavaScript 时间戳以毫秒为单位。您是否尝试过除以 1000?
推荐阅读
- flutter - DropdownButtonFormField 导致 RenderFlex 溢出
- flutter - 如何在颤振中集成 facebook 登录?
- powershell - 即使加载程序集,SMO Powershell 也会损坏
- r - 如何在 R 中读取 SharePoint 列表(本地)
- python - 用户输入以使用 python 在字典中显示某些值
- haskell - Haskell async:在 withAsync 中使用不同类型的 Monad
- fastapi - 在 GET 请求中使用 pydantic 验证器
- c# - 无法从 Windows 服务中运行 SWGVC.exe
- python - 如何使用“另存为”提示保存来自 interactive() 显示的 .svg 输出?
- python - 尝试在 Mac m1 上安装 opencv-python 时 ceres 出错