mirror of
https://github.com/jimathy/jim-payments.git
synced 2026-08-17 06:16:02 +01:00
v2.1 - Add confirmation popups for payments
This commit is contained in:
44
client.lua
44
client.lua
@@ -3,33 +3,13 @@ local QBCore = exports['qb-core']:GetCoreObject()
|
||||
PlayerJob = {}
|
||||
local onDuty = false
|
||||
|
||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded')
|
||||
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
|
||||
QBCore.Functions.GetPlayerData(function(PlayerData)
|
||||
PlayerJob = PlayerData.job
|
||||
PlayerGang = PlayerData.gang
|
||||
end)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Client:OnJobUpdate')
|
||||
AddEventHandler('QBCore:Client:OnJobUpdate', function(JobInfo)
|
||||
PlayerJob = JobInfo
|
||||
onDuty = PlayerJob.onduty
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Client:SetDuty')
|
||||
AddEventHandler('QBCore:Client:SetDuty', function(duty)
|
||||
onDuty = duty
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Client:OnGangUpdate')
|
||||
AddEventHandler('QBCore:Client:OnGangUpdate', function(GangInfo)
|
||||
PlayerGang = GangInfo
|
||||
end)
|
||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded') AddEventHandler('QBCore:Client:OnPlayerLoaded', function() QBCore.Functions.GetPlayerData(function(PlayerData) PlayerJob = PlayerData.job PlayerGang = PlayerData.gang end) end)
|
||||
RegisterNetEvent('QBCore:Client:OnJobUpdate') AddEventHandler('QBCore:Client:OnJobUpdate', function(JobInfo) PlayerJob = JobInfo onDuty = PlayerJob.onduty end)
|
||||
RegisterNetEvent('QBCore:Client:SetDuty') AddEventHandler('QBCore:Client:SetDuty', function(duty) onDuty = duty end)
|
||||
RegisterNetEvent('QBCore:Client:OnGangUpdate') AddEventHandler('QBCore:Client:OnGangUpdate', function(GangInfo) PlayerGang = GangInfo end)
|
||||
|
||||
--Keeps track of duty on script restarts
|
||||
AddEventHandler('onResourceStart', function(resource)
|
||||
if GetCurrentResourceName() == resource then QBCore.Functions.GetPlayerData(function(PlayerData) PlayerJob = PlayerData.job PlayerGang = PlayerData.gang onDuty = PlayerJob.onduty end) end end)
|
||||
AddEventHandler('onResourceStart', function(resource) if GetCurrentResourceName() == resource then QBCore.Functions.GetPlayerData(function(PlayerData) PlayerJob = PlayerData.job PlayerGang = PlayerData.gang onDuty = PlayerJob.onduty end) end end)
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
local jobroles = {}
|
||||
@@ -76,11 +56,19 @@ RegisterNetEvent('jim-payments:Tickets:Menu', function()
|
||||
else exports['qb-menu']:openMenu({
|
||||
{ isMenuHeader = true, header = "🧾 "..PlayerJob.label.." Receipts 🧾", txt = "Do you want trade your receipts for payment?" },
|
||||
{ isMenuHeader = true, header = "", txt = "Amount of Tickets: "..amount.."<br>Total Payment: $"..(Config.Jobs[PlayerJob.name].PayPerTicket * amount) },
|
||||
{ header = "Yes", txt = "", params = { event = "jim-payments:Tickets:Sell:yes" } },
|
||||
{ header = "No", txt = "", params = { event = "jim-payments:Tickets:Sell:no" } }, })
|
||||
{ header = "✅ Yes", txt = "", params = { event = "jim-payments:Tickets:Sell:yes" } },
|
||||
{ header = "❌ No", txt = "", params = { event = "jim-payments:Tickets:Sell:no" } }, })
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent("jim-payments:client:PayPopup", function(amount, biller, billtype)
|
||||
exports['qb-menu']:openMenu({
|
||||
{ isMenuHeader = true, header = "🧾 "..PlayerJob.label.." Payment 🧾", txt = "Do you want accept the payment?" },
|
||||
{ isMenuHeader = true, header = "", txt = billtype:gsub("^%l", string.upper).." Payment: $"..amount },
|
||||
{ header = "✅ Yes", txt = "", params = { isServer = true, event = "jim-payments:server:PayPopup", args = { accept = true, amount = amount, biller = biller, billtype = billtype } } },
|
||||
{ header = "❌ No", txt = "", params = { isServer = true, event = "jim-payments:server:PayPopup", args = { accept = false, amount = amount, biller = biller, billtype = billtype } } }, })
|
||||
end)
|
||||
|
||||
RegisterNetEvent('jim-payments:Tickets:Sell:yes', function() TriggerServerEvent('jim-payments:Tickets:Sell') end)
|
||||
RegisterNetEvent('jim-payments:Tickets:Sell:no', function() exports['qb-menu']:closeMenu() end)
|
||||
RegisterNetEvent('jim-payments:Tickets:Sell:no', function() exports['qb-menu']:closeMenu() end)
|
||||
12
config.lua
12
config.lua
@@ -1,4 +1,4 @@
|
||||
print("Jim-Payments v2 - Payments Script by Jimathy")
|
||||
print("Jim-Payments v2.1 - Payments Script by Jimathy")
|
||||
|
||||
-- If you need support I now have a discord available, it helps me keep track of issues and give better support.
|
||||
|
||||
@@ -15,15 +15,19 @@ Config.useBanks = true -- Enable this to use my banking stuff
|
||||
Config.BankBlips = true -- Enable this if you disabled qb-banking and need bank locations
|
||||
Config.ATMBlips = false -- Enable this if you are a pyscho and need every ATM to be on the map too
|
||||
|
||||
Config.PhoneBank = true -- Set this to false to use the popup payment system FOR CARD/BANK PAYMENTS instead of using phone invoices
|
||||
-- This doesn't affect Cash payments as they by default use confirmation now
|
||||
-- This is helpful for phones that don't support invoices well
|
||||
|
||||
-- MinAmountforTicket should be your cheapest item
|
||||
-- PayPerTicket should never be higher than MinAmountforTicket
|
||||
Config.Jobs = {
|
||||
['popsdiner'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
||||
['beanmachine'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
||||
['henhouse'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
||||
['pizzathis'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
||||
['burgershot'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
||||
['catcafe'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
||||
['henhouse'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
||||
['pizzathis'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
||||
['popsdiner'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
||||
['tequilala'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
||||
['vanilla'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
||||
['mechanic'] = { MinAmountforTicket = 1000, PayPerTicket = 500 },
|
||||
|
||||
39
server.lua
39
server.lua
@@ -52,31 +52,46 @@ QBCore.Functions.CreateCallback('jim-payments:Ticket:Count', function(source, cb
|
||||
end)
|
||||
|
||||
RegisterServerEvent("jim-payments:server:Charge", function(citizen, price, billtype)
|
||||
local biller = QBCore.Functions.GetPlayer(source)
|
||||
local src = source
|
||||
local biller = QBCore.Functions.GetPlayer(src)
|
||||
local billed = QBCore.Functions.GetPlayer(tonumber(citizen))
|
||||
local amount = tonumber(price)
|
||||
|
||||
if amount and amount > 0 then
|
||||
if billtype == "cash" then balance = billed.Functions.GetMoney(billtype)
|
||||
if balance >= amount then
|
||||
billed.Functions.RemoveMoney('cash', amount) TriggerEvent("qb-bossmenu:server:addAccountMoney", tostring(biller.PlayerData.job.name), amount)
|
||||
TriggerEvent('jim-payments:Tickets:Give', amount, tostring(biller.PlayerData.job.name))
|
||||
TriggerClientEvent("jim-payments:client:PayPopup", billed.PlayerData.source, amount, src, billtype)
|
||||
elseif balance < amount then
|
||||
TriggerClientEvent("QBCore:Notify", source, "Customer doesn't have enough cash to pay", "error")
|
||||
TriggerClientEvent("QBCore:Notify", src, "Customer doesn't have enough cash to pay", "error")
|
||||
TriggerClientEvent("QBCore:Notify", tonumber(citizen), "You don't have enough cash to pay", "error")
|
||||
end
|
||||
elseif billtype == "card" then
|
||||
MySQL.Async.insert(
|
||||
'INSERT INTO phone_invoices (citizenid, amount, society, sender, sendercitizenid) VALUES (?, ?, ?, ?, ?)',
|
||||
{billed.PlayerData.citizenid, amount, biller.PlayerData.job.name,
|
||||
biller.PlayerData.charinfo.firstname, biller.PlayerData.citizenid})
|
||||
TriggerClientEvent('qb-phone:RefreshPhone', billed.PlayerData.source)
|
||||
TriggerClientEvent('QBCore:Notify', source, 'Invoice Successfully Sent', 'success')
|
||||
TriggerClientEvent('QBCore:Notify', billed.PlayerData.source, 'New Invoice Received')
|
||||
if Config.PhoneBank == false then
|
||||
TriggerClientEvent("jim-payments:client:PayPopup", billed.PlayerData.source, amount, src, billtype)
|
||||
else
|
||||
MySQL.Async.insert(
|
||||
'INSERT INTO phone_invoices (citizenid, amount, society, sender, sendercitizenid) VALUES (?, ?, ?, ?, ?)',
|
||||
{billed.PlayerData.citizenid, amount, biller.PlayerData.job.name, biller.PlayerData.charinfo.firstname, biller.PlayerData.citizenid})
|
||||
TriggerClientEvent('qb-phone:RefreshPhone', billed.PlayerData.source)
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Invoice Successfully Sent', 'success')
|
||||
TriggerClientEvent('QBCore:Notify', billed.PlayerData.source, 'New Invoice Received')
|
||||
end
|
||||
end
|
||||
else TriggerClientEvent('QBCore:Notify', source, "You can't charge $0", 'error') return end
|
||||
end)
|
||||
|
||||
RegisterServerEvent("jim-payments:server:PayPopup", function(data)
|
||||
local src = source
|
||||
local billed = QBCore.Functions.GetPlayer(src)
|
||||
local biller = QBCore.Functions.GetPlayer(tonumber(data.biller))
|
||||
if data.accept == true then
|
||||
billed.Functions.RemoveMoney(tostring(data.billtype), data.amount) TriggerEvent("qb-bossmenu:server:addAccountMoney", tostring(biller.PlayerData.job.name), data.amount)
|
||||
TriggerEvent('jim-payments:Tickets:Give', data.amount, tostring(billed.PlayerData.job.name))
|
||||
elseif data.accept == false then
|
||||
TriggerClientEvent("QBCore:Notify", src, "You declined the payment")
|
||||
TriggerClientEvent("QBCore:Notify", data.biller, billed.PlayerData.charinfo.firstname.." declined the payment", "error")
|
||||
end
|
||||
end)
|
||||
|
||||
QBCore.Functions.CreateCallback('jim-payments:MakePlayerList', function(source, cb)
|
||||
local onlineList = {}
|
||||
for k, v in pairs(QBCore.Functions.GetPlayers()) do
|
||||
|
||||
Reference in New Issue
Block a user