Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 637
  • Last Modified:

PayPal Confirm Payment

Hi

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

                  <form action="https://www.paypal.com/cgi-bin/webscr" 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="myemail@address.com">
    <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="http://www.mywebsite.com/return.php">
    <input type="hidden" name="cancel_return" value="http://www.mywebsite.com/cancel_return.php">
    <input type="hidden" name="notify_url" value="http://www.mywebsite.com/return.php">
    <input type="hidden" name="image_url" value="http://www.mywebsite.com/images/paypal-logo.jpg">
    <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">

              </div>
            </form>

Many thanks

Matt
0
Matt_Wilkes
Asked:
Matt_Wilkes
  • 2
1 Solution
 
Ray PaseurCommented:
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:
https://www.paypal.com/ipn/

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.
0
 
Scott MadeiraCommented:
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.
0
 
Ray PaseurCommented:
@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:
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/certification_overview
https://www.x.com/developers/paypal/documentation-tools/training
https://www.x.com/community/
0
 
Matt_WilkesAuthor Commented:
Many thanks
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now