mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-06-05 16:56:19 +00:00
Refactor send_otp function to remove unused otp parameter and improve clarity
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 2m35s
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 2m35s
This commit is contained in:
parent
e0dfc28590
commit
5b4d0e6488
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user