Help With JSON formatting

Post your Gambas programming questions here.
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Help With JSON formatting

Post by AndyGable »

basically the app is a go between my EPoS Software and a Card Processing machine

Once a sale starts it output status in the same message

how would I pole the url? do I just have to call the same Function or can it be made to do that?

Code: Select all

Private Sub ShowSaleResults(RequestID As String, http As HttpClient)

    FMain.Refresh


    If http.Status < 0 Then 
        Global.addtoStatusList("SORRY A Error was detected")
        global.AddToDebugList(http.ErrorText)
    Else
        ' Success - read data
        If Lof(http) Then Read #http, global.sBuffer, Lof(http)
                Global.addtoStatusList(global.sBuffer)


            Dim vNew As Variant = JSON.Decode(global.sBuffer, True)
            
                global.AddToDebugList(global.sBuffer)
                
                Select Case UCase(vNew["notifications"][0])
                    Case ""
                        ShowSaleResults(requestId, http)
                        
                    Case "CARD_ERROR"
                        Global.addtoStatusList("Sorry a error has been detected with the customers card")

                    Case "PROCESSING_ERROR"
                        Global.ddtoStatusList("Sorry there has been a processing Error." & gb.CrLf & "Please check the PinPad Screen for further information")

                    Case "SIGNATURE_VERIFICATION"
                        If global.WaitingForPoS = 0 Then
                            Global.addtoStatusList("Requesting PoS User to confirm Card Signture")
                            global.WaitingForPoS = 1
                            'CreateSigntureSlip_FromPDQ(TerminalType, responseFromServer, IDNumber)
                            'SendToPoSterminal("Printdata_Signture|" & PoSSlipData)
                            'SendToPoSterminal("SigntureCheck")
                            ShowSaleResults(requestId, http)
                        End If
                        
                    Case "TRANSACTION_FINISHED"
                            If Global.SigntureReq = 1 Then
                                LoadCardSlipData(RequestID)
                                'selectSlipToPrint(1, responseFromServer)
                                'SendToPoSterminal("Printdata_Recipit|" & PoSSlipData)
                                'SendToPoSterminal("TransactionCompleted|" & cardSchemeName & "|" & (amountTotal * 100))
                                Global.WaitingForPoS = 0
                                ShowSaleResults(requestId, http)
                                
                            Else
                                If Global.WaitingForPoS = 0 Then
                                    LoadCardSlipData(RequestID, requestId) 

                                    If UCase(Global.paymentMethod) = "KEYED" Then Global.SigntureNotNeeded = 1

                                        Select Case Global.SigntureNotNeeded
                                            Case 0 ' No Signutre needed
                                               'selectSlipToPrint(0, responseFromServer) '
                                                Select Case Global.PrintStoreSlip
                                                    Case "Yes"
                                                        'SendToPoSterminal("Printdata_Store|" & PoSSlipData)

                                                    Case "No"
                                                       'SendToPoSterminal("Storedata_Store|" & PoSSlipData & "|" & transactionNumber & "|" & IDNumber & "|" & transactionId)
                                                End Select
                                                
                                            Case 1 ' Signture needed
                                                'CustomerNOTPresentCardSlip_FromPDQ(TerminalType, responseFromServer, IDNumberLocal)
                                                'SendToPoSterminal("Printdata_Store|" & PoSSlipData)
                                                ShowSaleResults(requestId, http)
                                                
                                        End Select
                                    Else
                                        LoadCardSlipData(requestID)
                                        'selectSlipToPrint(2, responseFromServer)

                                        Select Case Global.PrintStoreSlip
                                            Case "Yes"
                                                'SendToPoSterminal("Printdata_Store|" & PoSSlipData)

                                            Case "No"
                                                'SendToPoSterminal("Storedata_Store|" & PoSSlipData & "|" & transactionNumber & "|" & IDNumber & "|" & transactionId)
                                        End Select

                                        LoadCardSlipData(Requestid)
                                        'selectSlipToPrint(1, responseFromServer)
                                        'SendToPoSterminal("Printdata_Recipit|" & PoSSlipData)
                                        'SendToPoSterminal("TransactionCompleted|" & cardSchemeName & "|" & (amountTotal * 100))
                                        ShowSaleResults(requestId, http)
                                    End If
                                End If

                    Case "REMOVE_CARD"
                        'SendToPoSterminal("RemoveCard")
                        Global.addtoStatusList("Please ask customer to remove card") ''
                        ShowSaleResults(requestId, http)

                    Case "APPROVED"
                        'SendToPoSterminal("Approved")
                        Global.addtoStatusList("Transaction has been approved")
                       ShowSaleResults(requestId, http)

                    Case "CONNECTION_MADE"
                        'SendToPoSterminal("ConnectionMade")
                        Global.addtoStatusList("Connection Established to Payment Provider")
                        ShowSaleResults(requestId, http)
                        
                                
                    Case "CONNECTING"
                        'SendToPoSterminal("Connecting")
                        Global.addtoStatusList("Connecting to Payment Provider")
                        ShowSaleResults(requestId, http)

                    Case "PIN_ENTRY"
                        'SendToPoSterminal("EnterPIN")
                        Global.addtoStatusList("Waiting for customer to enter PIN")
                        ShowSaleResults(requestId, http)

                    Case "PLEASE_WAIT"
                        'SendToPoSterminal("PleaseWait")
                        Global.addtoStatusList("Please Wait...")
                        ShowSaleResults(requestId, http)

                    Case "PRESENT_CARD"
                        'SendToPoSterminal("InsertCard")
                        Global.addtoStatusList("Please insert card")
                        ShowSaleResults(requestId, http)

                    Case "INSERT_CARD"
                        'SendToPoSterminal("InsertCard")
                        Global.addtoStatusList("Card has been inserted")
                        ShowSaleResults(requestId, http)

                    Case "TRANSACTION_STARTED"
                        'Global.SigntureNotNeeded = 0
                      '  Global.SigntureReq = 0
                        Global.addtoStatusList("Starting transacation One moment...")
                        ShowSaleResults(requestId, http)
                End Select
        End If
End 
As you can see the system uses the same feed to send the full status of the transaction (from Insert Card to Complete sale)
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Help With JSON formatting

Post by BruceSteers »

Pole?

When a message is processed the DeviceMessage.Location property is filled.
If at first you don't succeed , try doing something differently.
BruceS
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Help With JSON formatting

Post by AndyGable »

opps sorry that was a typo it should have said poll

with your class do I still call ShowSaleResults? to get the newest status message?

also could someone tell me why while running the transaction nothing is being added to the listbox even though I am adding messages to the list
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Help With JSON formatting

Post by BruceSteers »

AndyGable wrote: Thursday 18th August 2022 8:58am opps sorry that was a typo it should have said poll

with your class do I still call ShowSaleResults? to get the newest status message?

also could someone tell me why while running the transaction nothing is being added to the listbox even though I am adding messages to the list
How are you adding messages to the listbox?

Note.
ListBox1.List.Add(sText) will not work.

ListBox1.Add(sText) is how to do it.


A ListBox.List read returns a copy of the list only not a pointer to it.


And.
The class has one function _call() did you even read the source code i posted?
Or download the source i uploaded to see?
Or read the last message about it being bare bones and doesn't do anything much?

Good luck with your problem.
If at first you don't succeed , try doing something differently.
BruceS
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Help With JSON formatting

Post by AndyGable »

BruceSteers wrote: Thursday 18th August 2022 1:38pm
AndyGable wrote: Thursday 18th August 2022 8:58am opps sorry that was a typo it should have said poll

with your class do I still call ShowSaleResults? to get the newest status message?

also could someone tell me why while running the transaction nothing is being added to the listbox even though I am adding messages to the list
How are you adding messages to the listbox?

Note.
ListBox1.List.Add(sText) will not work.

ListBox1.Add(sText) is how to do it.


A ListBox.List read returns a copy of the list only not a pointer to it.


And.
The class has one function _call() did you even read the source code i posted?
Or download the source i uploaded to see?
Or read the last message about it being bare bones and doesn't do anything much?

Good luck with your problem.
Hi This is the code I am using to add to my listbox

Code: Select all

Public Sub addtoStatusList(textToShow As String)
  Dim gw As GridView
    Dim b As Byte

    fmain.lstSystemMessages.Add(Trim(textToShow)) ' add to list box
    fmain.lstSystemMessages.Index = fmain.lstSystemMessages.Count - 1 ' places the blue line onto the newly added item
    gw = fmain.lstSystemMessages.Children[0]

    b = fmain.lstSystemMessages.List.Max 

    gw.Rows[b].Height = -1 ' adjust blue line if the data is over 2 or more lines
    
    fmain.lstSystemMessages.Refresh
    fmain.Refresh
End Sub
if i am not doing anything with the Status of the transaction I get Messages Showing up (Example when I click Check Status i get the Message "Terminal Ready for Transaction" but the moment a sale starts nothing seems to be added to the list (even though I have the code to do it see example)

Code: Select all

Case "TRANSACTION_STARTED"
   'Global.SigntureNotNeeded = 0
   'Global.SigntureReq = 0
   Global.addtoStatusList("Starting transacation One moment...")
   ShowSaleResults(requestId, http)
 
as you can see I am adding the message "Starting transaction One moment..." but it does not get added

once the transaction is cancelled on the PinPad the list box refresh and everything is showing up

could this be a update issues between the thread running on the update command?

any help would be most appreachated
User avatar
thatbruce
Posts: 161
Joined: Saturday 4th September 2021 11:29pm

Re: Help With JSON formatting

Post by thatbruce »

I don't think the following will help as I know nothing about EFTPOS systems in the UK but here in AUS the basic concept is that once the transaction is initiated from the till system to the card terminal the process is entirely atomic and takes place between the customer and the financial switch system. One of the reasons is to prevent fraud by the operator. So I question whether you are actually getting these interim messages while the transaction is in process. Again here, all the till system receives is a notification whether the transaction was processed or it failed for any reason at all.
Also, signature authorisation is no longer used here. And I wonder just how many till operators in the UK have been trained on how to validate a customers signature? ;)
Here, any attempt to communicate between the till and terminal until the final result is obtained by the terminal will "fail" the transaction.
b
Have you ever noticed that software is never advertised using the adjective "spreadable".
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Help With JSON formatting

Post by AndyGable »

@thatbruce

Here we can have communication with the EFT PinPad but it is only from the PinPad to the PoS and all it is would be things like

Present card, PIN Entry, Connecting, Authorized etc (so the cashier can also see the status messages that the customer sees)

I can see the communication with no problems as it runs fine in the background the problem I have is nothing is being added to my listbox
until the HTTP work is completed and then the listbox refreshes and everything is showing up in the list (I am convinced it is something to do with how the thread is refreshing the form and the listbox)
Post Reply