From d72b640e122a71aa57812a10d7d174ce54d0374d Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Tue, 5 Aug 2025 15:35:51 +0200 Subject: [PATCH] Update billing_server.lua --- .../[tools]/nordi_billing/billing_server.lua | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/resources/[tools]/nordi_billing/billing_server.lua b/resources/[tools]/nordi_billing/billing_server.lua index 49b8a2fc9..37f533395 100644 --- a/resources/[tools]/nordi_billing/billing_server.lua +++ b/resources/[tools]/nordi_billing/billing_server.lua @@ -439,3 +439,78 @@ RegisterServerEvent('billing:server:notifyBillDeclined', function(senderId, amou TriggerClientEvent('QBCore:Notify', sender.PlayerData.source, receiverName .. ' hat deine Rechnung über $' .. amount .. ' abgelehnt', 'error') end end) + +-- Add a new callback for handling bill responses +lib.callback.register('billing:server:handleBillResponse', function(source, data) + local src = source + local player = QBCore.Functions.GetPlayer(src) + + if not player then return false end + + if data.action == 'pay' then + -- Process payment based on selected account + if data.accountId == 'personal' then + -- Pay from personal bank account + local billResult = MySQL.query.await('SELECT * FROM ps_banking_bills WHERE id = ?', {data.billId}) + if not billResult or #billResult == 0 then return false end + + local bill = billResult[1] + local amount = tonumber(bill.amount) + + -- Check if player has enough money in their bank account + if player.PlayerData.money["bank"] < amount then + return false + end + + -- Process payment manually instead of using callback to avoid issues + player.Functions.RemoveMoney("bank", amount, "bill-payment") + + -- IMPORTANT: Delete the bill from ps_banking_bills table + MySQL.query.await('DELETE FROM ps_banking_bills WHERE id = ?', {data.billId}) + + -- Process the payment to the recipient's account + ProcessBillPayment(data.billId) + + -- Notify the player + TriggerClientEvent('QBCore:Notify', src, 'Du hast die Rechnung über $' .. amount .. ' bezahlt', 'success') + + return true + else + -- Pay from shared account + local success = PayBillFromSharedAccount(src, data.billId, data.accountId) + return success + end + elseif data.action == 'decline' then + -- Mark as declined in our system + MySQL.update.await('UPDATE billing_accounts SET declined = 1 WHERE bill_id = ?', {data.billId}) + + -- IMPORTANT: Delete the bill from ps_banking_bills table when declined + MySQL.query.await('DELETE FROM ps_banking_bills WHERE id = ?', {data.billId}) + + -- Find the sender to notify them + local billInfo = MySQL.query.await('SELECT * FROM billing_accounts WHERE bill_id = ?', {data.billId}) + if billInfo and #billInfo > 0 then + local senderId = billInfo[1].sender_id + local sender = QBCore.Functions.GetPlayerByCitizenId(senderId) + + if sender then + TriggerClientEvent('QBCore:Notify', sender.PlayerData.source, 'Deine Rechnung wurde abgelehnt', 'error') + end + end + + -- Notify the player + TriggerClientEvent('QBCore:Notify', src, 'Du hast die Rechnung abgelehnt', 'info') + + return true + elseif data.action == 'later' then + -- Simply close the prompt without any action + -- The bill will remain in the system as unpaid + + -- Notify the player + TriggerClientEvent('QBCore:Notify', src, 'Die Rechnung wurde für später gespeichert', 'info') + + return true + end + + return false +end)