Track restocking fee sweeps separately from refunds
- Customer refunds tracked in refund_* fields (amount, tx_hash, reason) - Restocking fees tracked in swept_* fields (amount, tx_hash, timestamp) - Provides complete audit trail: received = refund_amount + swept_amount - Shop owners can now see exactly how much was collected in restocking fees For expired payments with restocking fee: 1. First transaction: 91% refunded to customer 2. Second transaction: 9% swept to shop's cold wallet This gives full transparency into both sides of the refund process.
This commit is contained in:
parent
2d5c2543c9
commit
326c79fbda
1 changed files with 39 additions and 0 deletions
|
|
@ -616,6 +616,45 @@ def process_payment(
|
|||
logger.info(
|
||||
f"Refund executed for expired payment {crypto_payment.id}: TX {result['tx_hash']}"
|
||||
)
|
||||
# Track the customer refund
|
||||
crypto_payment.refund_amount = int(refund_details["refund_amount"] * coin_config["atomic_units"])
|
||||
crypto_payment.refund_tx_hash = result["tx_hash"]
|
||||
crypto_payment.refund_reason = refund_details["reason"]
|
||||
|
||||
# Now sweep the restocking fee to shop's wallet
|
||||
fee_amount = int(refund_details["fee_amount"] * coin_config["atomic_units"])
|
||||
if fee_amount > 0 and crypto_payment.shop_sweep_to_address:
|
||||
try:
|
||||
if crypto_payment.coin_type == "XMR":
|
||||
sweep_result = client._call("sweep_single", {
|
||||
"account_index": crypto_payment.account_index,
|
||||
"address": crypto_payment.shop_sweep_to_address,
|
||||
"amount": fee_amount,
|
||||
"priority": 1,
|
||||
"get_tx_hex": True,
|
||||
"do_not_relay": False,
|
||||
})
|
||||
fee_tx_hash = sweep_result.get("tx_hash_list", [None])[0]
|
||||
elif crypto_payment.coin_type == "DOGE":
|
||||
fee_tx_hash = client._call("sendtoaddress", [
|
||||
crypto_payment.shop_sweep_to_address,
|
||||
float(Decimal(fee_amount) / coin_config["atomic_units"])
|
||||
])
|
||||
else:
|
||||
fee_tx_hash = None
|
||||
|
||||
if fee_tx_hash:
|
||||
crypto_payment.swept_amount = fee_amount
|
||||
crypto_payment.swept_tx_hash = fee_tx_hash
|
||||
crypto_payment.swept_timestamp = now_timestamp()
|
||||
logger.info(
|
||||
f"Restocking fee swept for payment {crypto_payment.id}: "
|
||||
f"{Decimal(fee_amount) / coin_config['atomic_units']} {crypto_payment.coin_type} "
|
||||
f"TX: {fee_tx_hash}"
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to sweep restocking fee for payment {crypto_payment.id}: {e}")
|
||||
|
||||
crypto_payment.status = CryptoPayment.STATUS_EXPIRED_REFUNDED
|
||||
else:
|
||||
logger.error(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue