fix: admin refund actually sends funds (was calling a nonexistent method)

The admin "send funds" refund path called walletRPCService.sendPayment(),
which does not exist — guarded by a typeof check, so it silently never sent
while still reporting the refund as processed.

Now uses the real processPayout() (validates the address and transfers,
returning { success, txHash }), and refunds the amount the user actually paid
(received_amount, recorded at confirmation) rather than the expected amount,
falling back to expected for older records.
This commit is contained in:
jwinterm
2026-05-31 10:02:19 -04:00
parent ce83ec4b6c
commit 2e6f1a6335
2 changed files with 19 additions and 11 deletions
+18 -10
View File
@@ -811,19 +811,27 @@ app.post('/api/admin/refund/payment', adminAuth, asyncHandler(async (req, res) =
await client.query('COMMIT');
// Optionally send funds back via wallet RPC
// Optionally send funds back via wallet RPC. Refund what the user ACTUALLY paid
// (received_amount, recorded at confirmation) when available, falling back to the
// expected amount for older records.
let fundsSent = false;
let txHash = null;
if (sendFunds && payment.payout_address && payment.expected_amount > 0) {
const refundAmount = (payment.received_amount != null && Number(payment.received_amount) > 0)
? payment.received_amount
: payment.expected_amount;
if (sendFunds && payment.payout_address && Number(refundAmount) > 0) {
try {
if (walletRPCService && typeof walletRPCService.sendPayment === 'function') {
const result = await walletRPCService.sendPayment(
payment.payout_address,
payment.expected_amount
);
fundsSent = true;
txHash = result?.tx_hash || null;
}
// processPayout validates the address and performs the transfer; returns
// { success, txHash, fee }. (The previous code called a nonexistent sendPayment(),
// so refunds were silently never sent while still reporting success.)
const result = await walletRPCService.processPayout({
address: payment.payout_address,
amount: refundAmount,
userId: payment.user_id,
description: `Refund for payment ${paymentId}`
});
fundsSent = !!(result && result.success);
txHash = (result && result.txHash) || null;
} catch (err) {
console.error('Failed to send refund funds:', err.message);
// Don't fail the request - refund is recorded, funds can be sent manually