本文介绍了如何从Asp.Net中的Paypal Notify_Url获取自定义响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我发送付款请求的页面
this the page through which i am sending a request for payment
<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="[email protected]"/><!--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="[email protected]"/>--%>
<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>
这是我在更新数据库中的值的通知页面我没有得到自定义响应Request.form [uid]和Request.form [custom]除了那些客户价值我得到所有价值的原因?
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 ?
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();
}
}
}
}
}
推荐答案
这篇关于如何从Asp.Net中的Paypal Notify_Url获取自定义响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!