From 5b4d0e6488fe3a874e61dc5d232e52098426ea53 Mon Sep 17 00:00:00 2001 From: i701 Date: Fri, 30 May 2025 22:15:14 +0500 Subject: [PATCH] Refactor send_otp function to remove unused otp parameter and improve clarity --- api/sms.py | 2 +- billing/views.py | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/api/sms.py b/api/sms.py index 008c878..4d330d5 100644 --- a/api/sms.py +++ b/api/sms.py @@ -8,7 +8,7 @@ api_url = str(config("SMS_API_URL", cast=str, default="")) api_key = str(config("SMS_API_KEY", cast=str, default="")) -def send_otp(mobile: str, otp: str, message: str): +def send_otp(mobile: str, message: str): if not api_url or not api_key: logger.debug("Failed to send SMS. Missing SMS_API_URL or SMS_API_KEY.") return False diff --git a/billing/views.py b/billing/views.py index 21efb7b..7403e60 100644 --- a/billing/views.py +++ b/billing/views.py @@ -12,18 +12,16 @@ from rest_framework.response import Response from api.mixins import StaffEditorPermissionMixin from api.tasks import add_new_devices_to_omada from apibase.env import BASE_DIR, env +import logging from .models import Device, Payment from .serializers import PaymentSerializer, UpdatePaymentSerializer env.read_env(os.path.join(BASE_DIR, ".env")) -PAYMENT_BASE_URL = env("PAYMENT_BASE_URL", default=None) +PAYMENT_BASE_URL = env("PAYMENT_BASE_URL", default="") # type: ignore -if not PAYMENT_BASE_URL: - raise ValueError( - "PAYMENT_BASE_URL is not set. Please set it in your environment variables." - ) +logger = logging.getLogger(__name__) class InsufficientFundsError(Exception): @@ -142,7 +140,7 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView): devices = payment.devices.all() payment_status = False if method == "WALLET": - if user.wallet_balance < payment.amount: + if user.wallet_balance < payment.amount: # type: ignore return Response( {"message": "Insufficient funds in wallet."}, status=status.HTTP_400_BAD_REQUEST, @@ -154,8 +152,8 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView): ) if method == "TRANSFER": data = { - "benefName": f"{user.first_name} {user.last_name}", - "accountNo": user.acc_no, + "benefName": f"{user.first_name} {user.last_name}", # type: ignore + "accountNo": user.acc_no, # type: ignore "absAmount": payment.amount, "time": localtime(timezone.now() + timedelta(minutes=5)).strftime( "%Y-%m-%d %H:%M" @@ -209,7 +207,11 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView): return True def verify_transfer_payment(self, data, payment): - print(data) + if not PAYMENT_BASE_URL: + raise ValueError( + "PAYMENT_BASE_URL is not set. Please set it in your environment variables." + ) + logger.info(data) response = requests.post( f"{PAYMENT_BASE_URL}/verify-payment", json=data, @@ -217,6 +219,7 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView): ) response.raise_for_status() mib_resp = response.json() + print(mib_resp) if not response.json().get("success"): return mib_resp["success"] else: