mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 15:38:55 +01:00
Fix handling of customer.subscription.updated event to process new renewal end date
This commit is contained in:
parent
6a054d884b
commit
a761865724
1 changed files with 8 additions and 1 deletions
|
@ -66,11 +66,18 @@ async def subscribe(request: Request):
|
||||||
success = user is not None
|
success = user is not None
|
||||||
elif event_type in {"customer.subscription.updated"}:
|
elif event_type in {"customer.subscription.updated"}:
|
||||||
user_subscription = await sync_to_async(adapters.get_user_subscription)(customer_email)
|
user_subscription = await sync_to_async(adapters.get_user_subscription)(customer_email)
|
||||||
|
|
||||||
|
renewal_date = False
|
||||||
|
if subscription["current_period_end"]:
|
||||||
|
renewal_date = datetime.fromtimestamp(subscription["current_period_end"], tz=timezone.utc)
|
||||||
|
|
||||||
# Allow updating subscription status if paid user
|
# Allow updating subscription status if paid user
|
||||||
if user_subscription and user_subscription.renewal_date:
|
if user_subscription and user_subscription.renewal_date:
|
||||||
# Mark user as unsubscribed or resubscribed
|
# Mark user as unsubscribed or resubscribed
|
||||||
is_recurring = not subscription["cancel_at_period_end"]
|
is_recurring = not subscription["cancel_at_period_end"]
|
||||||
user, is_new = await adapters.set_user_subscription(customer_email, is_recurring=is_recurring)
|
user, is_new = await adapters.set_user_subscription(
|
||||||
|
customer_email, is_recurring=is_recurring, renewal_date=renewal_date
|
||||||
|
)
|
||||||
success = user is not None
|
success = user is not None
|
||||||
elif event_type in {"customer.subscription.deleted"}:
|
elif event_type in {"customer.subscription.deleted"}:
|
||||||
# Reset the user to trial state
|
# Reset the user to trial state
|
||||||
|
|
Loading…
Reference in a new issue