【发布时间】:2012-02-21 06:38:00
【问题描述】:
首先,让我说我在这方面已经太久了,我认为我坚持的部分应该是最简单的任务。然而,我无法做到。我真的很困惑。
我正在将 PayPal 集成到我的网站中。我以前开发过很多网站,但这是我第一次做支付。
我有以下代码(未修改 - 我复制并粘贴了 [不要惊慌!我这样做是有原因的]):
// ASP .NET C#
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Web;
public partial class csIPNexample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Post back to either sandbox or live
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;
//for proxy
//WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
//req.Proxy = proxy;
//Send the request to PayPal and get the response
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")
{
//check the payment_status is Completed
//check that txn_id has not been previously processed
//check that receiver_email is your Primary PayPal email
//check that payment_amount/payment_currency are correct
//process payment
}
else if (strResponse == "INVALID")
{
//log for manual investigation
}
else
{
//log response/ipn data for manual investigation
}
}
}
现在,我知道这段代码的含义,也知道它的作用。我唯一遇到困难的部分是这部分:
if (strResponse == "VERIFIED")
{
//check the payment_status is Completed
//check that txn_id has not been previously processed
//check that receiver_email is your Primary PayPal email
//check that payment_amount/payment_currency are correct
//process payment
}
else if (strResponse == "INVALID")
{
//log for manual investigation
}
else
{
//log response/ipn data for manual investigation
}
哪个,你现在可能在笑。没关系:
//check the payment_status is Completed
我认为这行应该这样写:
@{
if(Request.QueryString["payment_status"] == "Completed")
{
// Payment status is completed.
}
}
而且,我认为我应该对其余的注释行做几乎相同的事情(获取 Request["etc"] 变量并比较它们的值),并将数据与数据库中相关的数据进行匹配给用户。
有人可以帮帮我吗?我真的到处找遍了,似乎我能在网上找到的所有代码示例都没有向您展示这部分的代码。
非常感谢您的帮助。
谢谢
【问题讨论】:
-
如果您正在寻找 ASP.NET Web 表单中 PayPal 支付网关集成的最新解决方案,请查看演示:techtolia.com/PayPal
标签: c# asp.net razor paypal integration