【问题标题】:How to use the paypal IPN如何使用贝宝 IPN
【发布时间】:2013-02-01 08:53:14
【问题描述】:

我正在尝试创建一个页面:

  • 1.用户点击BUY按钮
  • 2.用户被重定向到paypal页面,需要登录并付款。

付款后,他将被重定向到另一个页面:

  • 1.在页面加载中,我会检查是否支付成功。

我已经这样做了,但它似乎不起作用。 我做了什么?

  • 1.从paypal账户启用IPN,并将url设置为asp页面。

    2.将这两个文件(php/asp.net)托管在一个网站上

  • 3.已测试,但标签文本未更改为“完成,已付款”,这意味着他无法处理付款。

购买产品的php页面:

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">

    <input type="hidden" name="cmd" value="_xclick" />
    <input type="hidden" name="business" value="seller@domain.com" />

    <input type="hidden" name="item_name" value="Happiness" />
    <input type="hidden" name="amount" value="6.52" /> 
    <input type="submit" value="Buy!" />

</form>

asp.net 页面:

 protected void Page_Load(object sender, EventArgs e)
        {
                string strSandbox = "https://www.sandbox.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;


                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")
                {
                    Label1.Text = "Done,payment was made.";
                }
                else if (strResponse == "INVALID")
                {
                    //whatever
                }
                else
                {
                    //whatever
                }
}

我能做什么?

【问题讨论】:

  • 什么是“不工作”?
  • 验证strResponse时不执行代码
  • 我不知道您在那里等待执行什么,因为这是来自 pp 的自动调用,而不是您调用的页面 - 如果您理解我的意思。如果是验证,这并不意味着付款,您需要检查更多的参数。

标签: c# asp.net paypal paypal-ipn paypal-sandbox


【解决方案1】:

IPN 交易是分批发送的,通常是在几分钟后发送。您不应该设计用户看到的页面来反映 IPN 消息的状态。在我的系统中,我只是告诉用户他们的购买已经完成,并且会在 PayPal 建议清空资金时完成,我会通过电子邮件通知他们。

【讨论】:

    猜你喜欢
    • 2015-06-16
    • 2016-05-09
    • 2015-06-09
    • 2023-03-11
    • 2014-04-24
    • 2012-08-19
    • 2012-08-15
    • 2014-08-25
    • 2013-07-10
    相关资源
    最近更新 更多