简体   繁体   English

如何使用贝宝IPN

[英]How to use the paypal IPN

I'm trying to create a page where : 我正在尝试创建一个页面,其中:

  • 1.The user clicks a button called BUY 1,用户点击一个叫买的按钮
  • 2.The user is redirected to paypal page where he needs to log in and pay. 2.用户被重定向到他需要登录并付款的贝宝页面。

After he paid , he will be redirected to another page where: 付款后,他将被重定向到另一个页面,其中:

  • 1.in the page load , I will check if the payment was successfully made. 1.在页面加载中,我将检查付款是否成功。

I've done this but it seems is not working. 我已经做到了,但是似乎没有用。 What have I done? 我做了什么?

  • 1.Enabled IPN from paypal account and the url was set to the asp page. 1.从paypal帐户启用IPN,URL设置为asp页面。

    2.Hosted the two files ( php/asp.net ) on a website 2.将两个文件(php / asp.net)托管在网站上

  • 3.Tested but the label text is not changing to "Done,payment made" which means he couldn't process the payment. 3.经过测试,但标签文本未更改为“完成,已付款”,这表示他无法处理付款。

The php page for buying the product: 用于购买产品的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>

The asp.net page: 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
                }
}

What can I do? 我能做什么?

IPN transactions are sent in batches, and often many minutes later. IPN事务是成批发送的,通常是几分钟之后。 You shouldn't be designing the page the user sees to reflect the status of IPN messages. 您不应该设计用户看到的反映IPN消息状态的页面。 In my system I just tell the users their purchase is complete and will be fulfilled when PayPal advises clearance of the funds, and I advise them of that by email. 在我的系统中,我只是告诉用户他们的购买已经完成,并且在PayPal建议清除资金时会完成,我会通过电子邮件通知他们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM