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"),
|
"PASSWORD": env("POSTGRES_PASSWORD"),
|
||||||
"HOST": env("POSTGRES_HOST"),
|
"HOST": env("POSTGRES_HOST"),
|
||||||
"PORT": env("POSTGRES_PORT"),
|
"PORT": env("POSTGRES_PORT"),
|
||||||
"OPTIONS": {
|
|
||||||
"pool": True,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +123,12 @@ 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:
|
||||||
|
return Response(
|
||||||
|
{"message": "Insufficient funds in wallet."},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
else:
|
||||||
payment_status = self.process_wallet_payment(
|
payment_status = self.process_wallet_payment(
|
||||||
user,
|
user,
|
||||||
payment,
|
payment,
|
||||||
@ -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,12 +180,10 @@ 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
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user