mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 13:18:18 +00:00
Fix handling of customer.subscription.updated event to process new renewal end date
This commit is contained in:
@@ -66,11 +66,18 @@ async def subscribe(request: Request):
|
||||
success = user is not None
|
||||
elif event_type in {"customer.subscription.updated"}:
|
||||
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
|
||||
if user_subscription and user_subscription.renewal_date:
|
||||
# Mark user as unsubscribed or resubscribed
|
||||
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
|
||||
elif event_type in {"customer.subscription.deleted"}:
|
||||
# Reset the user to trial state
|
||||
|
||||
Reference in New Issue
Block a user