Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用paypal IPN_C#_Asp.net_Paypal_Paypal Ipn_Paypal Sandbox - Fatal编程技术网

C# 如何使用paypal IPN

C# 如何使用paypal IPN,c#,asp.net,paypal,paypal-ipn,paypal-sandbox,C#,Asp.net,Paypal,Paypal Ipn,Paypal Sandbox,我正在尝试创建一个页面,其中: 1.用户单击一个名为“购买”的按钮 2.用户被重定向到paypal页面,需要登录并付款 付款后,他将被重定向到另一个页面,其中: 1.在页面加载中,我将检查付款是否成功 我已经这样做了,但似乎不起作用。 我做了什么 1.从paypal帐户启用IPN,url设置为asp页面 2.在一个网站上托管了两个文件(php/asp.net) 3.已测试,但标签文本未更改为“已完成,已付款”,这意味着他无法处理付款 购买产品的php页面: <form acti

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

  • 1.用户单击一个名为“购买”的按钮
  • 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>

我能做些什么?

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

什么是“不工作”?验证响应时不执行代码我不知道您在那里等待执行什么,因为这是来自pp的自动呼叫,如果你明白我的意思的话,这不是你所说的页面。如果被验证,这并不意味着支付了,你需要检查更多的参数。
 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
                }
}