mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-04-19 23:46:53 +00:00
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
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 2m51s
This commit is contained in:
parent
f8253d572d
commit
10b3800171
@ -149,9 +149,6 @@ else:
|
||||
"PASSWORD": env("POSTGRES_PASSWORD"),
|
||||
"HOST": env("POSTGRES_HOST"),
|
||||
"PORT": env("POSTGRES_PORT"),
|
||||
"OPTIONS": {
|
||||
"pool": True,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -123,10 +123,16 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
|
||||
devices = payment.devices.all()
|
||||
payment_status = False
|
||||
if method == "WALLET":
|
||||
payment_status = self.process_wallet_payment(
|
||||
user,
|
||||
payment,
|
||||
)
|
||||
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,
|
||||
)
|
||||
if method == "TRANSFER":
|
||||
data = {
|
||||
"benefName": f"{user.first_name} {user.last_name}",
|
||||
@ -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,13 +180,11 @@ 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 True
|
||||
return mib_resp["success"]
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
class DeletePaymentView(StaffEditorPermissionMixin, generics.DestroyAPIView):
|
||||
|
Loading…
x
Reference in New Issue
Block a user