Sunday 9 October 2016

Paypal direct payment ( Silent Transaction ) in ASP.NET

This code describes the complete code for silent transaction in PayPal using Merchant account (Pro).


  
using System.Text;  
using System.IO;  
public partial class PayPal  
{  
    public void DoDirect()  
    {  
        //API Credentials (3-token)  
        string strUsername = "Your userName";  
        string strPassword = "QFZCWN5HZM8VBG7Q";  
        string strSignature = "A21eW1ch..NEqJJ-glaLhqkBMlzeAsWqX0ycck-Tc0tKI4pa1u.rgNF";  
        string strCredentials="USER="+strUsername+"&PWD="+strPassword+"&SIGNATURE="+strSignature;  
        string strNVPSandboxServer = "https://api-3t.sandbox.paypal.com/nvp";  
        string strNVPLiveServer = "https://api-3t.paypal.com/nvp";  
        string strAPIVersion = "2.3"  
        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;  
        //Create web request and web response objects, make sure you using the correct server (sandbox/live)  
        HttpWebRequest wrWebRequest = (HttpWebRequest) WebRequest.Create(strNVPSandboxServer);  
        //Set WebRequest Properties  
        wrWebRequest.Method = "POST";  
        // write the form values into the request message  
        StreamWriter requestWriter = new StreamWriter(wrWebRequest.GetRequestStream());  
        requestWriter.Write(strNVP);  
        requestWriter.Close();  
        // Get the response.  
        HttpWebResponse hwrWebResponse = (HttpWebResponse) wrWebRequest.GetResponse();  
        StreamReader responseReader = new StreamReader(wrWebRequest.GetResponse().GetResponseStream());  
        // and read the response  
        string responseData = responseReader.ReadToEnd();  
        responseReader.Close();  
        string result = Server.UrlDecode(responseData);  
    }  
}  

No comments:

Post a Comment