mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-06-06 23:46: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=""))
|
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:
|
if not api_url or not api_key:
|
||||||
logger.debug("Failed to send SMS. Missing SMS_API_URL or SMS_API_KEY.")
|
logger.debug("Failed to send SMS. Missing SMS_API_URL or SMS_API_KEY.")
|
||||||
return False
|
return False
|
||||||
|
@ -12,18 +12,16 @@ from rest_framework.response import Response
|
|||||||
from api.mixins import StaffEditorPermissionMixin
|
from api.mixins import StaffEditorPermissionMixin
|
||||||
from api.tasks import add_new_devices_to_omada
|
from api.tasks import add_new_devices_to_omada
|
||||||
from apibase.env import BASE_DIR, env
|
from apibase.env import BASE_DIR, env
|
||||||
|
import logging
|
||||||
|
|
||||||
from .models import Device, Payment
|
from .models import Device, Payment
|
||||||
from .serializers import PaymentSerializer, UpdatePaymentSerializer
|
from .serializers import PaymentSerializer, UpdatePaymentSerializer
|
||||||
|
|
||||||
env.read_env(os.path.join(BASE_DIR, ".env"))
|
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:
|
logger = logging.getLogger(__name__)
|
||||||
raise ValueError(
|
|
||||||
"PAYMENT_BASE_URL is not set. Please set it in your environment variables."
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class InsufficientFundsError(Exception):
|
class InsufficientFundsError(Exception):
|
||||||
@ -142,7 +140,7 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
|||||||
devices = payment.devices.all()
|
devices = payment.devices.all()
|
||||||
payment_status = False
|
payment_status = False
|
||||||
if method == "WALLET":
|
if method == "WALLET":
|
||||||
if user.wallet_balance < payment.amount:
|
if user.wallet_balance < payment.amount: # type: ignore
|
||||||
return Response(
|
return Response(
|
||||||
{"message": "Insufficient funds in wallet."},
|
{"message": "Insufficient funds in wallet."},
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
@ -154,8 +152,8 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
|||||||
)
|
)
|
||||||
if method == "TRANSFER":
|
if method == "TRANSFER":
|
||||||
data = {
|
data = {
|
||||||
"benefName": f"{user.first_name} {user.last_name}",
|
"benefName": f"{user.first_name} {user.last_name}", # type: ignore
|
||||||
"accountNo": user.acc_no,
|
"accountNo": user.acc_no, # type: ignore
|
||||||
"absAmount": payment.amount,
|
"absAmount": payment.amount,
|
||||||
"time": localtime(timezone.now() + timedelta(minutes=5)).strftime(
|
"time": localtime(timezone.now() + timedelta(minutes=5)).strftime(
|
||||||
"%Y-%m-%d %H:%M"
|
"%Y-%m-%d %H:%M"
|
||||||
@ -209,7 +207,11 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def verify_transfer_payment(self, data, payment):
|
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(
|
response = requests.post(
|
||||||
f"{PAYMENT_BASE_URL}/verify-payment",
|
f"{PAYMENT_BASE_URL}/verify-payment",
|
||||||
json=data,
|
json=data,
|
||||||
@ -217,6 +219,7 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
|||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
mib_resp = response.json()
|
mib_resp = response.json()
|
||||||
|
print(mib_resp)
|
||||||
if not response.json().get("success"):
|
if not response.json().get("success"):
|
||||||
return mib_resp["success"]
|
return mib_resp["success"]
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user