1. For Test
Thank you for reading this post, don't forget to subscribe!First register it and login before payment.
https://developer.paypal.com/
2. Initialize Item for payment
//Query String of Item Detail to send item description to paypal
private string GetItemDtetail()
{
string strPayPalUrlType =”https://www.sandbox.paypal.com/cgi-bin/webscr”;// For Test
string strPayPalUrlType =”https://www.sandbox.paypal.com/cgi-bin/webscr”;// For Live
string cmd = “_xclick”;
string redirect = “”;
redirect += strPayPalUrlType;
redirect += “?cmd=” + cmd;
redirect += “&business=” + Bussiness Email;
redirect += “&item_name=” + Product Name;
redirect += “&item_number=” + Product Id;
redirect += “&amount=” + Price;
redirect += “&no_shipping=” + “2”;
redirect += “&no_note=” + “1”;
redirect += “¤cy_code=” + Currency;
redirect += “&lc=” + Buyer Country;
redirect += “&bn=” + “PP-BuyNowBF”;
//After successfull completition of payment
redirect += “&return=” + Success Url;
//Return to page before payment
redirect += “&return=” + Return url;
//Return to page before payment
redirect += “&cancel_return=” + Cancel Url;
redirect += “&rm=” + “2”;
return redirect;
}
3. Click button for payment
protected void Payment_Click(object sender, EventArgs e)
{
string strRedirectURL = GetItemDtetail();
Response.Redirect(strRedirectURL);
}
4. Confirmation on page load
//Get the payment message on success page load
protected void MessageConfirmation()
{
//Post back to either sandbox or live
string strSandbox = “https://www.sandbox.paypal.com/cgi-bin/webscr”;// For Test
//string strLive = “https://www.paypal.com/cgi-bin/webscr”; //For Live
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
//Set values for the request back
req.Method = “POST”;
req.ContentType = “application/x-www-form-urlencoded”;
byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
strRequest += “&cmd=_notify-validate”;
req.ContentLength = strRequest.Length;
//Send the request to PayPal and get the response
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
if (strResponse == “VERIFIED”)
{
Successfully Payment.
}
else if (strResponse == “INVALID”)
{
Fail to payment.
}