|
Looks like I got this one. Here is the code I was falling all over. This is simplistic and without web.config for now: First Create a button on anyold aspx page. Now go to the code behind and add: <!---------------Syntax Starts Here--------------------------------------> using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Net; using System.Text; using System.IO; using System.Text.RegularExpressions; public partial class vps_home : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //*************** Note *********************** //before using this code change the following line below: wrWebRequest.Headers.Add("X-VPS-VIT-Client-Certification-Id:14"  ; //you need to change the ID to something beside 14 that will be unique //2. Set your user info. This is case sensitive string PWD = "xxx"; string USER= "xxx"; string VENDOR="xxx"; string PARTNER = "xxx"; //3. now create the name value pair string to send to the Payflow servers //more variables can be found in the docs that can be downloaded from your payflow manager StringBuilder postData = new StringBuilder(); //***************add the user info*************** postData.Append("PWD=" + PWD); postData.Append("&USER=" + USER); postData.Append("&VENDOR=" + VENDOR); postData.Append("&PARTNER=" + PARTNER); //***************add some required info for testing*************** postData.Append("&CUSTIP=" + Request.UserHostAddress); //S for Sale. A for Auth. More in the docs postData.Append("&TRXTYPE=S"  ; postData.Append("&AMT=1.00"  ; //this is in the format MMYY postData.Append("&EXPDATE=0109"  ; postData.Append("&ACCT=5105105105105100"  ; postData.Append("&CVV2=123"  ; postData.Append("&FIRSTNAME=bob"  ; postData.Append("&LASTNAME=smith"  ; postData.Append("&STREET=155515 Q St"  ; postData.Append("&STATE=NE"  ; postData.Append("&CITY=Omaha"  ; postData.Append("&ZIP=68137"  ; postData.Append("&COUNTRY=US"  ; //C is for credit card, P is for PayPal Express Checkout. More in the docs postData.Append("&TENDER=C"  ; //*************add some optional feilds*************** postData.Append("&COMMENT1=ASP.NET Testing"  ; //make sure that the "@" is not url encoded or you will get an error postData.Append(" &email=bob@domain.com"  ; //this is if you want to have PayPal send an IPN post //postData.Append("&NOTIFYURL=" + xxxx); //removed for now: INVNUM=12345678& //add the REQUEST_ID postData.Append("&REQUEST_ID=" + System.Guid.NewGuid().ToString()); //write out the post data Response.Write("PostData:<br> " + postData + "<br><br>"  ; byte[] requestBytes = Encoding.UTF8.GetBytes(postData.ToString()); HttpWebRequest wrWebRequest = (HttpWebRequest)WebRequest.Create(postURL); //Set WebRequest Properties wrWebRequest.Method = "POST"; wrWebRequest.Accept = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; wrWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7"; wrWebRequest.ContentType = "text/namevalue"; wrWebRequest.ContentLength = requestBytes.Length; wrWebRequest.AllowAutoRedirect = false; //add the custom headers wrWebRequest.Headers.Add("X-VPS-Timeout:30"  ; wrWebRequest.Headers.Add("X-VPS-VIT-Client-Architecture:x86"  ; wrWebRequest.Headers.Add("X-VPS-VIT-Client-Certification-Id:14"  ; wrWebRequest.Headers.Add("X-VPS-VIT-Client-Type:ASP.NET"  ; wrWebRequest.Headers.Add("X-VPS-VIT-Client-Version:0.0.1"  ; wrWebRequest.Headers.Add("X-VPS-VIT-Integration-Product:Homegrown"  ; wrWebRequest.Headers.Add("X-VPS-VIT-Integration-Version:0.0.1"  ; wrWebRequest.Headers.Add("X-VPS-VIT-OS-Name:windows"  ; wrWebRequest.Headers.Add("X-VPS-VIT-OS-Version:2002_SP2"  ; // write the form values into the request message Stream reqStream = wrWebRequest.GetRequestStream(); reqStream.Write(requestBytes, 0, requestBytes.Length); // Get the response. HttpWebResponse hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse(); reqStream.Close(); StreamReader responseReader = new StreamReader(wrWebRequest.GetResponse().GetResponseStream()); string responseData = responseReader.ReadToEnd(); responseReader.Close(); Response.Write("Response Data:<br>" + responseData); } }
<!--------------Syntax obviously ends Here---------------------------> Special Thanks to: Ahmad PayPal Merchant Technical Support
|