From ee8145f07fd37c3fc6d42f212072a4b42048e91b Mon Sep 17 00:00:00 2001 From: i701 Date: Wed, 23 Apr 2025 10:43:39 +0500 Subject: [PATCH] Add environment variable checks for OMADA_PROXY_URL and enhance payment verification logic --- .env.example | 12 ++++++++---- billing/views.py | 26 +++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index f4c95ba..31b36a2 100644 --- a/.env.example +++ b/.env.example @@ -1,11 +1,12 @@ -DJANGO_DEBUG=False +CSRF_ALLOWED_HOST="" +DJANGO_DEBUG= SECRET_KEY="" POSTGRES_DATABASE= POSTGRES_USER= POSTGRES_PASSWORD= POSTGRES_HOST= POSTGRES_PORT= -DJANGO_SECURE_SSL_REDIRECT=False +DJANGO_SECURE_SSL_REDIRECT= ALLOWED_HOSTS="" CSRF_TRUSTED_ORIGINS="" CSRF_COOKIE_DOMAIN="" @@ -15,8 +16,11 @@ EMAIL_PORT= EMAIL_USERNAME= EMAIL_PASSWORD= + +OMADA_PROXY_URL="" PAYMENT_BASE_URL="" +PERSON_VERIFY_BASE_URL="" FRONTEND_URL="" -SMS_API_URL="" -SMS_API_KEY="" \ No newline at end of file +SMS_API_KEY="" +SMS_API_URL="" \ No newline at end of file diff --git a/billing/views.py b/billing/views.py index fa00d0f..e9bf102 100644 --- a/billing/views.py +++ b/billing/views.py @@ -20,6 +20,13 @@ import os env.read_env(os.path.join(BASE_DIR, ".env")) PAYMENT_BASE_URL = env("PAYMENT_BASE_URL", default=None) +OMADA_PROXY_URL = env("OMADA_PROXY_URL", default=None) + + +if not OMADA_PROXY_URL: + raise ValueError( + "OMADA_PROXY_URL is not set. Please set it in your environment variables." + ) if not PAYMENT_BASE_URL: raise ValueError( "PAYMENT_BASE_URL is not set. Please set it in your environment variables." @@ -168,8 +175,16 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView): # Update devices expiry_date = timezone.now() + timedelta(days=30 * payment.number_of_months) devices.update( - is_active=True, expiry_date=expiry_date, has_a_pending_payment=False + is_active=True, + expiry_date=expiry_date, + has_a_pending_payment=False, + registered=True, ) + # Need to add to omada if its a new device and not an existing device + for device in devices: + if not device.registered: + # Add to omada + pass return Response( {"message": f"Payment verified successfully using [{method}]."} @@ -228,3 +243,12 @@ class DeletePaymentView(StaffEditorPermissionMixin, generics.DestroyAPIView): devices = instance.devices.all() devices.update(is_active=False, expiry_date=None, has_a_pending_payment=False) return super().delete(request, *args, **kwargs) + + +def get_existing_devices(OMADA_SITE_ID: str, OMADA_GROUP_ID: str): + # Get existing devices from omada + response = requests.get( + f"{OMADA_PROXY_URL}/{OMADA_GROUP_ID}/api/v2/sites/{OMADA_SITE_ID}/setting/profiles/groups", + ) + response.raise_for_status() + return response.json()