mirror of
https://github.com/jimathy/jim-payments.git
synced 2026-08-18 23:06: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 = {}
|
PlayerJob = {}
|
||||||
local onDuty = false
|
local onDuty = false
|
||||||
|
|
||||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded')
|
RegisterNetEvent('QBCore:Client:OnPlayerLoaded') AddEventHandler('QBCore:Client:OnPlayerLoaded', function() QBCore.Functions.GetPlayerData(function(PlayerData) PlayerJob = PlayerData.job PlayerGang = PlayerData.gang end) end)
|
||||||
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
|
RegisterNetEvent('QBCore:Client:OnJobUpdate') AddEventHandler('QBCore:Client:OnJobUpdate', function(JobInfo) PlayerJob = JobInfo onDuty = PlayerJob.onduty end)
|
||||||
QBCore.Functions.GetPlayerData(function(PlayerData)
|
RegisterNetEvent('QBCore:Client:SetDuty') AddEventHandler('QBCore:Client:SetDuty', function(duty) onDuty = duty end)
|
||||||
PlayerJob = PlayerData.job
|
RegisterNetEvent('QBCore:Client:OnGangUpdate') AddEventHandler('QBCore:Client:OnGangUpdate', function(GangInfo) PlayerGang = GangInfo end)
|
||||||
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
|
--Keeps track of duty on script restarts
|
||||||
AddEventHandler('onResourceStart', function(resource)
|
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)
|
||||||
if GetCurrentResourceName() == resource then QBCore.Functions.GetPlayerData(function(PlayerData) PlayerJob = PlayerData.job PlayerGang = PlayerData.gang onDuty = PlayerJob.onduty end) end end)
|
|
||||||
|
|
||||||
Citizen.CreateThread(function()
|
Citizen.CreateThread(function()
|
||||||
local jobroles = {}
|
local jobroles = {}
|
||||||
@@ -76,11 +56,19 @@ RegisterNetEvent('jim-payments:Tickets:Menu', function()
|
|||||||
else exports['qb-menu']:openMenu({
|
else exports['qb-menu']:openMenu({
|
||||||
{ isMenuHeader = true, header = "🧾 "..PlayerJob.label.." Receipts 🧾", txt = "Do you want trade your receipts for payment?" },
|
{ 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) },
|
{ 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 = "✅ Yes", txt = "", params = { event = "jim-payments:Tickets:Sell:yes" } },
|
||||||
{ header = "No", txt = "", params = { event = "jim-payments:Tickets:Sell:no" } }, })
|
{ header = "❌ No", txt = "", params = { event = "jim-payments:Tickets:Sell:no" } }, })
|
||||||
end
|
end
|
||||||
end
|
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: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.
|
-- 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.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.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
|
-- MinAmountforTicket should be your cheapest item
|
||||||
-- PayPerTicket should never be higher than MinAmountforTicket
|
-- PayPerTicket should never be higher than MinAmountforTicket
|
||||||
Config.Jobs = {
|
Config.Jobs = {
|
||||||
['popsdiner'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
|
||||||
['beanmachine'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
['beanmachine'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
||||||
['henhouse'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
|
||||||
['pizzathis'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
|
||||||
['burgershot'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
['burgershot'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
||||||
['catcafe'] = { 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 },
|
['tequilala'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
||||||
['vanilla'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
['vanilla'] = { MinAmountforTicket = 50, PayPerTicket = 50 },
|
||||||
['mechanic'] = { MinAmountforTicket = 1000, PayPerTicket = 500 },
|
['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)
|
end)
|
||||||
|
|
||||||
RegisterServerEvent("jim-payments:server:Charge", function(citizen, price, billtype)
|
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 billed = QBCore.Functions.GetPlayer(tonumber(citizen))
|
||||||
local amount = tonumber(price)
|
local amount = tonumber(price)
|
||||||
|
|
||||||
if amount and amount > 0 then
|
if amount and amount > 0 then
|
||||||
if billtype == "cash" then balance = billed.Functions.GetMoney(billtype)
|
if billtype == "cash" then balance = billed.Functions.GetMoney(billtype)
|
||||||
if balance >= amount then
|
if balance >= amount then
|
||||||
billed.Functions.RemoveMoney('cash', amount) TriggerEvent("qb-bossmenu:server:addAccountMoney", tostring(biller.PlayerData.job.name), amount)
|
TriggerClientEvent("jim-payments:client:PayPopup", billed.PlayerData.source, amount, src, billtype)
|
||||||
TriggerEvent('jim-payments:Tickets:Give', amount, tostring(biller.PlayerData.job.name))
|
|
||||||
elseif balance < amount then
|
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")
|
TriggerClientEvent("QBCore:Notify", tonumber(citizen), "You don't have enough cash to pay", "error")
|
||||||
end
|
end
|
||||||
elseif billtype == "card" then
|
elseif billtype == "card" then
|
||||||
MySQL.Async.insert(
|
if Config.PhoneBank == false then
|
||||||
'INSERT INTO phone_invoices (citizenid, amount, society, sender, sendercitizenid) VALUES (?, ?, ?, ?, ?)',
|
TriggerClientEvent("jim-payments:client:PayPopup", billed.PlayerData.source, amount, src, billtype)
|
||||||
{billed.PlayerData.citizenid, amount, biller.PlayerData.job.name,
|
else
|
||||||
biller.PlayerData.charinfo.firstname, biller.PlayerData.citizenid})
|
MySQL.Async.insert(
|
||||||
TriggerClientEvent('qb-phone:RefreshPhone', billed.PlayerData.source)
|
'INSERT INTO phone_invoices (citizenid, amount, society, sender, sendercitizenid) VALUES (?, ?, ?, ?, ?)',
|
||||||
TriggerClientEvent('QBCore:Notify', source, 'Invoice Successfully Sent', 'success')
|
{billed.PlayerData.citizenid, amount, biller.PlayerData.job.name, biller.PlayerData.charinfo.firstname, biller.PlayerData.citizenid})
|
||||||
TriggerClientEvent('QBCore:Notify', billed.PlayerData.source, 'New Invoice Received')
|
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
|
end
|
||||||
else TriggerClientEvent('QBCore:Notify', source, "You can't charge $0", 'error') return end
|
else TriggerClientEvent('QBCore:Notify', source, "You can't charge $0", 'error') return end
|
||||||
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)
|
QBCore.Functions.CreateCallback('jim-payments:MakePlayerList', function(source, cb)
|
||||||
local onlineList = {}
|
local onlineList = {}
|
||||||
for k, v in pairs(QBCore.Functions.GetPlayers()) do
|
for k, v in pairs(QBCore.Functions.GetPlayers()) do
|
||||||
|
|||||||
Reference in New Issue
Block a user