asp.net - 为什么我使用 c# 在 asp.net 中收到来自 Paypal 的无效响应?

标签 asp.net paypal paypal-sandbox

我有一个用于试用的 paypal 沙箱帐户 一个aspx页面:sampleprocess.aspx

在 Merchant A/c 中,页面被重定向到 http://www.Hostsite.com/member/samplepaypal.aspx 付款完成后。

在 samplepaypal.aspx.cs 页面加载:

protected void Page_Load(object sender, EventArgs e)
    {
        //string tx = Request.QueryString["tx"];
        //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")
        {
            lblmsg.Text = "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")
        {
            lblmsg.Text = "Not Verified";
            //log for manual investigation
        }
        else
        {
            lblmsg.Text = "IPN Logged";
            //log response/ipn data for manual investigation
        }
    }

这里我得到结果“无效”!怎么了请纠正错误。 发回http://www.Hostsite.com/member/samplepaypal.aspx后 Paypal 页面 它显示:

http://111.111.111.111/member/samplepaypal.aspx?tx=8L903541KW5338647&st=Pending&amt=100.00&cc=USD&**cm=&item_number=&**sig=QRmNHFf5%2fAH3io9Tn2kj%2fuicu3gpAuMew701OvazfkCdN3jSR5tmFoX3OUPbQlZGoj2PY7vI%2fP1dH84g1CEzSG9NhjnLbjuAFFHyENVsBjKb1dVvK1nZe3FJfElZt11qPfggMOPu8%2bUhDwHekJvNAcXkjLQV01vAjN1y%2fZs1rJw%3d

这些是什么 cm & item_number 都是空白的!如何获得“有效”响应。

感谢帮助...!

最佳答案

使用回传进行验证:

如果您不能使用共享 key 进行通知验证,您可以使用回发到 PayPal, 反而。您的回发必须包含与您收到的完全相同的变量和值 PayPal 发布到您的服务器的 IPN,它们必须按相同的顺序排列。

构建你的回传

使用这些指南构建您对 PayPal 的回发:

  1. 您的回传必须发送至https://www.paypal.com/cgi-bin/webscr . 注意:您可以在没有 SSL 的情况下实现 IPN,包括用于验证的回发,但是 PayPal 建议不要这样做。

  2. 您的回发必须包含值为 _notify-validate 的变量 cmd: cmd=_notify-validate

  3. 您的回发必须包含与您在 来自 PayPal 的 IPN,它们必须在同一顺序。

处理对您的回发的 PayPal 响应 PayPal 在响应正文中使用一个词来响应您的回发:已验证 或无效。 当您收到 VERIFIED 回发响应时,对中的数据执行以下检查 IPN:

  1. 检查 payment_status 是否已完成。

  2. 如果 payment_status 是 Completed,检查 txn_id 与之前的 PayPal 您处理的交易以确保它不是重复的。

  3. 检查 receiver_email 是否是在您的 PayPal 帐户中注册的电子邮件地址。

  4. 检查 mc_gross 中携带的价格和 mc_currency 中携带的货币是否正确 正确的项目,携带在 item_name 或 item_number 中。完成上述检查后,通知验证就完成了。您可以使用提供的信息更新您的数据库,并且可以启动其他适当的自动化 后端处理。

关于asp.net - 为什么我使用 c# 在 asp.net 中收到来自 Paypal 的无效响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12329891/

相关文章:

c# - 在 asp.net 中增加复选框的大小?

android - Paypal 与 Android 集成

PayPal Web Payments Pro Hosted - 信用卡付款确认页面

javascript - 检索和存储 Paypal 订阅

paypal - 使用 IPN 检测并行支付的所有部分

asp.net - 将特定文件夹映射到 web.config 中的 HttpHandler

ASP.NET/ActiveX/Silverlight 屏幕捕获

c# - .Net 应用程序性能优化器

Paypal 沙盒错误 : Cookies are blocked

ssl - Parse.Cloud.httpRequest 返回 "Request failed; 35-111 SSL connect error; Connection refused"