首页 > 解决方案 > 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年!地球上发生了什么?

标签: node.jsdatetimestripe-payments

解决方案


似乎它与时间戳有关。PHP 时间戳以秒为单位,而 JavaScript 时间戳以毫秒为单位。您是否尝试过除以 1000?


推荐阅读