From 3ef271f3d6ee2cd80947d4fe342edfd5bf92ca1c Mon Sep 17 00:00:00 2001 From: Jhony Lucas Date: Wed, 28 Aug 2024 23:16:47 -0300 Subject: [PATCH] feat: add more fields related to Stripe (#665) --- backend/apps/account/models.py | 14 +++++++++++++- backend/custom/graphql_jwt.py | 10 +++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/backend/apps/account/models.py b/backend/apps/account/models.py index 430ccdd6..52dee4c8 100644 --- a/backend/apps/account/models.py +++ b/backend/apps/account/models.py @@ -557,7 +557,19 @@ def is_pro(self): @property def canceled_at(self): if self.subscription: - return self.subscription.canceled_at.isoformat() + return self.subscription.cancel_at.isoformat() + return None + + @property + def plan_interval(self): + if self.subscription: + return self.subscription.plan.interval + return None + + @property + def next_billing_cycle(self): + if self.subscription: + return self.subscription.current_period_end.isoformat() return None diff --git a/backend/custom/graphql_jwt.py b/backend/custom/graphql_jwt.py index f13a3e60..2974a298 100644 --- a/backend/custom/graphql_jwt.py +++ b/backend/custom/graphql_jwt.py @@ -146,5 +146,13 @@ def mutate(cls, *args, **kwargs): email = response.payload.get("email") user = Account.objects.get(email=email) if user: - response.payload.update({"pro_subscription_status": user.pro_subscription_status}) + subscription = user.pro_owner_subscription or user.pro_member_subscription + is_subscription_active = subscription.is_active if subscription else False + + response.payload.update( + { + "pro_subscription_status": user.pro_subscription_status, + "is_subscription_active": is_subscription_active, + } + ) return response