Thursday, January 1, 2009

Using PayPal Pro With ASP.Net application

Hi Everybody..
"How to use PayPal Pro Method in Asp.Net 2.0 web Application", this is topic for today which, I want to add as my latest post .I hope all of you are well aware of this.Yet I am adding this for quick reference.
You can also take an idea from HERE .
You have to add the following code in your page and modified it as per your need...


protected void Page_Load(object sender, EventArgs e)
{
// Do Your Other Task Here...
UpdatePaymentStatus();
}
protected void UpdatePaymentStatus()
{
#region Paypal Return
try
{
string status = GetSuccessStatus();
if (status != null && status != string.Empty)
{
if (status.Contains("success"))
{
// Do Your DatBase related things ag save the transaction details in DB
// for eg: userID ,Unit Price,And Total Amount or anyother thing as needed
}
if (status.Contains("failed"))
{
// do as per your Logic
}
}
}
catch (Exception Ex)
{
Session["errorMessage"] = Ex.Message.ToString();
//Response.Redirect("index.aspx");
}
#endregion
}
protected void ImgPayMent_Click(object sender, ImageClickEventArgs e)
{
amount = Convert.ToDouble(lblPrice.Text);
string redirect = "";

//redirect += "https://www.paypal.com/cgi-bin/webscr";
redirect += "https://www.sandbox.paypal.com/cgi-bin/webscr";
redirect += "?cmd=_xclick";
redirect += "&business=books._1235082065_biz@gmail.com ";
//Where abc@youdomain.com is Merchant account ID
redirect += "&item_name=" + "My Testing Purpose";
redirect += "&item_number=1";
redirect += "&amount=" + String.Format("{0:0.00} ", amount);// This is amount Double Type
redirect += "&currency_code=USD";
redirect += "&no_shipping=1";
redirect += "&no_note=1";
redirect += "&return=http://HomeUrlOfSite/Purchase.aspx/success/";
redirect += "&cancel_return=http://HomeUrlOfSite/Purchase.aspx/failed/"
Response.Redirect(redirect);
}
protected string GetSuccessStatus()
{
if (Request.PathInfo.Length == 0)
return "";
else if (Request.PathInfo.Contains("success"))
return "success";
else if (Request.PathInfo.Contains("failed"))
return "failed";
return "";
}
}

Thanks:...
Sanjeev Kumar
HelpOnDesk Team

No comments: