Refactor VerifyPaymentView to improve wallet payment handling and response messages. Remove redundant insufficient funds check and enhance failure message clarity.
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 2m51s

This commit is contained in:
i701 2025-04-11 00:41:44 +05:00
parent f8253d572d
commit 10b3800171
Signed by: i701
GPG Key ID: 54A0DA1E26D8E587
2 changed files with 18 additions and 20 deletions

View File

@ -149,9 +149,6 @@ else:
"PASSWORD": env("POSTGRES_PASSWORD"), "PASSWORD": env("POSTGRES_PASSWORD"),
"HOST": env("POSTGRES_HOST"), "HOST": env("POSTGRES_HOST"),
"PORT": env("POSTGRES_PORT"), "PORT": env("POSTGRES_PORT"),
"OPTIONS": {
"pool": True,
},
}, },
} }

View File

@ -123,10 +123,16 @@ 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":
payment_status = self.process_wallet_payment( if user.wallet_balance < payment.amount:
user, return Response(
payment, {"message": "Insufficient funds in wallet."},
) status=status.HTTP_400_BAD_REQUEST,
)
else:
payment_status = self.process_wallet_payment(
user,
payment,
)
if method == "TRANSFER": if method == "TRANSFER":
data = { data = {
"benefName": f"{user.first_name} {user.last_name}", "benefName": f"{user.first_name} {user.last_name}",
@ -148,17 +154,14 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
return Response( return Response(
{"message": f"Payment verified successfully using [{method}]."} {"message": f"Payment verified successfully using [{method}]."}
) )
else:
return Response({"message": "Payment verified successfully using [{method}]."}) return Response(
{"message": "Payment verification FAILED using [{method}]."}
)
def process_wallet_payment(self, user, payment): def process_wallet_payment(self, user, payment):
print("processing wallet payment...") print("processing wallet payment...")
print(user, payment.amount) print(user, payment.amount)
if user.wallet_balance < payment.amount:
return Response(
{"message": "Insufficient funds in wallet."},
status=status.HTTP_400_BAD_REQUEST,
)
payment.paid = True payment.paid = True
payment.paid_at = timezone.now() payment.paid_at = timezone.now()
@ -177,13 +180,11 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
headers={"Content-Type": "application/json"}, headers={"Content-Type": "application/json"},
) )
response.raise_for_status() response.raise_for_status()
print(response.json()) mib_resp = response.json()
if not response.json().get("success"): if not response.json().get("success"):
return Response( return mib_resp["success"]
{"message": "MIB Payment verification failed."}, else:
status=status.HTTP_400_BAD_REQUEST, return True
)
return True
class DeletePaymentView(StaffEditorPermissionMixin, generics.DestroyAPIView): class DeletePaymentView(StaffEditorPermissionMixin, generics.DestroyAPIView):