将PayPal与基于WebMatrix的网站集成(Razor/C#)

将PayPal与基于WebMatrix的网站集成(Razor/C#),c#,asp.net,razor,paypal,paypal-ipn,C#,Asp.net,Razor,Paypal,Paypal Ipn,我花了无数个小时阅读PayPal网站上的文档,以及他们的x.com网站上的文档,并在网上搜索这些文档,但不幸的是,我需要一些帮助 我在我的网站上提供了一项服务,我所要做的就是把客户送到paypal网站(我可以做到),让他们付款(他们可以做到),然后让他们在付款被批准/支付后重定向回我的网站(这就是发生的事),但这一切都停止了 我已经尝试了很多教程和示例,在这里变得非常困难。我需要能够在我的网站上做简单的检查(IPN的事情)。这样我就知道是否有人在paypal支付了服务费用,这样我就知道是否应该在

我花了无数个小时阅读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>
“/”应用程序中出现服务器错误。 -------------------------------------------------------------------------------- 运行时错误 描述:服务器上发生应用程序错误。此应用程序的当前自定义错误设置阻止远程查看应用程序错误的详细信息(出于安全原因)。但是,本地服务器上运行的浏览器可以查看它。 详细信息:要在远程计算机上查看此特定错误消息的详细信息,请在位于当前web应用程序根目录中的“web.config”配置文件中创建一个标记。然后,该标记的“mode”属性应设置为“Off”。 注意:通过修改应用程序配置标记的“defaultRedirect”属性以指向自定义错误页URL,可以将当前看到的错误页替换为自定义错误页。 注意:关闭CustomErrors后,我仍然收到此消息

更新#2 当我尝试输出字符串ipnPost=strequest的结果时;它显示一条消息“状态无效-form_charset=UTF8”

就这么说。我不知道为什么

最新资料- 我现在使用以下代码收到以下错误:

“/”应用程序中出现服务器错误。 必须先将ContentLength字节写入请求流,然后才能执行此操作 正在调用[Begin]GetResponse。描述:未处理的异常 在执行当前web请求期间发生。请 查看堆栈跟踪以了解有关错误和位置的更多信息 它起源于代码

异常详细信息:System.Net.ProtocolViolationException:您必须 在调用前将ContentLength字节写入请求流 [开始]获取响应

源错误:

第34行:第35行:第36行:StreamReader streamIn=新建 StreamReader(req.GetResponse().GetResponseStream());第37行:
字符串strResponse=streamIn.ReadToEnd();streamOut.Close();第38行: streamIn.Close()

源文件: c:\hostingspace\sss\sss.com\wwwroot\Checkout\Status.cshtml 电话号码:36

堆栈跟踪:

[ProtocolViolationException:必须将ContentLength字节写入 在调用[Begin]GetResponse之前请求流。]
System.Net.HttpWebRequest.GetResponse()+7769822
ASP.\u页面\u签出\u状态\u cshtml.Execute()在中 c:\hostingspace\ssss\ssss.com\wwwroot\Checkout\Status.cshtml:36 System.Web.WebPages.WebPageBase.ExecutePageHierarchy()+280
System.Web.WebPages.WebPages.ExecutePageHierarchy()+369
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext、TextWriter编写器、WebPageUnderingBase起始页)+157
System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContext 上下文)+294

--------------------------------------------------------------------------------版本信息:Microsoft.NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.1

@使用System.Collections.Generic
@使用System.Text
@使用System.Web
@使用System.Web.UI
@使用System.Web.UI.HTMLControl
@使用System.Web.UI.WebControl
@使用System.ComponentModel
@{
Layout=“~/\u siteloayout.cshtml”;
Page.Title=“签出| SSS”;
字符串姿势=”https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest req=(HttpWebRequest)WebRequest.Create(postrl);
//设置请求返回的值
请求方法=“POST”;
req.ContentType=“应用程序/x-www-form-urlencoded”;
byte[]param=Request.BinaryRead(HttpContext.Current.Request.ContentLength);
string strequest=System.Text.Encoding.UTF8.GetString(param);
字符串ipnPost=strRequest;
strRequest+=“&cmd=_notify-validate”;
请求内容长度=请求长度;
//代理
//WebProxy proxy=新的WebProxy(新的Uri(“http://url:port#"));
//请求代理=代理;
//将请求发送到PayPal并获得响应
StreamWriter streamOut=新StreamWriter(req.GetRequestStream(),
System.Text.Encoding.UTF8);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn=新的StreamReader(req.GetResponse().GetResponseStream());
字符串strResponse=streamIn.ReadToEnd();
streamIn.Close();
/*/正在记录ipn消息…请确保您提供了write
//执行此代码的进程权限
字符串logPathDir=ResolveUrl(“消息”);
string logPath=string.Format(“{0}\\{1}.txt”,
Server.MapPath(logPathDir),DateTime
@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>
}