Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Classic ASP code to C# equivilant

Posted on 2009-05-20
2
Medium Priority
?
1,693 Views
Last Modified: 2013-11-07
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
Comment
Question by:Paulconsulting
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
rdogmartin earned 1500 total points
ID: 24433052
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
 

Author Closing Comment

by:Paulconsulting
ID: 31583550
Thanks, i ended up using a different dll to solve the problem.  Thanks for your help.
0

Featured Post

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question