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
+44 -21
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." return PaymentVerificationResponse(
message="Payment gateway is not configured. Please contact support.",
success=False,
transaction=None,
) )
try:
response = requests.post( response = requests.post(
f"{PAYMENT_BASE_URL}/verify-payment", f"{PAYMENT_BASE_URL}/verify-payment",
json=data, json=data,
headers={"Content-Type": "application/json"}, headers={"Content-Type": "application/json"},
) )
logger.info("MIB Verification Response -> ", response)
try:
response.raise_for_status() response.raise_for_status()
except requests.exceptions.HTTPError as e:
logger.error(f"HTTPError: {e}")
return PaymentVerificationResponse(
message="Payment verification failed.", success=False, transaction=None
)
mib_resp = response.json() mib_resp = response.json()
logger.info("MIB Verification Response ->", mib_resp) except requests.exceptions.RequestException as e:
if not response.json().get("success"): 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)
try:
response = requests.post( response = requests.post(
f"{PAYMENT_BASE_URL}/verify-payment", f"{PAYMENT_BASE_URL}/verify-payment",
json=data, json=data,
headers={"Content-Type": "application/json"}, headers={"Content-Type": "application/json"},
) )
try:
response.raise_for_status() response.raise_for_status()
except requests.exceptions.HTTPError as e:
logger.error(f"HTTPError: {e}")
return PaymentVerificationResponse(
message="Payment verification failed.", success=False, transaction=None
)
mib_resp = response.json() mib_resp = response.json()
print(mib_resp) except requests.exceptions.RequestException as e:
if not response.json().get("success"): 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"],