Solved

Classic ASP code to C# equivilant

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Angular JS Route 3 45
Run time Error 4 34
Help with C#, MVC, razor. 6 21
IIS issues - Convert to Application - APS.NET v4.0 3 19
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
A short film showing how OnPage and Connectwise integration works.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

919 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now