我花了无数个小时阅读PayPal网站上的文档,也浏览了他们的x.com网站,并在网上搜索了这个,但不幸的是,我需要一些帮助。
我在我的网站上提供了一项服务,而我所要做的就是将客户发送到paypal网站(我可以这样做),并让他们支付(他们可以做的),以及然后,一旦付款被批准/制作(发生了什么),就将它们重定向回我的网站,但这就是一切都停止的地方......
我已经尝试了很多教程和样本,而且这里变得非常困难。我需要能够对我的网站进行简单的检查(IPN事情)。因此,我知道某人是否已通过PayPal支付服务费用,因此我知道是否应该在我的网站上为该特定客户激活该服务。
我知道有一个PayPal助手,但在这种情况下这对我没有帮助,因为它没有处理IPN的东西。
注意:此服务不是订阅服务,只是一次性付款。
我真的很感谢你对此的帮助,我真的很困难,不知道下一步该做什么。
所以我测试了@Bobby在答案中提供的脚本,我收到了一个错误:
Server Error in '/' Application.
--------------------------------------------------------------------------------
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
注意:关闭CustomErrors后,我仍会收到此消息。
当我尝试输出string ipnPost = strRequest的结果时;它会显示一条消息“状态无效 - form_charset = UTF8”
就是这样。我不知道为什么..
我现在使用以下代码收到以下错误:
2>'/'应用程序中的服务器错误。您必须先将ContentLength字节写入请求流 调用[Begin] GetResponse。描述:未处理的异常 在执行当前Web请求期间发生。请 查看堆栈跟踪以获取有关错误和位置的更多信息 它起源于代码。
异常详细信息:System.Net.ProtocolViolationException:您必须 在调用之前将ContentLength字节写入请求流 [开始]的GetResponse。
来源错误:
第34行:第35行:第36行:StreamReader streamIn = new 的StreamReader(req.GetResponse()的GetResponseStream());第37行:
string strResponse = streamIn.ReadToEnd(); streamOut.Close();第38行: streamIn.Close();源文件: C:\ HostingSpaces \ sssssssss \ sssssss.com \ wwwroot的\结帐\ Status.cshtml 行:36
堆栈追踪:
[ProtocolViolationException:您必须将ContentLength字节写入 在调用[Begin] GetResponse之前请求流。]
System.Net.HttpWebRequest.GetResponse()+7769822
ASP._Page_Checkout_Status_cshtml.Execute()in C:\ HostingSpaces \ SSSSSS \ ssssssss.com \ wwwroot的\结帐\ Status.cshtml:36 System.Web.WebPages.WebPageBase.ExecutePageHierarchy()+280
System.Web.WebPages.WebPage.ExecutePageHierarchy()+ 369
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext,TextWriter writer,WebPageRenderingBase startPage)+157
System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContext的 上下文)+294----------------------------------------------- ---------------------------------版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.1
@using System.Collections.Generic
@using System.Text
@using System.Web
@using System.Web.UI
@using System.Web.UI.HtmlControls
@using System.Web.UI.WebControls
@using System.ComponentModel
@{
Layout = "~/_SiteLayout.cshtml";
Page.Title = "Checkout | sssss";
string postUrl = "https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(postUrl);
//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 = System.Text.Encoding.UTF8.GetString(param);
string ipnPost = strRequest;
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.UTF8);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
/*/ logging ipn messages... be sure that you give write
// permission to process executing this code
string logPathDir = ResolveUrl("Messages");
string logPath = string.Format("{0}\\{1}.txt",
Server.MapPath(logPathDir), DateTime.Now.Ticks);
File.WriteAllText(logPath, ipnPost);
/*/
}
@if (strResponse == "VERIFIED")
{
/*---------------- WILL DO OTHER CHECKS LATER ------------------*/
//check the payment_status is Completed
<p>status is verified</p>
//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
<p>status is invalid.</p>
<p>@ipnPost</p>
}
else
{
//log response/ipn data for manual investigation
<p>status is invalid.</p>
<p>@ipnPost</p>
}