qbcore-framework / qb-banking

Banking System For QB-Core
GNU General Public License v3.0
47 stars 195 forks source link

[BUG] Change card PIN not syncing to player inventory #105

Closed altefwan closed 1 year ago

altefwan commented 1 year ago

Describe the bug When changing card PIN, the new PIN won't be recognized on ATMs. The PIN stays at when you first created the card. Looking at the database and quick look at the code, it seems that the record updates the data on bank_cards but is not being cascaded to the inventory field in players. Thus, the PIN stays at when you first created the card. Additionally, the ATM login page does not show errors and notifications.

To Reproduce Steps to reproduce the behavior:

  1. Create a debit card
  2. Change the PIN
  3. Open ATM using new PIN
  4. You won't be able to login unless you use the PIN you used when you created the card (You won't see wrong PIN error message due to bug in ATM login page)
altefwan commented 1 year ago

Created a quick fix by updating the following event:

RegisterNetEvent('qb-banking:updatePin', function(currentBankCard, newPin)
    if newPin ~= nil then
        local src = source
        local xPlayer = QBCore.Functions.GetPlayer(src)
        if not xPlayer then return end
        MySQL.update('UPDATE bank_cards SET cardPin = ? WHERE record_id = ?', {
            newPin,
            currentBankCard.record_id
        }, function(result)
            if result == 1 then
                local invItems = xPlayer.PlayerData.items
                for _, v in pairs(invItems) do
                    if v.name == currentBankCard.cardType and currentBankCard.cardNumber == tostring(v.info.cardNumber) then 
                        v.info.cardPin = newPin
                    end
                end
                xPlayer.Functions.SetPlayerData("items", invItems)
                TriggerClientEvent('qb-banking:openBankScreen', src)
                TriggerClientEvent('qb-banking:successAlert', src, Lang:t('success.updated_pin'))
            else
                TriggerClientEvent('QBCore:Notify', src, 'Error updating pin', "error")
            end
        end)
    end
end)