From 509c8e7718115a438aa250276d1cd7e032b4f329 Mon Sep 17 00:00:00 2001 From: rizwanisready Date: Mon, 15 Apr 2024 15:12:58 +0530 Subject: [PATCH] Payment Service 1 --- goodtimes/services.py | 31 ++++++++++++++++++------------- manage_subscriptions/views.py | 10 ---------- templates/stripe_html/index.html | 4 ++-- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/goodtimes/services.py b/goodtimes/services.py index 1b86ab9..8f4f6ca 100644 --- a/goodtimes/services.py +++ b/goodtimes/services.py @@ -214,12 +214,9 @@ class PaymentProcessingService: return self.charge_data.get("customer", None) def _get_transaction_by_id(self): - # print("self.webhook_data: ", self.webhook_data) - # print("self.charge_data: ", self.charge_data) print("self.metadata: ", self.charge_data["metadata"]) - # Extract transaction_id from webhook metadata transaction_id = self.charge_data["metadata"]["transaction_id"] - # Fetch the Transaction instance using the transaction_id + print("_get_transaction_by_id: ", transaction_id) return Transaction.objects.get(id=int(transaction_id)) def _get_principal_subscription_by_id(self): @@ -402,7 +399,9 @@ class EventFilterService: @staticmethod def filter_events_by_search(search_query=None): today = timezone.now().date() - filtered_events = Event.objects.filter(deleted=False, active=True, draft=False) + filtered_events = Event.objects.filter( + deleted=False, active=True, draft=False, created_by__is_active=True + ) # Optional search filtering on title and key_guest (modify as needed) if search_query: @@ -428,7 +427,11 @@ class EventFilterService: if search_query: print("search_query: ", search_query) filtered_events = Event.objects.filter( - tags__isnull=False, deleted=False, active=True, draft=False + tags__isnull=False, + deleted=False, + active=True, + draft=False, + created_by__is_active=True, ) filtered_events = ( @@ -457,9 +460,9 @@ class EventFilterService: today = timezone.now().date() events = Event.objects.none() - current_and_future_events_query = Q(active=True, deleted=False, draft=False) & ( - Q(start_date__lte=today, end_date__gte=today) | Q(start_date__gt=today) - ) + current_and_future_events_query = Q( + active=True, deleted=False, draft=False, created_by__is_active=True + ) & (Q(start_date__lte=today, end_date__gte=today) | Q(start_date__gt=today)) if filter_type == "expensive": events = Event.objects.filter(current_and_future_events_query).order_by( @@ -480,6 +483,7 @@ class EventFilterService: draft=False, active=True, deleted=False, + created_by__is_active=True, ).distinct() return events @@ -488,9 +492,9 @@ class EventFilterService: def filter_events_by_category(category_id): today = timezone.now().date() - current_and_future_events_query = Q(active=True, deleted=False, draft=False) & ( - Q(start_date__lte=today, end_date__gte=today) | Q(start_date__gt=today) - ) + current_and_future_events_query = Q( + active=True, deleted=False, draft=False, created_by__is_active=True + ) & (Q(start_date__lte=today, end_date__gte=today) | Q(start_date__gt=today)) # Ensure the category_id is valid and within the specified range (1-8) if 1 <= category_id <= 8: @@ -516,7 +520,7 @@ class EventFilterService: | (Q(start_date__lte=tomorrow) & Q(end_date__gte=tomorrow)) ) events = Event.objects.filter( - events_query, active=True, deleted=False, draft=False + events_query, active=True, deleted=False, draft=False, created_by__is_active=True, ).distinct() return events @@ -532,6 +536,7 @@ class EventFilterService: draft=False, start_date__lte=today, end_date__gte=today, + created_by__is_active=True, ) return events diff --git a/manage_subscriptions/views.py b/manage_subscriptions/views.py index 5246f99..87a1816 100644 --- a/manage_subscriptions/views.py +++ b/manage_subscriptions/views.py @@ -412,15 +412,6 @@ def create_checkout_session(request): data = json.loads(request.body) print("data: ", data) subscription_id = data.get("subscriptionId", None) - # if request.method == "GET": - # subscription_id = None # Assuming 3 is a default or fallback subscription ID - - # if request.user.is_authenticated: - # print("request.user: ", request.user) - # if request.user.principal_type.name == "event_user": - # subscription_id = 2 - # elif request.user.principal_type.name == "event_manager": - # subscription_id = 1 try: subscription = Subscription.objects.get(id=subscription_id) @@ -504,7 +495,6 @@ def create_checkout_session(request): "transaction_id": str(transaction.id), "principal_subscription_id": str(principal_subscription.id), }, - # Optionally, set shipping options, allow promotion codes, etc. ) return JsonResponse({"sessionId": checkout_session["id"]}) except Exception as e: diff --git a/templates/stripe_html/index.html b/templates/stripe_html/index.html index 7da8800..0789c9c 100644 --- a/templates/stripe_html/index.html +++ b/templates/stripe_html/index.html @@ -246,9 +246,9 @@ -
+