diff --git a/make_post_sell/lib/crypto_watcher.py b/make_post_sell/lib/crypto_watcher.py index 16eb367..9863ea1 100644 --- a/make_post_sell/lib/crypto_watcher.py +++ b/make_post_sell/lib/crypto_watcher.py @@ -884,6 +884,10 @@ def process_payment( logger.info( f"Expired payment {crypto_payment.id} eligible for refund: {refund_details}" ) + + # Set status to expired-refunded immediately when refund is determined + crypto_payment.status = CryptoPayment.STATUS_EXPIRED_REFUNDED + result = payment_rescue.execute_refund( refund_details, crypto_payment ) @@ -898,9 +902,7 @@ def process_payment( ) crypto_payment.refund_tx_hash = result["tx_hash"] crypto_payment.refund_reason = refund_details["reason"] - crypto_payment.status = ( - CryptoPayment.STATUS_EXPIRED_REFUNDED - ) + # Status already set above # Commit the refund first env_request.dbsession.add(crypto_payment) @@ -1147,6 +1149,10 @@ def process_payment( logger.info( f"Underpayment {crypto_payment.id} eligible for refund: {refund_details}" ) + + # Set status to underpaid-refunded immediately when refund is determined + crypto_payment.status = CryptoPayment.STATUS_UNDERPAID_REFUNDED + result = payment_rescue.execute_refund( refund_details, crypto_payment ) @@ -1154,11 +1160,12 @@ def process_payment( logger.info( f"Refund executed for underpayment {crypto_payment.id}: TX {result['tx_hash']}" ) - crypto_payment.status = CryptoPayment.STATUS_UNDERPAID_REFUNDED + # Status already set above else: logger.error( f"Refund failed for underpayment {crypto_payment.id}: {result['error']}" ) + # Status remains underpaid-refunded, refund will be retried later else: # No refund possible - no refund address configured logger.warning( diff --git a/make_post_sell/templates/crypto_quotes_history.j2 b/make_post_sell/templates/crypto_quotes_history.j2 index 2445c16..547ed2d 100644 --- a/make_post_sell/templates/crypto_quotes_history.j2 +++ b/make_post_sell/templates/crypto_quotes_history.j2 @@ -46,6 +46,8 @@ {% else %} {{ '%.8f' % payment.received_crypto }} {{ payment.coin_type }} {% endif %} +
+ ${{ '%.2f' % (payment.received_crypto * (payment.rate_usd_per_coin|float)) }} USD {% if payment.confirmations > 0 %}
{{ payment.confirmations }}/{{ payment.confirmations_required }} confirmations @@ -88,11 +90,20 @@ {% elif payment.status.endswith('-refunded') %}
- 💸 This payment was automatically refunded. - {% if payment.status == 'out-of-stock-refunded' %} - The item became unavailable after your payment - full refund issued. + {% if payment.refund_tx_hash %} + 💸 This payment was automatically refunded. + {% if payment.status == 'out-of-stock-refunded' %} + The item became unavailable after your payment - full refund issued. + {% else %} + A 9% restocking fee was deducted to cover network costs. + {% endif %} {% else %} - A 9% restocking fee was deducted to cover network costs. + ⏳ Refund pending - waiting for your payment to reach 10 confirmations before processing the refund. + {% if payment.status == 'out-of-stock-refunded' %} + The item became unavailable after your payment - full refund will be issued. + {% else %} + A 9% restocking fee will be deducted to cover network costs. + {% endif %} {% endif %}
diff --git a/make_post_sell/views/crypto.py b/make_post_sell/views/crypto.py index 93422ba..458e6d3 100644 --- a/make_post_sell/views/crypto.py +++ b/make_post_sell/views/crypto.py @@ -799,7 +799,7 @@ def crypto_cancel(request): # Clear the invoice reference BEFORE deleting the invoice (now that invoice_id is nullable) crypto_payment.invoice_id = None crypto_payment.invoice = None - + delete_result = delete_invoice_by_id(request.dbsession, invoice.id) # We don't fail the cancellation if invoice deletion fails # The payment cancellation is more important than invoice cleanup @@ -879,6 +879,7 @@ def crypto_quotes_history(request): "invoice_id": payment.invoice.id if payment.invoice else None, "shop_name": payment.shop.name if payment.shop else "Unknown Shop", "refund_reason": payment.refund_reason, + "refund_tx_hash": payment.refund_tx_hash, } payment_history.append(payment_data) @@ -955,6 +956,10 @@ def get_payment_status_info(status): "expired": {"label": "Expired", "color": "#6c757d"}, "expired-refunded": {"label": "Expired - Refunded", "color": "#fd7e14"}, "underpaid-refunded": {"label": "Underpaid - Refunded", "color": "#fd7e14"}, + "confirmed-overpaid-refunded": { + "label": "Overpaid - Refunded", + "color": "#fd7e14", + }, "cancelled": {"label": "Cancelled", "color": "#6c757d"}, "out-of-stock-refunded": { "label": "Out of Stock - Refunded",