1
0
Fork 0
forked from Simnation/Main

Update billing_server.lua

This commit is contained in:
Nordi98 2025-08-05 14:43:36 +02:00
parent 7b2d064f63
commit a3269e304b

View file

@ -75,9 +75,26 @@ lib.callback.register('billing:server:handleBillResponse', function(source, data
if data.action == 'pay' then
-- Process payment based on selected account
if data.accountId == 'personal' then
-- Pay from personal bank account
local success = lib.callback.await('ps-banking:server:payBill', src, data.billId)
return success
-- Pay from personal bank account using ps-banking's payBill function
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")
MySQL.query.await('DELETE FROM ps_banking_bills WHERE id = ?', {data.billId})
-- Process the payment to the recipient's account
ProcessBillPayment(data.billId)
return true
else
-- Pay from shared account
local success = PayBillFromSharedAccount(src, data.billId, data.accountId)
@ -119,7 +136,7 @@ function PayBillFromSharedAccount(source, billId, accountId)
if not billResult or #billResult == 0 then return false end
local bill = billResult[1]
local amount = bill.amount
local amount = tonumber(bill.amount)
-- Get account details
local accountResult = MySQL.query.await('SELECT * FROM ps_banking_accounts WHERE id = ?', {accountId})
@ -146,7 +163,7 @@ function PayBillFromSharedAccount(source, billId, accountId)
if not hasAccess then return false end
-- Check if account has enough balance
if tonumber(account.balance) < tonumber(amount) then return false end
if tonumber(account.balance) < amount then return false end
-- Process payment
MySQL.update.await('UPDATE ps_banking_accounts SET balance = balance - ? WHERE id = ?', {amount, accountId})
@ -161,10 +178,31 @@ end
-- Add a callback for paying bill from selected account
lib.callback.register('billing:server:payBillFromAccount', function(source, data)
local src = source
local player = QBCore.Functions.GetPlayer(src)
if not player then return false end
if data.accountId == 'personal' then
-- Pay from personal bank account
return lib.callback.await('ps-banking:server:payBill', src, data.billId)
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
player.Functions.RemoveMoney("bank", amount, "bill-payment")
MySQL.query.await('DELETE FROM ps_banking_bills WHERE id = ?', {data.billId})
-- Process the payment to the recipient's account
ProcessBillPayment(data.billId)
return true
else
-- Pay from shared account
return PayBillFromSharedAccount(src, data.billId, data.accountId)
@ -180,7 +218,7 @@ function ProcessBillPayment(billId)
local bill = billData[1]
local receiverId = bill.sender_id
local accountId = bill.account_id
local amount = bill.amount
local amount = tonumber(bill.amount)
-- If it's a personal account
if accountId == 'personal' then
@ -210,11 +248,6 @@ function ProcessBillPayment(billId)
end
end
-- Event handler for when a bill is paid
RegisterNetEvent('ps-banking:server:billPaid', function(billId)
ProcessBillPayment(billId)
end)
-- Create the necessary database tables if they don't exist
MySQL.ready(function()
MySQL.query.await([[