Thursday 8 November 2012

Payplal Integration in ASP.net

Do you want to intergrate PayPal in your shopping cart or web site? Here some source code samples to help you get started.



DataView dvOrderItems = oProducts.GetOrderByID(OrderID);
ID = dvOrderItems[0]["OrderID"].ToString();
string Payment = dvOrderItems[0]["SubTotal"].ToString();
string Orderstatus = dvOrderItems[0]["Shipping"].ToString();
amount = Convert.ToDecimal(Payment).ToString("N2").Replace(',', '.');
shipping = Convert.ToDecimal(Orderstatus).ToString("N2").Replace(',', '.');
 



string serverUrl = (config.Store.SandboxMode?
               "https://www.sandbox.paypal.com/us/cgi-bin/webscr" :
               "https://www.paypal.com/us/cgi-bin/webscr");
           
string baseUrl = HttpContext.Current.Request.Url.AbsoluteUri.Replace(
HttpContext.Current.Request.Url.PathAndQuery, "") +     HttpContext.Current.Request.ApplicationPath;
if (!baseUrl.EndsWith("/"))
    baseUrl += "/";
           
string notifyUrl = HttpUtility.UrlEncode(baseUrl + "PayPal/Notify.aspx");
string returnUrl = HttpUtility.UrlEncode(baseUrl + "PayPal/OrderCompleted.aspx?ID=" + ID);
string cancelUrl = HttpUtility.UrlEncode(baseUrl + "PayPal/OrderCancelled.aspx");
string business = HttpUtility.UrlEncode(config.Store.BusinessEmail);
string itemName = HttpUtility.UrlEncode("Order #" + ID);

StringBuilder url = new StringBuilder();
url.AppendFormat(
               "{0}?cmd=_xclick&upload=1&rm=2&no_shipping=1&no_note=1&currency_code={1}&business={2}&item_number={3}&custom={3}&item_name={4}&amount={5}&shipping={6}&notify_url={7}&return={8}&cancel_return={9}",
               serverUrl,config.Store.CurrencyCode, business, ID, itemName,
               amount, shipping, notifyUrl, returnUrl, cancelUrl);
         
return url.ToString();

then give your messsage or value in 

Notify.aspx


OrderCompleted.aspx 
OrderCancelled.aspx

No comments:

Post a Comment