<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Untitled Page</title> </head> <body> <!--form action for live transaction https://www.paypal.com/cgi-bin/webscr--> <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="form1" name="form1"> <input type="hidden" name="cmd" value="_xclick"/> <input type="hidden" name="business" value="dharmendr90-facilitator@gmail.com"/><!--Paypal or sandbox Merchant account --> <input type="hidden" name="item_name" value="Books"/> <input type="hidden" name="uid" value="<%=Session["uid"] %>" /> <input type="hidden" name="custom" value="<%=Session["Email"]%>"/><!--Custom Field for payer email --> <%--<input type="hidden" name="Email" value="dharmendr90@gmail.com"/>--%> <input type="hidden" name="item_number" value="1"/> <input type="hidden" name="amount" value="<%=Session["Amount"]%>"/> <input type="hidden" name="return" value="http://www.test.svpindore.com/Success.aspx"/><!--this page will be your redirection page --> <input type="hidden" name="cancel_return" value="http://www.test.svpindore.com/cancel.html"/> <input type="hidden" name="currency_code" value="USD"/> <input type="hidden" name="notify_url" value="http://www.test.svpindore.com/UpdatePayment.aspx"/><!--this should be your domain web page where you going to receive all your transaction variables --> </form> <script type="text/jscript"> document.form1.submit(); </script> </body> </html>
string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr"; // string strLive = "https://www.paypal.com/cgi-bin/webscr"; 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; string txnid = Server.HtmlEncode(Request.Form["txn_id"]); string receiv_email = Server.HtmlEncode(Request.Form["receiver_email"]); string business = Server.HtmlEncode(Request.Form["business"]); string payer_email = Server.HtmlEncode(Request.Form["payer_email"]); string tnx_type = Server.HtmlEncode(Request.Form["txn_Type"]); string payment_type = Server.HtmlEncode(Request.Form["payment_type"]); string payment_stat = Server.HtmlEncode(Request.Form["payment_status"]); string custom = Server.HtmlEncode(Request.Form["custom"]); string uid = Server.HtmlEncode(Request.Form["uid"]); using (SqlConnection sc = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString)) { string data = txnid + " " + receiv_email + " " + business + " " + payer_email + " " + tnx_type + " " + payment_type + " " + payment_stat + " " + custom + " "; sc.Open(); SqlCommand cmd = new SqlCommand("Insert into PaymentData(data)Values('" + data + "')", sc); cmd.ExecuteNonQuery(); } 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") { //UPDATE YOUR DATABASE using (SqlConnection sc = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString)) { sc.Open(); SqlCommand cmd = new SqlCommand("Update Payment set transactionid='" + txnid + "',Status='" + payment_stat + "' where unicode='" + uid + "'", sc); cmd.ExecuteNonQuery(); } } else if (strResponse == "INVALID") { //UPDATE YOUR DATABASE using (SqlConnection sc = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString)) { sc.Open(); SqlCommand cmd = new SqlCommand("Update Payment set transactionid='" + txnid + "',Status='" + payment_stat + "' where unicode='" + uid + "'", sc); cmd.ExecuteNonQuery(); } } else { using (SqlConnection sc = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString)) { sc.Open(); SqlCommand cmd = new SqlCommand("Update Payment set transactionid='" + txnid + "',Status='" + payment_stat + "' where unicode='" + uid + "'", sc); cmd.ExecuteNonQuery(); } } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)