Reputation: 363
When calling stripe's api to update a customer's subscription, I am getting an error. When users perform actions on my site, they can earn free months for their subscription. To give users free months, I'm trying to update the trial_end
parameter to extend the free trial period. The error I'm getting is: Invalid trial_end must be one of now
new_end_dt = datetime.now() + timedelta(days=30)
new_end_ts = new_end_dt.replace(tzinfo=timezone.utc).timestamp()
stripe.Subscription.modify(
self.stripe_subscription_id,
trial_end=new_end_ts,
trial_from_plan=False,
)
Upvotes: 4
Views: 2667
Reputation: 363
It turns out that the timestamp that i was passing stripe had a decimal in it. The timestamp was 1560360533.0
and this was causing problems. When I truncate the timestamp to remove the decimal everything worked properly. here's the line of code that fixed it:
new_end_ts = round(new_end_dt.replace(tzinfo=timezone.utc).timestamp())
Upvotes: 15