Added some fail safes for inconsequential errors.

This commit is contained in:
Ty Reynolds
2026-05-27 13:19:12 -04:00
parent 8c4f1f753e
commit 7789d13584

View File

@@ -157,6 +157,17 @@ Response:
if success == "1": if success == "1":
frappe.log_error(
f"""
PAYMENT SUCCESS FAILSAFE
Invoice: {invoice}
Transaction ID: {transaction_id}
Amount: {payload['amount']}
""",
"PAYMENT SUCCESS FAILSAFE"
)
if payment_type == "check": if payment_type == "check":
mode_of_payment = "ACH" mode_of_payment = "ACH"
else: else:
@@ -175,12 +186,23 @@ Response:
"duplicate": True "duplicate": True
} }
create_payment_entry( try:
invoice=invoice,
amount=payload["amount"], create_payment_entry(
transaction_id=transaction_id, invoice=invoice,
mode_of_payment=mode_of_payment amount=payload["amount"],
) transaction_id=transaction_id,
mode_of_payment=mode_of_payment
)
frappe.db.commit()
except Exception:
frappe.log_error(
frappe.get_traceback(),
"PAYMENT ENTRY FAILURE AFTER SUCCESSFUL CHARGE"
)
return { return {
"success": True, "success": True,
@@ -379,6 +401,17 @@ Response:
)[0] )[0]
} }
frappe.log_error(
f"""
PAYMENT SUCCESS FAILSAFE
Invoice: {invoice}
Transaction ID: {transaction_id}
Amount: {inv.outstanding_amount}
""",
"PAYMENT SUCCESS FAILSAFE"
)
existing_pe = frappe.db.exists( existing_pe = frappe.db.exists(
"Payment Entry", "Payment Entry",
{"reference_no": transaction_id} {"reference_no": transaction_id}
@@ -386,54 +419,74 @@ Response:
if not existing_pe: if not existing_pe:
create_payment_entry( try:
invoice=invoice,
amount=inv.outstanding_amount, create_payment_entry(
transaction_id=transaction_id, invoice=invoice,
mode_of_payment="Credit Card" amount=inv.outstanding_amount,
) transaction_id=transaction_id,
mode_of_payment="Credit Card"
)
frappe.db.commit()
except Exception:
frappe.log_error(
frappe.get_traceback(),
"PAYMENT ENTRY FAILURE AFTER SUCCESSFUL CHARGE"
)
# Save AutoPay info locally # Save AutoPay info locally
if save_autopay and vault_id: if save_autopay and vault_id:
customer.custom_auto_pay_id = ( try:
vault_id
)
customer.custom_auto_pay_status = 1 customer.custom_auto_pay_id = (
vault_id
)
customer.custom_auto_pay_first_name = ( customer.custom_auto_pay_status = 1
first_name
)
customer.custom_auto_pay_last_name = ( customer.custom_auto_pay_first_name = (
last_name first_name
) )
customer.custom_auto_pay_company = ( customer.custom_auto_pay_last_name = (
company last_name
) )
customer.custom_auto_pay_zip = ( customer.custom_auto_pay_company = (
billing_zip company
) )
customer.save( customer.custom_auto_pay_zip = (
ignore_permissions=True billing_zip
) )
frappe.db.commit() customer.save(
ignore_permissions=True
)
frappe.log_error( frappe.db.commit()
f"""
frappe.log_error(
f"""
Vault save complete Vault save complete
customer={customer.name} customer={customer.name}
vault_id={vault_id} vault_id={vault_id}
""", """,
"AUTOPAY DEBUG - SAVE COMPLETE" "AUTOPAY DEBUG - SAVE COMPLETE"
) )
except Exception:
frappe.log_error(
frappe.get_traceback(),
"AUTOPAY CUSTOMER SAVE FAILED"
)
return { return {
"success": True, "success": True,
@@ -551,31 +604,40 @@ def save_to_autopay(
or "duplicate" in message.lower() or "duplicate" in message.lower()
): ):
cust.custom_auto_pay_id = ( try:
returned_vault_id
)
cust.custom_auto_pay_status = 1 cust.custom_auto_pay_id = (
returned_vault_id
)
cust.custom_auto_pay_first_name = ( cust.custom_auto_pay_status = 1
first_name
)
cust.custom_auto_pay_last_name = ( cust.custom_auto_pay_first_name = (
last_name first_name
) )
cust.custom_auto_pay_company = ( cust.custom_auto_pay_last_name = (
company last_name
) )
cust.custom_auto_pay_zip = ( cust.custom_auto_pay_company = (
billing_zip company
) )
cust.save(ignore_permissions=True) cust.custom_auto_pay_zip = (
billing_zip
)
frappe.db.commit() cust.save(ignore_permissions=True)
frappe.db.commit()
except Exception:
frappe.log_error(
frappe.get_traceback(),
"AUTOPAY CUSTOMER SAVE FAILED"
)
return { return {
"success": True, "success": True,
@@ -606,12 +668,23 @@ def crystalclear_webhook():
else: else:
mode_of_payment = "Credit Card" mode_of_payment = "Credit Card"
create_payment_entry( try:
invoice=invoice,
amount=amount, create_payment_entry(
transaction_id=transaction_id, invoice=invoice,
mode_of_payment=mode_of_payment amount=amount,
) transaction_id=transaction_id,
mode_of_payment=mode_of_payment
)
frappe.db.commit()
except Exception:
frappe.log_error(
frappe.get_traceback(),
"WEBHOOK PAYMENT ENTRY FAILURE"
)
return "ok" return "ok"