diff --git a/make_post_sell/views/crypto.py b/make_post_sell/views/crypto.py index bd83ae2..c1196e0 100644 --- a/make_post_sell/views/crypto.py +++ b/make_post_sell/views/crypto.py @@ -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