string strUsername = “api user name”;
            string strPassword = “pasword”;
            string strSignature = “signature”;
            string strCredentials = “USER=” + strUsername + “&PWD=” + strPassword + “&SIGNATURE=” + strSignature;

            string strNVPSandboxServer = “https://api-3t.sandbox.paypal.com/nvp”;
            string strAPIVersion = “50.0”;
        
            string strNVP = strCredentials + “&METHOD=DoDirectPayment” +
            “&CREDITCARDTYPE=” + “credit card type”+
            “&ACCT=” + “credit card number” +
            “&EXPDATE=” + “expire date” +
            “&CVV2=” + “cvv number”+
            “&AMT=” + “100” +
            “&FIRSTNAME=” + “Gopal” +
            “&LASTNAME=” + “Singh”+
            “&IPADDRESS= ip address” +
            “&STREET=” + “street” +
            “&CITY=” + “city”+
            “&STATE=” +”state”+
            “&COUNTRY=” + “contry” +
            “&ZIP=” +”1234″ + “” +
            “&CURRENCYCODE=GBP” +
            “&PAYMENTACTION=Sale” +
            “&VERSION=” + strAPIVersion;

            try
            {
                //Create web request and web response objects, make sure you using the correct server (sandbox/live)
                HttpWebRequest wrWebRequest = (HttpWebRequest)WebRequest.Create(strNVPSandboxServer);
                wrWebRequest.Method = “POST”;
                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);

                string[] arrResult = result.Split(‘&’);
                Hashtable htResponse = new Hashtable();
                string[] responseItemArray;
                foreach (string responseItem in arrResult)
                {
                    responseItemArray = responseItem.Split(‘=’);
                    htResponse.Add(responseItemArray[0], responseItemArray[1]);
                }

                string strAck = htResponse[“ACK”].ToString();
                Response.Write(strAck);

                if (strAck == “Success” || strAck == “SuccessWithWarning”)
                {
                    string strAmt = htResponse[“AMT”].ToString();
                    string strCcy = htResponse[“CURRENCYCODE”].ToString();
                    string strTransactionID = htResponse[“TRANSACTIONID”].ToString();
                    string strSuccess = “Thank you, your order for: $” + strAmt + ” ” + strCcy + ” has been processed.”;

                }
                else
                {
                    string strErr = “Error: ” + htResponse[“L_LONGMESSAGE0”].ToString();
                    string strErrcode = “Error code: ” + htResponse[“L_ERRORCODE0”].ToString();
            

                }
            }
            catch (Exception ex)
            {
                // do something to catch the error, like write to a log file.
                // Response.Write(“error processing”);
                //  Response.End();
             
            }

Advertisements