• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1786
  • Last Modified:

Classic ASP code to C# equivilant

I need help translating the following code to the equivilant in ASP.NET C#.  It is for use with Paypal payflow pro to provide a simple interface to submit transactions.  I'm not looking for alternatives, just the translation equivilant.  My main problem is the Server.CreateObject("WinHttp.WinHttpRequest.5.1")  Thanks in advance.
'**************************************************************************
' This work product is provided "AS IS" and without warranty. 
'**************************************************************************
 
'Please refer to the posting regarding the HTTPS Interface on the PayPal Developer's
'Forum for the Payflow Gateway.  Go to http://www.paypaldeveloper.com and "Jump to" 
'Payflow Gateway.
'
'You will also need to reference the Payflow Pro Developer's Guide are that available
'from the Integration Center at https://www.paypal.com/IntegrationCenter/ic_payflowpro.html.
 
'Things you should implement are:
' 
'1. Check for DUPLICATE transaction and react accordingly.
'2. Build in some re-try logic in case you do not receive a response.  You will
'   need to take into consideration the Request ID. See the HTTPS Interface posting for
'   more information on the Request ID and DUPLICATE response.
 
'Define the Gateway URL
'Do not use the older host URls of test-payflow.verisign.com or payflow.verisign.com.
 
if request.form("GHostURL") = 0 then
	GatewayHost = "https://pilot-payflowpro.paypal.com"
elseif request.form("GHostURL") = 1 then
	GatewayHost = "https://payflowpro.paypal.com"
end if
 
'Put in your login information here
Password = "xxxxx"
UserID = "xxxxxx"
VendorID = "xxxxxx"
PartnerID = "xxxxxx"
 
' Start out declaring our variables.
Dim objWinHttp
Dim strHTML
Dim parmList
Dim requestID
 
' Need to generate a unique id for the request id
requestID = generateRequestID(32)
 
'Build the parameter list
'
'This a very, very basic implementation to just how how you can post data.  What data 
'you decide to send and how your react to the response is a business decision that you
'must make.
parmList = "TENDER=C"
parmList = parmList + "&ACCT=" + request.form("cardNum") 
parmList = parmList + "&PWD=" & Password
parmList = parmList + "&USER=" & UserID
parmList = parmList + "&VENDOR=" & VendorID
parmList = parmList + "&PARTNER=" & PartnerID
parmList = parmList + "&EXPDATE=" + request.form("cardExp")
parmList = parmList + "&AMT=" + request.form("amount")
parmList = parmList + "&TRXTYPE=" + request.form("TransactType")
parmList = parmList + "&STREET=" + request.form("StreetAddress")
parmList = parmList + "&ZIP=" + request.form("ZipCode")
 
'original v3 SDK line, replaced with WinHttp
' create the PNCOMClient component
'Set client = Server.CreateObject("PFProCOMControl.PFProCOMControl.1")
 
'Open Session
Set objWinHttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
 
' Full Docs:
' http://msdn.microsoft.com/library/en-us/winhttp/http/portal.asp
'
' If you have trouble or are getting connection errors,
' try using the proxycfg.exe tool.
 
' Here we get the request ready to be sent.
' First 2 parameters indicate method and URL.
' The third is optional and indicates whether or not to
' open the request in asyncronous mode (wait for a response
' or not).  The default is False = syncronous = wait.
' Syntax:
 
'original v3 SDK line, replaced with WinHttp Open statement
'Ctx1 = client.CreateContext("payflow.verisign.com", 443, 30, "", 0, "", "")
objWinHttp.Open "POST", GatewayHost, False
 
'Build the headers
'
'The required headers are Content-Type, X-VPS-Timeout and X-VPS-Request-ID.  All other headers are for
'your use and you'd populate them based on your environment.
'
objWinHttp.setRequestHeader "Content-Type", "text/namevalue"  ' for XML, use text/xml
'objWinHttp.SetRequestHeader "Host", "mywebsite.com"   ' your website
objWinHttp.SetRequestHeader "X-VPS-Timeout", "30"
'objWinHttp.SetRequestHeader "X-VPS-VIT-Client-Architecture", "x86"  ' set to your environment
'objWinHttp.SetRequestHeader "X-VPS-VIT-Client-Type", "ASP/Classic"
'objWinHttp.SetRequestHeader "X-VPS-VIT-Client-Version", "0.0.1"     ' your application version
'objWinHttp.SetRequestHeader "X-VPS-VIT-Integration-Product", "Homegrown"   ' your application 
'objWinHttp.SetRequestHeader "X-VPS-VIT-Integration-Version", "0.0.1"
'objWinHttp.SetRequestHeader "X-VPS-VIT-OS-Name", "windows"      ' your OS
'objWinHttp.SetRequestHeader "X-VPS-VIT-OS-Version", "2002_SP2"  ' your OS version
objWinHttp.SetRequestHeader "X-VPS-Request-ID", requestID
 
'Send Parameter List
'original v3 SDK line, replaced with WinHttp Send
'curString = client.SubmitTransaction(Ctx1, parmList, Len(parmList))
objWinHttp.Send parmList
 
' Print out the request status:
Response.Write "Status: " & objWinHttp.Status & " " _
	& objWinHttp.StatusText & "<br />"
 
' Get the text of the response.
transResponse = objWinHttp.ResponseText
 
'original v3 SDK line, replaced with Nothing statement
'client.DestroyContext (Ctx1)
' Trash our object now that we are finished with it.
Set objWinHttp = Nothing

Open in new window

0
Paulconsulting
Asked:
Paulconsulting
1 Solution
 
rdogmartinCommented:
This isn't the translation you asked for, but I think it will help. It is code I use during a PayPal payment notification. I construct an HTTP post and then read the HTTP response back as a string. The HttpWebRequest object has a Headers property for setting the request headers.

private bool ValidateNotification()
{
	const string PAYPAL_URL = "https://www.paypal.com/cgi-bin/webscr";
 
	HttpWebRequest req = (HttpWebRequest)WebRequest.Create(PAYPAL_URL);
 
	//Set values for the request back
	req.Method = "POST";
	req.ContentType = "application/x-www-form-urlencoded";
	byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
	string strRequest = System.Text.Encoding.ASCII.GetString(param);
	strRequest += "&cmd=_notify-validate";
	req.ContentLength = strRequest.Length;
 
	//Send the request to PayPal and get the response
	StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
	streamOut.Write(strRequest);
	streamOut.Close();
	StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
	string strResponse = streamIn.ReadToEnd();
	streamIn.Close();
 
	return (strResponse == "VERIFIED");
}

Open in new window

0
 
PaulconsultingAuthor Commented:
Thanks, i ended up using a different dll to solve the problem.  Thanks for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now