Eth*_*han 0 datetime node.js stripe-payments
我正在使用 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)
})
})
Run Code Online (Sandbox Code Playgroud)
该代码故意创建错误以获取准确的服务器时间,然后进行实际stripe.subscriptions.create调用。
当我打电话时stripe.subscriptions.create,Stripe 给了我这个错误:
时间戳无效:不能超过未来五年
在这种情况下,我的代码给它的时间戳是1535104976000. 它包含在错误消息标题中:
date: 'Fri, 24 Aug 2018 10:02:27 GMT'
Run Code Online (Sandbox Code Playgroud)
转换为一个纪元,即1535104947000。
所以,我的时间绝对不会比他们提前5年!到底是怎么回事?
| 归档时间: |
|
| 查看次数: |
1168 次 |
| 最近记录: |