Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 280
aevansme Avatar asked Oct 17 '25 08:10

aevansme


1 Answers

Stripe is using a slightly different timestamp here. It's the number of seconds. You must divide it by 1000.

  1. So Date.now() / 1000 shall work.
  2. However, Stripe APIs expects a whole number so Math.ceil(Date.now() / 1000) or (Date.now() / 1000).toFixed(0) should work. (@William's comment, verified)
like image 131
Christian Avatar answered Oct 18 '25 23:10

Christian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!