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"),
"HOST": env("POSTGRES_HOST"),
"PORT": env("POSTGRES_PORT"),
"OPTIONS": {
"pool": True,
},
},
}

View File

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