Paypal Silent Transaction in ASP.NET

  1. using System;  
  2. using System.Net;  
  3. using System.Text;  
  4. using System.IO;  
  5. public partial class PayPal  
  6. {  
  7.     public void DoDirect()  
  8.     {  
  9.         //API Credentials (3-token)  
  10.         string strUsername = "Your userName";  
  11.         string strPassword = "QFZCWN5HZM8VBG7Q";  
  12.         string strSignature = "A21eW1ch..NEqJJ-glaLhqkBMlzeAsWqX0ycck-CTc0tKI4pa1u.rgNF";  
  13.         string strCredentials = "USER=" + strUsername + "&PWD=" + strPassword + "&SIGNATURE=" + strSignature;  
  14.         string strNVPSandboxServer = "https://api-3t.sandbox.paypal.com/nvp";  
  15.         string strNVPLiveServer = "https://api-3t.paypal.com/nvp";  
  16.         string strAPIVersion = "2.3"  
  17.         string strNVP = strCredentials + "&METHOD=DoDirectPayment&CREDITCARDTYPE=VISA&ACCT=XXXXXXXXXXXXXXXXX&EXPDATE=092007&CVV2=808&AMT=212.95&FIRSTNAME=Designer&LASTNAME=Fotos&IPADDRESS=255.55.167.002&STREET=1234+Easy+Street&CITY=San+Jose&STATE=CA&COUNTRY=United+States&ZIP=95110&COUNTRYCODE=US&PAYMENTACTION=Sale&VERSION=" + strAPIVersion;  
  18.         //Create web request and web response objects, make sure you using the correct server (sandbox/live)  
  19.         HttpWebRequest wrWebRequest = (HttpWebRequest) WebRequest.Create(strNVPSandboxServer);  
  20.         //Set WebRequest Properties  
  21.         wrWebRequest.Method = "POST";  
  22.         // write the form values into the request message  
  23.         StreamWriter requestWriter = new StreamWriter(wrWebRequest.GetRequestStream());  
  24.         requestWriter.Write(strNVP);  
  25.         requestWriter.Close();  
  26.         // Get the response.  
  27.         HttpWebResponse hwrWebResponse = (HttpWebResponse) wrWebRequest.GetResponse();  
  28.         StreamReader responseReader = new StreamReader(wrWebRequest.GetResponse().GetResponseStream());  
  29.         // and read the response  
  30.         string responseData = responseReader.ReadToEnd();  
  31.         responseReader.Close();  
  32.         string result = Server.UrlDecode(responseData);  
  33.     }  
  34. }