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();
}
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();
}
How we can pass a amount in this ...and if m using sandbox account for testing purpose than how can i add credit card detail here?
ReplyDeleteHey...this post is useful to me.....Thanks ..
ReplyDeletebut I want to know how to add amount with this account details for payment?????
i am facing problem of this errror as given below,
ReplyDeleteTIMESTAMP=2014%2d02%2d15T06%3a22%3a06Z&CORRELATIONID=efa21eeb94c9c&ACK=Failure&VERSION=56%2e0&BUILD=9720069&L_ERRORCODE0=10002&L_SHORTMESSAGE0=Security%20error&L_LONGMESSAGE0=Security%20header%20is%20not%20valid&L_SEVERITYCODE0=Error
please let me know how to recover this problem ? as i have already done with API Credential m, and sandbox testing account but facing problem in above error!!! Can u send me sample code in mvc .net or simple asp.net ??? it's very argent for me . THnaks & Regards, Aneaknt