mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-04-30 13:55:41 +00:00
Add environment variable checks for OMADA_PROXY_URL and enhance payment verification logic
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m52s
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m52s
This commit is contained in:
parent
929c6168a4
commit
ee8145f07f
12
.env.example
12
.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=""
|
||||
SMS_API_KEY=""
|
||||
SMS_API_URL=""
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user