Delete invoice when crypto payment is cancelled
When a crypto payment is cancelled, delete the associated invoice and line items since no actual purchase occurred. Keep the crypto_payment record for transaction history and audit trails. This prevents cancelled quotes from cluttering user purchase history.
This commit is contained in:
parent
2c7dd8e6ca
commit
b352430b63
1 changed files with 16 additions and 0 deletions
|
|
@ -742,6 +742,22 @@ def crypto_cancel(request):
|
|||
# Cancel the payment
|
||||
crypto_payment.status = CryptoPayment.STATUS_CANCELLED
|
||||
request.dbsession.add(crypto_payment)
|
||||
|
||||
# Delete the invoice since this was never a real purchase
|
||||
# Keep the crypto_payment for transaction history
|
||||
invoice = crypto_payment.invoice
|
||||
if invoice:
|
||||
# Delete invoice line items first
|
||||
for line_item in invoice.line_items:
|
||||
request.dbsession.delete(line_item)
|
||||
|
||||
# Clear the invoice reference from crypto payment
|
||||
crypto_payment.invoice_id = None
|
||||
crypto_payment.invoice = None
|
||||
|
||||
# Delete the invoice
|
||||
request.dbsession.delete(invoice)
|
||||
|
||||
request.dbsession.flush()
|
||||
|
||||
# Get the cart URL for redirect
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue