Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this the page through which i am sending a request for payment

C#
<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>


This is the notification page where i am updating a values in database but i am not getting custom response Request.form["uid"] and Request.form["custom"] apart from those custome values i am getting all values why ?


C#
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();


                }


            }
        }

    }
}
Posted
Updated 8-May-14 1:36am
v3
Comments
ZurdoDev 8-May-14 7:39am    
You should first ask paypal. It's much more likely you'll get a faster and more accurate response from them.
duke90 8-May-14 7:43am    
thanks.I itself got an answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900