Stripe Create Usage Record Error - Timestamp must be before the subscription's current period end time - Date.now()?

爱⌒轻易说出口 提交于 2020-01-14 14:35:51

问题


I'm trying to create a stripe usage record for a customer on a metered plan.

When I'm using timestamp Date.now() in my request. The error I'm receiving is

"Cannot create the usage record with this timestamp because timestamps must be before the subscription's current period end time"

This seems self-explanatory. But given the subscription's current period end time isn't for another 14 days, how can Date.now() not be before this.

        await stripe.usageRecords.create(
            'si_EwzQ....',
            {
                quantity: 2,
                timestamp: Date.now(),
                action: 'set'
            }
        )

Is this because the current subscription period is a trial? Or have I misunderstood something here?


回答1:


They're using a slightly different timestamp here. You must divide it by 1000.

So Date.now() / 1000




回答2:


Node.JS uses millisecond timescales, so you are saying the current time is 1000 times more seconds than it currently is.

Just do this first var currentTimestamp = Date.now()/1000



来源:https://stackoverflow.com/questions/55848108/stripe-create-usage-record-error-timestamp-must-be-before-the-subscriptions-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!