mirror of
https://github.com/Such-Software/wownerogue.git
synced 2026-10-21 08:08:32 +02:00
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:
+18
-10
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user