简体   繁体   中英

How to use the paypal IPN

I'm trying to create a page where :

  • 1.The user clicks a button called BUY
  • 2.The user is redirected to paypal page where he needs to log in and pay.

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.

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.

    2.Hosted the two files ( php/asp.net ) on a website

  • 3.Tested but the label text is not changing to "Done,payment made" which means he couldn't process the payment.

The php page for buying the product:

<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:

 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. You shouldn't be designing the page the user sees to reflect the status of IPN messages. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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