PayPal Confirm Payment

Posted on 2012-08-13
Last Modified: 2016-03-24

Has anyone got some example code that would check if this PayPal session has had a successful payment?

                  <form action="" method="post" name="form2" target="paypal">
              <div align="left">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="bn" value="wa_dw_3.0.4">
    <input type="hidden" name="business" value="">
    <input type="hidden" name="item_name" value="Item Name">
    <input type="hidden" name="item_number" value="Item Ref #<?php print $s_id;?>">
      <input type="hidden" name="custom" value="<?php print $s_id;?>">
    <input type="hidden" name="amount" value="99.00">
    <input type="hidden" name="currency_code" value="GBP">
    <input type="hidden" name="return" value="">
    <input type="hidden" name="cancel_return" value="">
    <input type="hidden" name="notify_url" value="">
    <input type="hidden" name="image_url" value="">
    <input type="hidden" name="undefined_quantity" value="0">
    <input type="hidden" name="no_shipping" value="0">

    <input type="hidden" name="no_note" value="0">
  <INPUT TYPE="image" SRC="images/pay-now.png" HEIGHT="50" WIDTH="562" BORDER="0" ALT="Apply Now">


Many thanks

Question by:Matt_Wilkes
    LVL 107

    Expert Comment

    by:Ray Paseur
    The thing you need is called a PayPal Instant Payment Notification script.  Also called the IPN.  It is an asynchronous script that can receive a POST-method request from PayPal.  You can learn more about the IPN here:

    As far as I know you cannot definitively confirm receipt of the payment in your web site without using the IPN.  There are "return" and "cancel_return" pages, but these are not 100% reliable, since transactions can get reversed for a variety of reasons.
    LVL 14

    Accepted Solution

    If you want real time notification that the payment was accepted then IPN is probably not the answer.  It is not 100% guaranteed to provide a response that quickly.  There are times when IPN messages will be sent seconds and possibly minutes after the transaction has completed.

    If you are trying to do something like instant digital downloads then this may be a problem.  If you are taking money and then shipping a product or are sending a download link after payment has been confirmed then IPN will work for you.

    What you need to do on your end is save all of the relevant product and form information in a database on your site.  Then submit the form to PayPal.  Your IPN script will get the notification back from PayPal and will need to update your database with the status of the payment.

    The IPN message is an asynchronous transaction with PayPal from the form you submitted.

    For sample IPN code you can google IPN paypal sample.  PayPal has their sample and there are others out there as well that have a few more details filled in.
    LVL 107

    Expert Comment

    by:Ray Paseur
    @smadeira: There are also times when the IPN will be called multiple times, such as when a client pays by eCheck and the check clears, or when the client pays by credit card and the charge is denied or reversed, or when the client pays via PayPal account and requests a refund. In short, the IPN is the "truth" from PayPal, but the truth can take on a lot of meanings at different times in the life of the transaction!

    In my experience, these non-purchase calls are rare and extreme outliers.  I have used the IPN to do a bill-of-materials explosion and trigger factory processes affecting inventory and shipping.  The question of timeliness has never been much of an issue, and the notifications appear to arrive in near real time, at most a second or two after the payment is triggered.  I use a data base as you describe so I have the information to track the factory activity on the order.  Since 2006 I have only rarely gotten a non-purchase call to the IPN.  However one of the calls was a reversal of a $5,000 payment.  So you have to be aware of these things and write your programming accordingly.

    It's not easy to handle money in a secure and safe way, and there are a lot of bad guys on the internet who would love to steal from you.  In the case of novice programmers writing an interface to ecommerce solutions, I would say, "Just don't!" and recommend hiring a PayPal Developer instead.

    If you want to get certified yourself, start with these links:

    Author Comment

    Many thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now