Removes redundant payment recording

Removes the explicit call to the record-payment API when settling a receivable.

The webhook (on_invoice_paid in tasks.py) automatically handles recording the payment in Fava, making the API call redundant. This simplifies the frontend logic.

Also, in the `showPayUserDialog` function, it now correctly identifies users who are owed payments based on a negative balance instead of a positive balance.
This commit is contained in:
padreug 2025-11-10 11:13:25 +01:00
parent 490b361268
commit 1d605be021

View file

@ -1184,38 +1184,21 @@ window.app = Vue.createApp({
clearInterval(this.settleReceivableDialog.pollIntervalId) clearInterval(this.settleReceivableDialog.pollIntervalId)
this.settleReceivableDialog.pollIntervalId = null this.settleReceivableDialog.pollIntervalId = null
// Record payment in accounting - this creates the journal entry // Payment detected! The webhook (on_invoice_paid in tasks.py) will automatically
// that settles the receivable // record this in Fava, so we don't need to call record-payment API here.
try { // Just notify the user and refresh the UI.
const recordResponse = await LNbits.api.request( this.$q.notify({
'POST', type: 'positive',
'/castle/api/v1/record-payment', message: 'Payment received! Receivable has been settled.',
this.g.user.wallets[0].adminkey, timeout: 3000
{ })
payment_hash: paymentHash
}
)
console.log('Settlement payment recorded:', recordResponse.data)
this.$q.notify({ // Close dialog and refresh
type: 'positive', this.settleReceivableDialog.show = false
message: 'Payment received! Receivable has been settled.', await this.loadBalance()
timeout: 3000 await this.loadTransactions()
}) await this.loadAllUserBalances()
// Close dialog and refresh
this.settleReceivableDialog.show = false
await this.loadBalance()
await this.loadTransactions()
await this.loadAllUserBalances()
} catch (error) {
console.error('Error recording settlement payment:', error)
this.$q.notify({
type: 'negative',
message: 'Payment detected but failed to record: ' + (error.response?.data?.detail || error.message),
timeout: 5000
})
}
return true return true
} }
return false return false
@ -1297,8 +1280,8 @@ window.app = Vue.createApp({
} }
}, },
showPayUserDialog(userBalance) { showPayUserDialog(userBalance) {
// Only show for users castle owes (positive balance) // Only show for users castle owes (negative balance = payable)
if (userBalance.balance <= 0) return if (userBalance.balance >= 0) return
// Extract fiat balances (e.g., EUR) // Extract fiat balances (e.g., EUR)
const fiatBalances = userBalance.fiat_balances || {} const fiatBalances = userBalance.fiat_balances || {}