简体   繁体   中英

stripe.Customer.list returns wrong customers

I'm currently doing a query to try and find the total number of customers between yesterday's utc0 and todays utc0, for some reason though it returns customers made the first hour or so after utc0

import stripe
from datetime import datetime, timedelta
stripe.api_key = app_config.STRIPE_KEY['secret_key']

yesterday_utc = datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0) - timedelta(1)
today_utc = datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0)
print(len(stripe.Customer.list(created={"gte":yesterday_utc, "lte":today_utc})['data']))

Not sure if I'm calling the wrong utc time, but this returns the customers made yesterday + the ones that where made immediately after the reset of the UTC day

datetime.utcnow() returns the current timestamp in UTC, but you then replace the "hour-minute-second" part of the timestamp with zeroes. That's not the same thing as computing the timestamp for midnight UTC.

See this StackOverflow answer for how to reliably compute timestamps for midnight UTC depending on your timezone: https://stackoverflow.com/a/381788/5307473 .

Keep in mind that Stripe's API expects UNIX timestamps, so you should call .strftime('%s') on your datetime instances to convert them to UNIX timestamps.

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