|
|
@ -180,6 +180,20 @@ def find_set_pending_splynx_invoices(splynx_id: int) -> List[Dict[str, Any]]: |
|
|
updated_invoices.append(res) |
|
|
updated_invoices.append(res) |
|
|
return updated_invoices |
|
|
return updated_invoices |
|
|
|
|
|
|
|
|
|
|
|
def find_set_pending_splynx_invoices_to_unpaid(splynx_id: int) -> List[Dict[str, Any]]: |
|
|
|
|
|
result = splynx.get(url=f"/api/2.0/admin/finance/invoices?main_attributes[customer_id]={splynx_id}&main_attributes[status]=pending") |
|
|
|
|
|
|
|
|
|
|
|
invoice_pay = { |
|
|
|
|
|
"status": "not_paid" |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
updated_invoices = [] |
|
|
|
|
|
for pay in result: |
|
|
|
|
|
res = splynx.put(url=f"/api/2.0/admin/finance/invoices/{pay['id']}", params=invoice_pay) |
|
|
|
|
|
if res: |
|
|
|
|
|
updated_invoices.append(res) |
|
|
|
|
|
return updated_invoices |
|
|
|
|
|
|
|
|
def delete_splynx_invoices(splynx_id: int, payintent: str) -> Dict[str, Any]: |
|
|
def delete_splynx_invoices(splynx_id: int, payintent: str) -> Dict[str, Any]: |
|
|
"""Delete Splynx payment records for a given customer and payment intent.""" |
|
|
"""Delete Splynx payment records for a given customer and payment intent.""" |
|
|
try: |
|
|
try: |
|
|
@ -884,6 +898,14 @@ def handle_failed_payment_notification(payment_record, error_details: str, payme |
|
|
'payment_intent': payment_record.Payment_Intent |
|
|
'payment_intent': payment_record.Payment_Intent |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# Revert pending invoices back to "not_paid" (only in live mode) |
|
|
|
|
|
if PROCESS_LIVE: |
|
|
|
|
|
updated_invoices = find_set_pending_splynx_invoices_to_unpaid(splynx_id=payment_record.Splynx_ID) |
|
|
|
|
|
if updated_invoices: |
|
|
|
|
|
logger.info(f"✅ Payment failure pending invoices reverted back to not_paid Splynx ID: {payment_record.Splynx_ID} - PayID: {payment_record.id}") |
|
|
|
|
|
else: |
|
|
|
|
|
logger.error(f"❌ Failed to send payment failure email for payment {payment_record.id}") |
|
|
|
|
|
|
|
|
# Send email notification (only in live mode) |
|
|
# Send email notification (only in live mode) |
|
|
if PROCESS_LIVE: |
|
|
if PROCESS_LIVE: |
|
|
email_sent = notification_service.send_payment_failure_notification(payment_data) |
|
|
email_sent = notification_service.send_payment_failure_notification(payment_data) |
|
|
|