.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Post New Resource Bookmark and Share   

Paypal linking reg

Posted By:Gowthammanju       Posted Date: July 31, 2011    Points: 200    Category:    URL: http://www.dotnetspark.com  

this article explains about linking of paypall to our website
 

While page Designing make sure you have these Fields

1) Card Type

2) Textbox for CreditCard Number

3) Expire DateĀ  / Expire Month

4) Pay button / Cancel button

paybutton_Click
try
        {
              bool validateCard = false;
              if (ddlCCType.SelectedValue.ToString() == "Visa")
              {
                  validateCard = CardValidator.Validate( CardType.Visa , 

txtCCNumber.Text);
              }
              else if (ddlCCType.SelectedValue.ToString() == "MasterCard")
              {
                  validateCard = CardValidator.Validate(CardType.MasterCard , 

txtCCNumber.Text);
              }
              else if (ddlCCType.SelectedValue.ToString() == "AMEX")
              {
                  validateCard = CardValidator.Validate(CardType.AmericanExpress, 

txtCCNumber.Text);
              }

            if (validateCard != false)
            {
                  string ipaddress;

                ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

                if (ipaddress == "" || ipaddress == null)
                {
                    ipaddress = Request.ServerVariables["REMOTE_ADDR"];

                }
        Session["ipAddress"] = ipaddress;

         //API Credentials (3-token)

            string strUsername = "troy2._1261822640_biz_api1.gmail.com";

            string strPassword = "1261822646";

            string strSignature = 

"An5ns1Kso7MWUdW4ErQKJJJ4qi4-A60C4mgCoX2-L9FhwhF2rfGtRPeI";

            string strCredentials = "USER=" + strUsername + "&PWD=" + strPassword 

+ "&SIGNATURE=" + strSignature;
        
            // For Sandbox testing use this API 
            string strNVPSandboxServer = "https://api-3t.sandbox.paypal.com/nvp";

            // Fpr Live Server use this API
            string strNVPLiveServer = "https://api-3t.paypal.com/nvp";

            string strAPIVersion = "2.3";

// here i am assigning the credit card type cardno,expiry date/month to
 //the session variable and pass it here 

                       string strNVP = strCredentials + 

"&METHOD=DoDirectPayment&CREDITCARDTYPE=" + Session["cardType"].ToString() + 

"&ACCT=" + Session["cardNo"].ToString() + "&EXPDATE=" + 

Session["expiryDate"].ToString() + "&CVV2=808&AMT=" + Amount_Label.Text + 

"&FIRSTNAME=" + FirstName_Label.Text + "&LASTNAME=" + LastName_Label.Text + 

"&IPADDRESS=" + Session["ipAddress"].ToString() + "&STREET=" + address1 + "+" + 

address2 + "&CITY=" + city + "&STATE=" + state + "&COUNTRY=" + country + "&ZIP=" 

+ zip + "&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();
            Response.Write(Server.UrlDecode(responseData));
               
            }
            else
            {
                validateCard_Label.Text = "Please check your card number...";
            }
            
            
          
        }
        catch (Exception ex)
        {
            throw ex;
        } 

Finally , once your Transaction is success you will get the output ie:TransactionID with ack

EX: Output

ACK=Success&TIMESTAMP=date/timeOfResponse
&CORRELATIONID=debuggingToken&VERSION=2.300000&BUILD=buildNumber
&TOKEN=EC-3DJ78083ES565113B&EMAIL=abcdef@anyemail.com
&PAYERID=95HR9CM6D56Q2&PAYERSTATUS=verified
&FIRSTNAME=John&LASTNAME=Smith...&AMT=15&TRANSACTIONID=24527936A38716


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend