PayPal POST payment not working on mobile browsers - vb.net

I have a web application written in VB.net. I implemented the payment via paypal.
When I make a payment via pc there is no problem, but when I make a payment via mobile I have some problems.
I can't read the paypal parameters on my return page.
I used httpwebrequest for read the info from paypal, but the variables request.form is empty, so the response is "INVALID".
is there anyone who can help me??? please...

This is my code:
Dim objHttp As HttpWebRequest
objHttp = WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr")
objHttp.Method = "POST"
objHttp.ContentType = "application/x-www-form-urlencoded"
Dim param As Byte() = Request.BinaryRead(HttpContext.Current.Request.ContentLength)
Dim strRequest As String = Encoding.ASCII.GetString(param)
Dim ipnPost As String = strRequest
strRequest += "&cmd=_notify-validate"
objHttp.ContentLength = strRequest.Length
'Send the request to PayPal and get the response
Dim streamOut As New StreamWriter(objHttp.GetRequestStream(), System.Text.Encoding.ASCII)
streamOut.Write(strRequest)
streamOut.Close()
Dim streamIn As New StreamReader(objHttp.GetResponse().GetResponseStream())
Dim strResponse As String = streamIn.ReadToEnd()
streamIn.Close()
Dim myHttpWebResponse As HttpWebResponse = CType(objHttp.GetResponse(), HttpWebResponse)
Dim strIdTransazione = Request.Form("txn_id")
Dim strDscTransazione = Request.Form("payment_status")
'HttpStatusCode.myHttpWebResponse.StatusCode()
If myHttpWebResponse.StatusCode <> HttpStatusCode.OK Then
Else
end if

Related

VB POST request whit form-control values

I am having different problems when trying to make a POST request to my API, the API works perfectly tested in postman.
I would like to know if anyone sees that I am doing wrong, thank you very much
Dim url As String = "http://0.0.0.0/connect"
Dim dataToPassFromFormData As String = "client_id=1020&client_secret=FF29D58E&grant_type=password&username=admin&password=123"
Dim enc As UTF8Encoding
Dim postdatabytes As Byte()
Dim request As HttpWebRequest = TryCast(WebRequest.Create(url), HttpWebRequest)
enc = New System.Text.UTF8Encoding()
postdatabytes = enc.GetBytes(dataToPassFromFormData)
request.Method = "POST"
request.ContentLength = postdatabytes.Length
Using stream = request.GetRequestStream()
stream.Write(postdatabytes, 0, postdatabytes.Length)
End Using
Dim response As HttpWebResponse = TryCast(request.GetResponse(), HttpWebResponse)
Dim receiveStream As Stream = response.GetResponseStream()
Dim readStream As StreamReader = New StreamReader(receiveStream, Encoding.UTF8)
Dim us As user
us = JsonConvert.DeserializeObject(Of user)(readStream.ReadToEnd())
response.Close()
readStream.Close()
Return us.access_token
My api expects these parameters by body / form-data
client_id=1020
client_secret=FF29D58E
grant_type=password
username=admin
password=123

Create SOAP request with vb.net

I'm trying to call a webservice in vb.net and I have followed this thread: WebService Send SOAP request and received response using visual Basic
These are the steps that I have followed:
I have already add the reference to the project (http://webservice_url?wsdl).
I have written the soap request in an xml file by hand (I attach the xml file as image here )
I have load the xml file into an string variable and call to the webservice like that:
Dim strDocumentoSoap As String
Dim document As XDocument = XDocument.Load("C:\myFile.xml")
strDocumentoSoap = document.ToString
Dim servicioWeb As svc.v79jIntegracionPerfilSesion = New svc.v79jIntegracionPerfilSesion
Dim sbLogin As New System.Text.StringBuilder
sbLogin.Append(strDocumentoSoap)
Dim hwrequest As System.Net.HttpWebRequest
hwrequest = System.Net.WebRequest.Create("http://myServiceURL/realizarPeticionPublicacionOSBUS?WSDL")
hwrequest.Method = "POST"
hwrequest.ContentType = "text/xml; charset=utf-8"
Dim byteData As Byte() = System.Text.Encoding.UTF8.GetBytes(sbLogin.ToString())
hwrequest.ContentLength = byteData.Length
Dim writer As Stream = hwrequest.GetRequestStream
writer.Write(byteData, 0, byteData.Length)
writer.Close()
Dim Response As System.Net.HttpWebResponse
Response = hwrequest.GetResponse
Dim responseStatus As String = Response.StatusDescription.ToString
Dim DataStream As Stream
Dim Reader As StreamReader
DataStream = Response.GetResponseStream()
Reader = New StreamReader(DataStream)
Dim SD2Request As String = Reader.ReadToEnd()
'SHOW THE RESPONSE INTO MSGBOX
MsgBox(SD2Request)
This works perfectly, but I have read in the internet that this practice is not recommended (hand made XML for SOAP), because there are other useful tools in .net.
Can anyone explain me other options or libraries for creating a soap request in VB.NET without creating the soapenvelope by hand.
Thank you very much in advance!
Marga

how to use API in Vb net

What is the best way to issue a http get in VB.net? I want to get the result of a request like
http://89.36.220.56/api.php?photo=urlphoto&point=numberlikes&socks=proxy
Photo = URL Photo
Point = Number
Socks = Proxy
Dim url = "http://89.36.220.56/api.php?photo=urlphoto&point=numberlikes&socks=proxy"
Dim request = DirectCast(WebRequest.Create(url), HttpWebRequest)
Dim response = request.GetResponse()
Dim receiveStream As Stream = response.GetResponseStream()
Dim readStream As New StreamReader(receiveStream, Encoding.UTF8)
Dim data = readStream.ReadToEnd()
response.Close()
readStream.Close()

Error trying to Create ASANA Project in VB.NET

I am getting an error:
400 Bad request
when trying to create a project via vb.net in asana.
Note: The ApiKey I am using works when I use it in other vb.net code to get the list of workspaces which is where I got my workspace ID.
Here is my code; I would be grateful for any insight...
Public Sub main()
Dim address As Uri
address = New Uri("https://app.asana.com/api/1.0/projects")
Dim ApiKey As String
ApiKey = "<my api key>"
Dim basicAuthenticationString As String
basicAuthenticationString = Convert.ToBase64String(New UTF8Encoding().GetBytes(ApiKey + ":"))
' Create the web request
Dim request As HttpWebRequest
request = DirectCast(WebRequest.Create(address), HttpWebRequest)
request.Headers("Authorization") = "Basic " & basicAuthenticationString
request.Method = "POST"
request.ContentType = "application/json"
Dim postData As String = "{""data"":[{""name"":""Randy Test Project"",""notes"":""Randy Test Project Notes"",""workspace"":5272875888767}]}"
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
request.ContentLength = byteArray.Length
Dim dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
Dim response As HttpWebResponse = request.GetResponse()
Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
dataStream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
Console.WriteLine(responseFromServer)
reader.Close()
dataStream.Close()
response.Close()
Exit Sub
End Sub
I was able to figure it out, My address needed to be:
Dim address As Uri = New Uri("app.asana.com/api/1.0/teams/22956925957833/projects")
Then my postData needed to be:
Dim postData As String = "{""data"":{""name"":""Randy Test Project"",""notes"":""Randy Test Project Notes""}}"
Alternatively, you can specify the team or workspace in the post data. When you get a 400 Bad Request the body of the error response will tell you which fields were actually missing/invalid.

PayPal IPN issue for notify

I have set up a PDT form and that is working and collecting payments and then returning to the appropriate url with the follow parameters
tx=1******X&st=Completed&amt=0.02&cc=GBP&cm=&item_number=NA
I am using the follow example code:
Dim strSandbox As String = "https://www.sandbox.paypal.com/cgi-bin/webscr"
Dim strLive As String = "https://www.paypal.com/cgi-bin/webscr"
Dim req As HttpWebRequest = CType(WebRequest.Create(strLive), HttpWebRequest)
'Set values for the request back
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
Dim Param() As Byte = Request.BinaryRead(HttpContext.Current.Request.ContentLength)
Dim strRequest As String = Encoding.ASCII.GetString(Param)
strRequest = strRequest & "&cmd=_notify-validate"
req.ContentLength = strRequest.Length
'for proxy
'Dim proxy As New WebProxy(New System.Uri("http://url:port#"))
'req.Proxy = proxy
'Send the request to PayPal and get the response
Dim streamOut As StreamWriter = New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
streamOut.Write(strRequest)
streamOut.Close()
Dim streamIn As StreamReader = New StreamReader(req.GetResponse().GetResponseStream())
Dim strResponse As String = streamIn.ReadToEnd()
streamIn.Close()
If strResponse = "VERIFIED" Then
'check the payment_status is Completed
'check that txn_id has not been previously processed
'check that receiver_email is your Primary PayPal email
'check that payment_amount/payment_currency are correct
'process payment
lit1.Text = "verified"
ElseIf strResponse = "INVALID" Then
'log for manual investigation
lit1.Text = "invalid"
Else
'Response wasn't VERIFIED or INVALID, log for manual investigation
lit1.Text = "unknown"
End If
lit1.Text = lit1.Text & "<br /><br />" & strRequest.ToString
I am only getting an invalid response so I tried to see what was being sent to Paypal but its only sending &cmd=_notify-validate and not rest of the parameters.
So I manually added to the parameters but still only got invalid.
Could someone please assist with what I am missing? The payment was successful
Thanks
I sorted it, I didnt understand the process but do now