handle payment erros better
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 6s

This commit is contained in:
2026-08-02 15:11:46 +05:00
parent 1ea2f9f4c2
commit 3397f212b5
+55 -32
View File
@@ -327,25 +327,36 @@ class VerifyPaymentView(StaffEditorPermissionMixin, generics.UpdateAPIView):
def verify_transfer_payment(self, data, payment) -> PaymentVerificationResponse: def verify_transfer_payment(self, data, payment) -> PaymentVerificationResponse:
if not PAYMENT_BASE_URL: if not PAYMENT_BASE_URL:
raise ValueError( logger.error("PAYMENT_BASE_URL is not set.")
"PAYMENT_BASE_URL is not set. Please set it in your environment variables."
)
response = requests.post(
f"{PAYMENT_BASE_URL}/verify-payment",
json=data,
headers={"Content-Type": "application/json"},
)
logger.info("MIB Verification Response -> ", response)
try:
response.raise_for_status()
except requests.exceptions.HTTPError as e:
logger.error(f"HTTPError: {e}")
return PaymentVerificationResponse( return PaymentVerificationResponse(
message="Payment verification failed.", success=False, transaction=None message="Payment gateway is not configured. Please contact support.",
success=False,
transaction=None,
) )
mib_resp = response.json() try:
logger.info("MIB Verification Response ->", mib_resp) response = requests.post(
if not response.json().get("success"): f"{PAYMENT_BASE_URL}/verify-payment",
json=data,
headers={"Content-Type": "application/json"},
)
response.raise_for_status()
mib_resp = response.json()
except requests.exceptions.RequestException as e:
logger.error(f"MIB request failed: {e}")
return PaymentVerificationResponse(
message="Unable to reach the payment gateway. Please try again or contact support.",
success=False,
transaction=None,
)
except ValueError as e:
logger.error(f"MIB returned an invalid response: {e}")
return PaymentVerificationResponse(
message="Received an invalid response from the payment gateway. Please contact support.",
success=False,
transaction=None,
)
logger.info("MIB Verification Response -> %s", mib_resp)
if not mib_resp.get("success"):
return PaymentVerificationResponse( return PaymentVerificationResponse(
message=mib_resp["message"], message=mib_resp["message"],
success=mib_resp["success"], success=mib_resp["success"],
@@ -471,25 +482,37 @@ class VerifyTopupPaymentAPIView(StaffEditorPermissionMixin, generics.UpdateAPIVi
def verify_transfer_topup(self, data, topup) -> PaymentVerificationResponse: def verify_transfer_topup(self, data, topup) -> PaymentVerificationResponse:
if not PAYMENT_BASE_URL: if not PAYMENT_BASE_URL:
raise ValueError( logger.error("PAYMENT_BASE_URL is not set.")
"PAYMENT_BASE_URL is not set. Please set it in your environment variables." return PaymentVerificationResponse(
message="Payment gateway is not configured. Please contact support.",
success=False,
transaction=None,
) )
logger.info(data) logger.info(data)
response = requests.post(
f"{PAYMENT_BASE_URL}/verify-payment",
json=data,
headers={"Content-Type": "application/json"},
)
try: try:
response.raise_for_status() response = requests.post(
except requests.exceptions.HTTPError as e: f"{PAYMENT_BASE_URL}/verify-payment",
logger.error(f"HTTPError: {e}") json=data,
return PaymentVerificationResponse( headers={"Content-Type": "application/json"},
message="Payment verification failed.", success=False, transaction=None
) )
mib_resp = response.json() response.raise_for_status()
print(mib_resp) mib_resp = response.json()
if not response.json().get("success"): except requests.exceptions.RequestException as e:
logger.error(f"MIB request failed: {e}")
return PaymentVerificationResponse(
message="Unable to reach the payment gateway. Please try again or contact support.",
success=False,
transaction=None,
)
except ValueError as e:
logger.error(f"MIB returned an invalid response: {e}")
return PaymentVerificationResponse(
message="Received an invalid response from the payment gateway. Please contact support.",
success=False,
transaction=None,
)
logger.info("MIB Verification Response -> %s", mib_resp)
if not mib_resp.get("success"):
return PaymentVerificationResponse( return PaymentVerificationResponse(
message=mib_resp["message"], message=mib_resp["message"],
success=mib_resp["success"], success=mib_resp["success"],