VB.NET to Corona

hi guys,

i have a function written in VB.NET … this function calls a payment gateway … it is working perfectly

i want to run the same code using corona … but i’m not sure how to do it exactly

this is the VB.NET code … all you need is a windows form and a button inside the form … it will run smoothly

Imports System.Net Imports System.Text Imports System.IO Imports System.Web Public Class Form1     Private Sub Button1\_Click(sender As Object, e As EventArgs) Handles Button1.Click         Dim responseData         responseData = Request()("result")("description")         MsgBox(responseData)     End Sub     Public Function Request() As Dictionary(Of String, Object)         Dim url As String = "https://test.oppwa.com/v1/checkouts"         Dim data As String = "" +             "authentication.userId=8a8294174d0595bb014d05d829e701d1" +             "&authentication.password=9TnJPc2n9h" +             "&authentication.entityId=8a8294174d0595bb014d05d82e5b01d2" +             "&amount=92.00" +             "&currency=EUR" +             "&paymentType=DB"         Dim req As WebRequest = WebRequest.Create(url)         req.Method = "POST"         req.ContentType = "application/x-www-form-urlencoded"         Dim byteArray As Byte() = Encoding.UTF8.GetBytes(data)         req.ContentLength = byteArray.Length         Dim dataStream As Stream = req.GetRequestStream()         dataStream.Write(byteArray, 0, byteArray.Length)         dataStream.Close()         Dim res As WebResponse = req.GetResponse()         Dim resStream = res.GetResponseStream()         Dim reader As New StreamReader(resStream)         Dim response As String = reader.ReadToEnd()         reader.Close()         resStream.Close()         res.Close()         Dim jss As New System.Web.Script.Serialization.JavaScriptSerializer()         Dim dict As Dictionary(Of String, Object) = jss.Deserialize(Of Dictionary(Of String, Object))(response)         Return dict     End Function End Class

this is the code in lua but still not complete and not working … i’m not sure what is the equivalent to bytes array and where to put data variable in body or where …etc.

local headers = {} headers["accept"] = "application/json"; headers["Content-Type"] = "application/x-www-form-urlencoded"; headers["Accept-Language"] = "en-US"; local data1="\n".."authentication.userId=8a8294174d0595bb014d05d829e701d1".."\n".."&authentication.password=9TnJPc2n9h".."\n".."&authentication.entityId=8a8294174d0595bb014d05d82e5b01d2".."\n".."&amount=92.00".."\n".."&currency=EUR".."\n".."&paymentType=DB" local function networkListener( event ) -- local function that connects to webservice and get next available prize, for this game, for current Prize\_Val\_ID Reached which is between 1 and X...     if ( event.isError ) or event.response==nil then            else       print(event.response)   end  end local body = ""      local params = {} params.headers = headers params.body = body network.request( "https://test.oppwa.com/v1/checkouts", "POST", networkListener, params )

I don’t know much about vb.net, but when I see:

 Dim data As String = "" + "authentication.userId=8a8294174d0595bb014d05d829e701d1" + "&authentication.password=9TnJPc2n9h" + "&authentication.entityId=8a8294174d0595bb014d05d82e5b01d2" + "&amount=92.00" + "&currency=EUR" + "&paymentType=DB"

I see one long line of HTML key-value pairs. You’re inserting a bunch of newlines that I don’t believe your need. Try changing:

local data1="\n".."authentication.userId=8a8294174d0595bb014d05d829e701d1".."\n".."&authentication.password=9TnJPc2n9h".."\n".."&authentication.entityId=8a8294174d0595bb014d05d82e5b01d2".."\n".."&amount=92.00".."\n".."&currency=EUR".."\n".."&paymentType=DB"

into

local data1="authentication.userId=8a8294174d0595bb014d05d829e701d1&authentication.password=9TnJPc2n9h&authentication.entityId=8a8294174d0595bb014d05d82e5b01d2&amount=92.00&currency=EUR&paymentType=DB"

Then you need to get data1 into the body of the HTTP request:

params.body = data1

And then see if network.request() does what you want.

Rob

Thanks Rob you are absolutely correct on the string issue

i also need to find the equivalent of the below functions

        Dim byteArray As Byte() = Encoding.UTF8.GetBytes(data)

which seems to get a byte array of the string

Thanks

      

I believe that code is making the POST data UTF8 safe. I don’t know that it will cause you problems with Corona since Lua is UTF8 friendly. But this seems to be useful in making sure UTF8 strings get URL encoded properly:

https://www.rosettacode.org/wiki/URL_encoding#Lua

Rob

I don’t know much about vb.net, but when I see:

 Dim data As String = "" + "authentication.userId=8a8294174d0595bb014d05d829e701d1" + "&authentication.password=9TnJPc2n9h" + "&authentication.entityId=8a8294174d0595bb014d05d82e5b01d2" + "&amount=92.00" + "&currency=EUR" + "&paymentType=DB"

I see one long line of HTML key-value pairs. You’re inserting a bunch of newlines that I don’t believe your need. Try changing:

local data1="\n".."authentication.userId=8a8294174d0595bb014d05d829e701d1".."\n".."&authentication.password=9TnJPc2n9h".."\n".."&authentication.entityId=8a8294174d0595bb014d05d82e5b01d2".."\n".."&amount=92.00".."\n".."&currency=EUR".."\n".."&paymentType=DB"

into

local data1="authentication.userId=8a8294174d0595bb014d05d829e701d1&authentication.password=9TnJPc2n9h&authentication.entityId=8a8294174d0595bb014d05d82e5b01d2&amount=92.00&currency=EUR&paymentType=DB"

Then you need to get data1 into the body of the HTTP request:

params.body = data1

And then see if network.request() does what you want.

Rob

Thanks Rob you are absolutely correct on the string issue

i also need to find the equivalent of the below functions

        Dim byteArray As Byte() = Encoding.UTF8.GetBytes(data)

which seems to get a byte array of the string

Thanks

      

I believe that code is making the POST data UTF8 safe. I don’t know that it will cause you problems with Corona since Lua is UTF8 friendly. But this seems to be useful in making sure UTF8 strings get URL encoded properly:

https://www.rosettacode.org/wiki/URL_encoding#Lua

Rob