Solved

Classic ASP code to C# equivilant

Posted on 2009-05-20
2
1,679 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 500 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

617 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