简体   繁体   中英

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

I am creating a flask app that integrates with Stripe for subscriptions.

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

datetime = str(int(dt.now().replace(tzinfo=tz.utc).timestamp()))
stripe.SubscriptionItem.create_usage_record(subscription_item, quantity='1',timestamp=datetime)

However i get the error:

stripe.error.InvalidRequestError: Request req_uq0tJXmT43BjHy: Cannot create the usage record with this timestamp because timestamps must be before the subscription's current period end time.

This is despite the fact the subscription's current period end time isn't for another month.

What's strange further, is I was able to create usage records fine previously.

I found the following question on SO: Stripe Create Usage Record Error - Timestamp must be before the subscription's current period end time - Date.now()?

and so adapted my code to the following:

datetime = str(int(dt.now().replace(tzinfo=tz.utc).timestamp()/1000))
stripe.SubscriptionItem.create_usage_record(subscription_item, quantity='1',timestamp=datetime)

Not sure if this was the right thing to do for my case, but again it led to the same error.

Can anyone help please? Many thanks in advance

I figured out what id done wrong. My initial code worked fine. However, with my tests id set up lots of testing accounts with the same email, and so my i was trying to subscribe to an old account. hence wasnt working. but the code was fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM