diff --git a/ticketmachine.lua b/ticketmachine.lua index 6a48f61..80e5dd3 100644 --- a/ticketmachine.lua +++ b/ticketmachine.lua @@ -1,6 +1,6 @@ local CURRENT_STATION_CODE = 'Ticket-Machine' local API_BASE = 'https://ticket.fse-media.group/api' -local VERSION = 'v1.5.25' +local VERSION = 'v1.5.29' local UPDATE_CHECK_INTERVAL = 5 -- ########################### @@ -1181,7 +1181,7 @@ state = { departure = nil, terminal = nil, trainType = nil, trips = 1, cost = 0, paid = 0, doneAudioPlayed = false, productMode = 'ticket', cardMode = nil, cardPaymentMode = 'local', holderName = '', cardDeposit = 0, cardTopup = 0, cardBalance = 0, cardOrderValue = 0, - card_id = nil, card_server_data = nil, pendingBlankCardId = nil + card_id = nil, card_server_data = nil, pendingBlankCardId = nil, cardIssueWarning = nil } local function getCardConfig() @@ -1216,6 +1216,7 @@ local function resetTicketFlow() state.card_id = nil state.card_server_data = nil state.pendingBlankCardId = nil + state.cardIssueWarning = nil end local function resetCardFlow(mode) @@ -1235,6 +1236,7 @@ local function resetCardFlow(mode) state.card_id = nil state.card_server_data = nil state.pendingBlankCardId = nil + state.cardIssueWarning = nil end local function isCardOrderLike(data) @@ -2256,6 +2258,7 @@ local function showOrderAndAudio() end if okIssueBlank and #blankCardId > 0 then payload.card_id = blankCardId + state.card_id = blankCardId state.pendingBlankCardId = blankCardId local okReq, code, parsed, err = submitCardOpen(payload) if okReq then @@ -2267,11 +2270,15 @@ local function showOrderAndAudio() state.cardBalance = tonumber(writtenCard.balance) or finalCard.balance state.card_server_data = respData state.pendingBlankCardId = nil + state.cardIssueWarning = nil confirmed = true statusMsg, statusCol = 'Card ready', colors.green if not state.doneAudioPlayed then playConfirmTicketMelody(); state.doneAudioPlayed = true end else - statusMsg, statusCol = 'Write failed: ' .. tostring(writeMethod), colors.red + state.card_server_data = respData + state.cardIssueWarning = 'Write pending: ' .. tostring(writeMethod) + confirmed = true + statusMsg, statusCol = 'Card issued, write pending', colors.red end else local errorMsg = 'Card API Err' @@ -2282,9 +2289,14 @@ local function showOrderAndAudio() elseif code and type(code) == 'number' then errorMsg = 'HTTP ' .. tostring(code) end - statusMsg, statusCol = 'Issued, retry sync: ' .. errorMsg, colors.red + state.cardIssueWarning = 'Sync pending: ' .. errorMsg + confirmed = true + statusMsg, statusCol = 'Card issued, sync pending', colors.red end elseif okIssueBlank then + state.card_id = payload.card_id + state.cardIssueWarning = 'Issued without readable ID' + confirmed = true statusMsg, statusCol = 'Card issued without ID', colors.red else local okReq, code, parsed, err = submitCardOpen(payload) @@ -2297,6 +2309,7 @@ local function showOrderAndAudio() state.cardBalance = tonumber(writtenCard.balance) or finalCard.balance state.card_server_data = respData state.pendingBlankCardId = nil + state.cardIssueWarning = nil confirmed = true statusMsg, statusCol = 'Card ready', colors.green if not state.doneAudioPlayed then playConfirmTicketMelody(); state.doneAudioPlayed = true end @@ -2429,7 +2442,8 @@ end local function showDone() if state.productMode == 'card' then - drawHeader('Card Ready', 'Please take your IC card') + local warning = firstString(state.cardIssueWarning) + drawHeader(warning ~= '' and 'Card Issued' or 'Card Ready', warning ~= '' and 'Please check issue status' or 'Please take your IC card') local y = 5 local function line(label, value, col) termDev.setTextColor(colors.white) @@ -2444,6 +2458,7 @@ local function showDone() line('Balance', tonumber(state.cardBalance) or 0, colors.green) line('Card ID', firstString(state.card_id, 'PENDING'), colors.cyan) if state.voucher_code then line('Voucher', state.voucher_code, colors.cyan) end + if warning ~= '' then line('Status', warning, colors.red) end saveCardIssueSnapshot({ card_id = state.card_id, holder_name = state.holderName, @@ -2451,6 +2466,7 @@ local function showDone() topup = state.cardTopup, balance = state.cardBalance, voucher_code = state.voucher_code, + issue_warning = warning, station_code = state.stationCode or CURRENT_STATION_CODE, ts = (os.epoch and os.epoch('utc')) or (os.time() * 1000) })