Help needed please to migrate from VB2008 HttpWebRequest functions to Gambas

Post

Posted
Rating:
#1 (In Topic #744)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
Hi everyone,

I would like some help with the below code

Code (gambas)

  1.         Try
  2.             Dim Request As HttpWebRequest = HttpWebRequest.Create(PS_URL & "/terminals/" & TerminalIDNumber)
  3.             Dim credentials As String = Convert.ToBase64String(Encoding.ASCII.GetBytes(PS_USER & ":" & PS_PASS))
  4.             txtResults.Text = vbNullString
  5.  
  6.             With Request
  7.                 .Proxy = Nothing
  8.                 .Headers(HttpRequestHeader.Authorization) = String.Format("Basic \{0}", credentials)
  9.                 .Accept = "application/connect.v2+json"
  10.                 .Headers.Add("Software-House-Id: SD459T92") ' algPoS ID Number
  11.                 .Headers.Add("Installer-Id:ABC12319785")
  12.                 .UserAgent = PS_USER
  13.             End With
  14.  
  15.             Dim response As HttpWebResponse = Request.GetResponse()
  16.             Dim dataStream As Stream = response.GetResponseStream
  17.             Dim reader As New StreamReader(dataStream)
  18.             Dim responseFromServer As String = reader.ReadToEnd()
  19.  
  20.             txtResults.Text = responseFromServer
  21.  
  22.  
  23.             If responseFromServer = "0" Then
  24.                 MsgBox("Retreal of Status Failed")
  25.             Else
  26.                 Dim json As String = responseFromServer
  27.                 Dim ser As JObject = JObject.Parse(json)
  28.                 Dim data As List(Of JToken) = ser.Children().ToList
  29.                 For Each item As JProperty In data
  30.                     item.CreateReader()
  31.                     Select Case item.Name
  32.                         Case "status"
  33.                             Select Case item.Value
  34.                                 Case "AVAILABLE"
  35.                                     GetStatus = 1
  36.                                     If DontSendDataToPoS = 0 Then SendToPoSterminal("TerminalOnLine|")
  37.                                     Me.ListBox1.Items.Clear
  38.                                     addtoStatusList("Terminal Ready")
  39.  
  40.                                 Case "BUSY"
  41.                                     If DontSendDataToPoS = 0 Then SendToPoSterminal("TerminalBusy|")
  42.                                     addtoStatusList("Terminal busy please wait 10 seconds and try again")
  43.  
  44.                                 Case "Offline", "OFFLINE", "offline"
  45.                                     If DontSendDataToPoS = 0 Then SendToPoSterminal("offline|")
  46.                                     addtoStatusList("Terminal OFFLINE NO Card processing Possible - Please check with Payment Sense")
  47.                             End Select
  48.                     End Select
  49.                 Next
  50.             End If
  51.         Catch ex As Exception
  52.             addtoStatusList(ex.ToString)
  53.             If DebugActive = "Yes" Then AddToDebugList(ex.ToString)
  54.             If DontSendDataToPoS = 0 Then SendToPoSterminal("ProcessingError")
  55.             FromPoSTCP.Stop()
  56.             FromPoSTCP.Start()
  57.         End Try
  58.  

As you can see this is code I am using in my VB application that talks to one of the card processing servers that I talk to for card processing (this code gets the status of the Terminal as this is the simplest example of what the terminal does I figured this would be the best one to start with)

I have tried for weeks to get something to work and I have given up.

could some one please convert this so it would work in Gambas (once i can see what was converted I would have a better understanding of how to do the rest of the code I need to do) I know I am asking a lot of someone to covert the above code but I just can not work it out.
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
Andy,
Why not throw out the VB code, read the Gambas help files and write it the Gambas way?
Or at least convert the VB code into a pseudo-code summary and post that.

(I've said it before and no doubt I'll say it again: I couldn't be bothered less reading VB code, let alone trying to understand it. I am sorry if this attitude offends some people but it is the truth.)

Online now: No Back to the top

Post

Posted
Rating:
#3
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
 I can not throw the vb code out as that is the code that has been approved by the card processing people.

I just need to see what I have to change for Gambas but so far no matter what I read up on and try nothing works.

Any advise most welcome at the moment.
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
Andy,
I just spent two hours writing a treatise on how this stuff works only to have phpBB time out and delete that entire work. :evil:  :evil:  :evil:  :evil:  So briefly

Advice, as requested.
  1. find out and understand how all the upstream processing for a payment  works and the subtle differences between "authorised", "declined" and "failed" response codes.
  2. research the Gambas http components and how they work (IOW RTFM) then ask questions about them, don't ask "homework" questions.
  3. find out about the payment processors transaction cancellation, refund and transaction amendment protocols
  4. find out about how to do "post transaction queries" and the protocols there
  5. figure out how to handle communications failures between your node and the payment processor node.
  6. figure out how to get your till reports back in order after a 5).

Wishing you the best of luck, this stuff can take in the order of 6-18 man months to implement, test and get "approved"  (hah! any payments processor that is still claiming that level of authority is either above themselves or spruiking an insecure or unstable interface. )
thatbruce

p.s. By way of qualification, my c.v. has better than 15 years of working with payments systems.

Online now: No Back to the top

Post

Posted
Rating:
#5
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
 The card processor I use does all the work (talk to the card machine etc) the only connection between the POS and the card is a cloud API that sends the data

I have all ready been approved for the windows version (took 2 days to Implement)

I may just have to bite the bullet and have windows on a raspberry pi.
Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’
I'd focus on getting the following 2 lines converted correctly.

   
 
     Dim credentials As String = Convert.ToBase64String(Encoding.ASCII.GetBytes(PS_USER & ":" & PS_PASS))
   
 
   
 
        .Headers(HttpRequestHeader.Authorization) = String.Format("Basic {0}", credentials)
 

The rest of the code looks almost like Gambas and should not be that hard to convert.
the exact differences in the conversion of your credentials string is going to be the fall down i reckon.

Can you edit the VB app to display the exact credential string it produces and sends and then get the gambas to do the same to see if they match.

Print Quote(credentials)  in gambas will give you a quoted string showing all the escape chars too.
Online now: No Back to the top
1 guest and 0 members have just viewed this.