Next: PHP Authorize.net AIM Interfacing Class

PHP Paypal IPN Integration Class

April 19th, 2005

This free PHP script provides a simple method to interface with paypal and the paypal Instant Payment Notification (IPN) system. It is not a complete system but a single PHP class allowing the PHP developer more control. Included in the zip file is a demonstration PHP script called paypal.php which shows the basic usage of the class.


This class handles the submission of an order to paypal as well as the processing an Instant Payment Notification (IPN). Including the demonstration file, the entire "paypal system" consists of just 2 PHP scripts. Once is the class and one implements the class.

Download:
Download Paypal IPN Script paypal-1.3.0.zip

Do you like this code? Rate This Script at Hot Scripts.

If you enjoy this free PHP script and want to show your support, you can throw me a couple of bucks using paypal. Any donation, even just a buck, is always appreciated.

Version History

  • v1.3.0 [10.10.2005] - Fixed it so that single quotes are handled the right way rather than simple stripping them. This was needed because the user could still put in quotes.
  • v1.2.1 [06.05.2005] - Fixed typo from previous fix :)
  • v1.2.0 [05.31.2005] - Added the optional ability to remove all quotes from the paypal posts. The IPN will come back invalid sometimes when quotes are used in certain fields.
  • v1.1.0 [05.15.2005] - Revised the form output in the submit_paypal_post method to allow non-javascript capable browsers to provide a means of manual form submission.
  • v1.0.0 [04.16.2005] - Initial Version

Resources

Related Books




Categories
Web Development PHP

Related Posts


Technorati Tags

151 Responses to “PHP Paypal IPN Integration Class”

RSS Subscription Comments RSS Feed

  1. Andrew Says:

    Paypal class was excellent.
    If you put the payment bits back on your site.......

  2. Dale Hay Says:

    For some reason it's not letting me use other / custom fields. Any ideas?

  3. Micah Says:

    It's not letting you use other custom fields? What fields are you adding? Do you mean other paypal fields as specified in the Website Payments Standard Integration Guide or your own variables which you are trying to pass through?

  4. Derek Gomez Says:

    I'm having trouble getting the values in a database in the case 'ipn' section.

    Here is what I tried so far:

    foreach ($p->ipn_data as $key => $value) { $$key == $value; }

    $qry="INSERT INTO paypal_table VALUES (0 , '$payer_id', '$payment_date', '$txn_id', '$first_name', '$last_name', '$payer_email', '$payer_status', '$payment_type', '$memo', '$item_name', '$item_number', $quantity, $mc_gross, '$mc_currency', '$address_name', '".nl2br($address_street)."', '$address_city', '$address_state', '$address_zip', '$address_country', '$address_status', '$payer_business_name', '$payment_status', '$pending_reason', '$reason_code', '$txn_type')";

    mysql_query($qry);

    Your help is greatly appreciated.

  5. Micah Says:

    Since the ipn data is stored in an array in the class, you're going to do something more along the lines of:
    For troubleshooting that code, you will need to log the errors. Try the debugging log that is provided with the class, or setup php.ini to log errors and check the error log.

  6. Derek Gomez Says:

    Thanks for getting back so quick Micah.
    Looks like you had a suggestion for coding but it's not in your message?
    along the lines of:....

    thanks again

  7. Micah Says:

    Yeah... I looked at your code again and didn't see the problem. You want to send me your file via email at micahcarrick.com and I'll see if anything jumps out at me?

  8. Micah Says:

    My thinking is that you have empty values due to scope. But I could be wrong. I would dump the value of $qry into a text file or the error log to see what it looks like--or check PHP error log for MySQL errors.

    Is *anything* getting into the database?

  9. Derek Gomez Says:

    There is not much that is different from your sample except instead of emailing the values I attempt the insert into the database. The emailing the values works and I get the values in the email.

    Here is the complete ipn section:

    if ($_GET['action'] == 'ipn')
    {// Paypal is calling page for IPN validation...

    // It's important to remember that paypal calling this script. There
    // is no output here. This is where you validate the IPN data and if it's
    // valid, update your database to signify that the user has payed. If
    // you try and use an echo or printf function here it's not going to do you
    // a bit of good. This is on the "backend". That is why, by default, the
    // class logs all IPN data to a text file.

    if ($p->validate_ipn())
    {

    // Payment has been recieved and IPN is verified. This is where you
    // update your database to activate or process the order, or setup
    // the database with the user's order details, email an administrator,
    // etc. You can access a slew of information via the ipn_data() array.

    // Check the paypal documentation for specifics on what information
    // is available in the IPN POST variables. Basically, all the POST vars
    // which paypal sends, which we send back for validation, are now stored
    // in the ipn_data() array.

    mysql_connect("localhost","ediblepr_dgomez","mozart123") or die("Unable to connect to database");
    mysql_select_db("ediblepr_paypal") or die("Unable to select database");

    foreach ($p->ipn_data as $key => $value) { $$key == $value; }

    $qry="INSERT INTO paypal_table VALUES (0 , '$payer_id', '$payment_date', '$txn_id', '$first_name', '$last_name', '$payer_email', '$payer_status', '$payment_type', '$memo', '$item_name', '$item_number', $quantity, $mc_gross, '$mc_currency', '$address_name', '".nl2br($address_street)."', '$address_city', '$address_state', '$address_zip', '$address_country', '$address_status', '$payer_business_name', '$payment_status', '$pending_reason', '$reason_code', '$txn_type')";

    mysql_query($qry);
    }
    }

  10. Vikas Says:

    Hi

    Ive written a Free digital downloads delivery script using your class. Any recommendations would be welcome.

    You can check it out here

    http://www.ngcoders.com/php/selling-digital-goods-with-paypal-ipn-and-php/

    Thanks for the class.

  11. Micah Says:

    Vikas: Although I haven't downloaded it, it look cool. It's free--which is great--and it is well explained on your blog. Kudos.

  12. Derek Gomez Says:

    I looked at the email I received and the fields don't match what I have for the table so that was my mistake. I'll update the table and SQL and see if that fixes the problem.

    thanks again

  13. Uros Says:

    Hi all, simple script... One question... How can currency be changed...???

  14. Micah Says:

    Look in the integration guide or online for a list of Paypal variables. Any of these can be set/overridden using the classes add_field() method. So, to use Canadian currency for example:

    $p->add_field('mc_currency', 'CAD');

  15. Gajendra Says:

    Micah, I have sent you a detailed mail about my problem. I am using your class with sandbox and getting txn_id as 0

    Could you please tell me what the problem is ???

  16. Micah Says:

    I don't have time to troubleshoot your problem and I couldn't say off the top of my head why you're getting 0 as a txn_id. I suggest you post this question in the Paypal Developer Forums: http://www.paypaldev.org

  17. kkyuen Says:

    Dear Sir,

    This script is very great!! It works perfect ... until when the customer's info (such as memo, Address ...) contains special characters such as (') quote, (") double quote, or (_) underscore.

    Then, inside the paypal.php,

    foreach ($p->ipn_data as $key => $value)
    {
    $body .= "\n$key: $value";
    }
    $body= addslashes("$body");
    mail($to, $subject, $body, $headers);

    the function "mail" stopped.

    Please advise.

  18. Micah Says:

    I have seen quotes become a problem in the post back IPN data, however, I thought it was fixed in the new code (at least the problem I had seen). I don't have time to test this right now, however, you may want to post this question in the paypal developer's forums: http://www.paypaldev.org

  19. kkyuen Says:

    Thanks for your fast reply!

  20. kurt Says:

    very nice script worked first go! ....

  21. Eshban Says:

    Hello,

    I am using your paypal class
    paypal.class.php

    It works very fine, but i want to change the currency to "GBP".

    i add the following line for this
    $p->add_field('currency_code','GBP');

    but it wont works, i write this line above the amount variable.

    Please tell me that how can i use "GBP" currency

    thanks

    waiting for your reply

    Eshban

  22. Micah Says:

    You may have the wrong variable. Try:

    $p->add_field(’mc_currency’, ‘GBP’);

    or refer to the Integration Guide for more details on which variables should be used for which type of payments.

  23. Ole Says:

    I'm using your script, but the ipn case doesn't seem to be working. I'm not getting any emails with confirmation of the order or anything. The success page works and outputs all the data, but the case IPN does nothing. Is their anyway of testing whether or not it is actually working ?

  24. Micah Says:

    I would guess that you're not setup properly with Paypal. Read the Website Payments Standard Integration Guide (link at the end of article above) to see how to setup the IPN. Regardless of whether you're in paypal Sandbox for testing or a live paypal account, you need to tell Paypal where to find the IPN script.

    If it's still not working, make sure PHP is reporting errors to a text file and then check it for any PHP errors. You can write debugging information to this text file from within this script using something like:

    trigger_error("Testpoint", E_USER_NOTICE);

    Putting that towards the top of the script will tell you the script is getting called, putting it right within the IPN block will tell you it's getting called with an IPN from paypal, etc.

  25. Top 10 Useful PHP Classes « Uncommon Magic Says:

    [...] PayPal IPN Integration - Micah Carrick [...]

  26. » 10 scripts PHP que deberías conocer | Solo Código | Says:

    [...] Paypal IPN integration class: para realizar pagos desde nuestro sitio web. Sin duda muy útil para una tienda online. [...]

  27. 每个PHP开发者应该使用的10个技术项目 | .::灵狼天::. Says:

    [...] Paypal Payment Integration 正如你所想的那样,很多的网站尤其是商业网站会使用paypal的API把接口做在自己的网站上面(国外是这样,国内一般都是支付宝)。那么paypal IPN integration class就是一个完整的模块,使用受理时间大约为20分钟。 [...]

  28. 10 projects every php developer should use « i-nfotech Says:

    [...] know paypal has a nice API for developers who want to integrate paypal payments in their sites. The paypal IPN integration class helps you make use of it and start accepting payments in 20 [...]

  29. 10 scripts PHP que deberías conocer Says:

    [...] Paypal IPN integration class, una clase php que, a través de de la API de Paypal, nos permite realizar pagos desde nuestro sitio web. [...]

  30. 10 projects every php developer should use | alexander-steireif.com Says:

    [...] know paypal has a nice API for developers who want to integrate paypal payments in their sites. The paypal IPN integration class helps you make use of it and start accepting payments in 20 minutes. Editor Controls I don’t [...]

  31. Ali Says:

    Hello,

    Thanks again for the great IPN handler you have made available to all. I was trying to use your code and so far, it was a success.

    The only problem I am having is when I try to set up a recuring payment, so that the payment happens every month.

    I have tried adding the varibles listed in the IPN documentation but I was unsuccessful

    $p->add_field('username', $_POST['paypalemail']);
    $p->add_field('business', $owner_paypal_email);
    $p->add_field('return', $this_script.'?action=success');
    $p->add_field('cancel_return', $this_script.'?action=cancel');
    $p->add_field('notify_url', $this_script.'?action=ipn');
    $p->add_field('item_name', $item_name.$_POST['login']);
    $p->add_field('amount', $price);
    //MY THREE VARIABLES FOR RECURING
    $p->add_field('reattempt', '1');
    $p->add_field('recur_times', '1');
    $p->add_field('recurring', '1');
    $p->add_field('custom', $_POST['login']);
    $p->submit_paypal_post();
    break;

    I have also tried with

    $p->add_field('a3', $price);
    $p->add_field('t3', 'M');
    $p->add_field('src', '1');
    $p->add_field('sra', '1');

    But same problem, a payment is possible but no "recurring payment" is set...

    Pease help me out, I have been working on it for three days now and no one on the paypal community seems to be able to help.

    Sincerely,

    Ali

  32. Dean Says:

    newbie Question,

    can this script process the creditcard payment automatically, without any user intervention?
    if not, is there a way to bypass the paypal front page? where you does not have to click on "Don't have a paypal account? use creditcard click here ..." and send the user directly to the billing info page ?

    thanks

  33. Micah Says:

    RE: Dead

    I'm not sure actually. Although it has been my experience that no, you cannot do that from paypal, I haven't used it in a couple years and have never used premium account or services.

  34. cp Says:

    Hi,
    I was reading your CLASS file. As the last transmission of data between paypal and your server I think we're suppose to send Response 200 Ok

    This is the reason I was reading your class as I've alread a script that seems to be working.

    Do you send the 200 ok? If so how do you do it?

    I think the flow of info is Paypal ipn -> myserver -> postback all data to paypal -> verified sent from paypal to myserver (i do the checks) -> I send paypal 200ok

  35. Micah Says:

    Yes, you are correct. This must be something more recent than when I first wrote this class. From paypal:

    "Your IPN script should then post back a 200 OK response to prevent additional attempts by PayPal to post your transaction data. If PayPal does not receive the 200 OK response from your server, PayPal will resend the notification for up to four days."

    I'll make a note to update my class.

  36. sean Says:

    Micah, you never answered Ali's question, I have the same exact problem and cannot find a reasonable answer anywhere.

  37. Micah Says:

    Ali and sean:

    I haven't worked with recurring payments, so I'm afraid I am of no help. However, this class just passes variables to paypal the same way any other form would, so it's hard to imagine that it wouldn't theoretically work. I believe some people have had success with recurring payments, though I don't have the specifics.

  38. Jeremiah Lewis Says:

    Great script, Micah, I switched all my functions-based approach to your class pretty seamlessly.

    However, I've run into a situation where everything works correctly (IPN sends email, Success outputs a Success message), but on the Success page, I am getting no values back.
    It's almost as if the entire loop is being bypassed.

    Any ideas why this might be?

  39. Jeremiah Lewis Says:

    To clarify, I can't figure out a way to dump the raw $_POST data from PayPal onto my success page. The for loop you've got in your example does absolutely nothing when I get spit back to the "Success" page.

    Your code for the success case:

    echo "SuccessThank you for your order.";
    foreach ($_POST as $key => $value) {echo "$key: $value";}
    echo "";

    What I get back:
    SuccessThank you for your order.

    But I know the data is getting passed back, since I can receive emails via the ipn case that contain all the raw data parsed into table format. So I'm really at a loss.

  40. Micah Says:

    I have heard of this, however, I can't remember how or what causes the data not to be posted back to the success page. It's a setting in your seller account somewhere I believe... like auto-return or something.

    Keep in mind, the success page and the ipn case are completely independent of one another. The success page is the page the user goes back to, the ipn page is a separate process which the paypal server requests--not the user.

  41. Jeremiah Says:

    Thanks for the reply, Micah. I understand the success and ipn cases are independent of each other. However, that data that's getting passed to the ipn case exists--otherwise, the ipn actions after paypal validation (pass info into email and send) would not work.

    But it's moot, I guess, since I turned auto-return off and now those values get posted to the success page! Yay! So, subquestion: I can get $key -> $value combinations from paypal on the success page now. Is there any way to put them into variables? For instance, how to I turn the output of mc_gross into $mc_gross = value;?

  42. Micah Says:

    I'm not sure I understand your question. The values are coming back as $_POST data... so they're in those variables. $_POST['mc_gross'], etc.

  43. Besimus Says:

    Paypal class was excellent.
    If you put the payment bits back on your site.......

  44. Mark Says:

    Hi,

    Huge error showing up with this class. One person made payment, and for some reason, it seems like the IPN keeps getting triggered. They paid only one time, but 15 entries have been created over the last 2 days.

    Any ideas why?

    Mark

  45. Jeremiah Says:

    Hey hope your holiday was great. I figured out what I was trying to do. I needed to put those values into an array and output as keyvalue variable pairs.

  46. mGz Says:

    Still not secured. Good job but it's not enough for me. Regards

  47. Flo Says:

    When somebody pays by eCheck the script handle it like the user makes two payments. The first one when he submits the check and the second one when it gets cleared.

  48. Nick Says:

    Re: Derek Gomez's problem...

    Not sure if it's still helpful, but from what I can see Derek needs to change this line:

    foreach ($p->ipn_data as $key => $value) { $$key == $value; }

    to this:

    foreach ($p->ipn_data as $key => $value) { $$key = $value; }

    Note the SINGLE equals sign instead of the double equals.

  49. Vayn技术网摘 » 每个PHP开发者都应该知道10个项目 Says:

    [...] 网站要赚钱你也要给别人提供个汇钱的接口呀,Paypal给开发者提供了良好的开发接口 paypal IPN integration class 。 [...]

  50. naheed Says:

    i want some help that how i can use pay pall in my website.?by using php coding
    can anyone help me.
    thanks for advnce

  51. Fran Says:

    Great great code, excellent.
    It does work for recurring payment too, the detail is that you have to change the
    "$this->add_field('cmd','_xclick');" to "$this->add_field('cmd','xclick-subscription');" BUT "xclick-subscription" doesn't work when it is encrypted so the problem is not with the code, but with paypal.
    What I suggest you to do is to create your own form and add return variable with the address
    http://yourdomain.com/paypal.php?action=success

  52. Integrated payment from Paypal with PHP | ARTEgami in English Says:

    [...] Micah Carric developed a class PHP that allows the web master to have a major control over their payments, through Paypal. It has 2 Scripts in PHP. If you want to download it or know more about it, check out the developer’s site. SHARETHIS.addEntry({ title: "Integrated payment from Paypal with PHP", url: "http://english.artegami.com/integrated-payment-from-paypal-with-php/" }); Posted in » PHP, Tricks, Web Design | [...]

  53. Mahesh kumar Says:

    Hi thnx for giving nice code for payoal integration.it works but i can't insert into my databse that cunstomer information.but i am getting his firstname Test,last name user and date only.if any body knows how to send customer information to database please tell me....

  54. Matt86 Says:

    Hi,
    I'm italian, i speack english so and so. I have a problem, I can't update my database in Section 'ipn'

    f ($p->validate_ipn())
    {

    // Payment has been recieved and IPN is verified. This is where you
    // update your database to activate or process the order, or setup
    // the database with the user's order details, email an administrator,
    // etc. You can access a slew of information via the ipn_data() array.

    // Check the paypal documentation for specifics on what information
    // is available in the IPN POST variables. Basically, all the POST vars
    // which paypal sends, which we send back for validation, are now stored
    // in the ipn_data() array.

    $updateSQL = sprintf("UPDATE utenti SET stato_account='1' WHERE id='$id'");
    mysql_select_db($database_data, $data);
    $Result1 = mysql_query($updateSQL, $data) or die(mysql_error());

    foreach ($p->ipn_data as $key => $value) { $$key == $value; }
    ......
    }

    Thanks
    Matt86

  55. Desen Web » Blog Archive » 10 scripts PHP que deberías conocer Says:

    [...] Paypal IPN integration class, una clase php que, a través de de la API de Paypal, nos permite realizar pagos desde nuestro sitio web. [...]

  56. bilal ghouri Says:

    how to install it?
    i mean , how to configure the buy now button form to work with this script?
    please help !

  57. Jason Says:

    Hey can you please give me an example of using the class for multiple products? I can't seemed to use:

    $p->add_field('item_name1', 'White Bread');
    $p->add_field('amount1', $total_amount);
    $p->add_field('item_name2', 'Wheat Bread');
    $p->add_field('amount2', $total_amount);

    etc etc... Any help would be greatly appreciated.

  58. Scripts for 2008-03-20 | CalinSoft Says:

    [...] Paypal IPN integration class Para realizar pagos desde nuestro sitio web. Sin duda muy útil para una tienda online. [...]

  59. Himanshu Varshney Says:

    Hi Micah,

    It is really a very simple script and run in a first try.

    Thanks!!!!!!!!

  60. Younus Says:

    HI,

    I'm using your script. It's working well. I'm running the script from my localhost. The payment is done successfully but I face problem to handle ipn response.I think the line of code ### if (empty($_GET['action'])) $_GET['action'] = 'process'; ### in the script paypal.php is not working properly.
    I think the variable $_GET['action'] is always empty so it's assigned by 'process' and the case 'process' is executed only. Any other case ('success','cancel' and 'ipn') is not executed so there is not any ipn response.

    Is there any solution of the problem ? I'll be grateful if you please reply me. Thanks in advance.

  61. spirit Says:

    @Younus: I think you misunderstood how the class works.

    1/ The user click the link 'Pay now' for example
    2/ He is redirected to the file paypal.php (without action=anything). So in the file paypal.php, the action=process is automatically set with if (empty($_GET['action'])) $_GET['action'] = 'process'. Then the switch case structure matched the 'process' case
    3/ The message 'you will be rederected...' appears and validate the form with your orders data
    ______________ Solution 1 _______________________
    4/ Buyer pay the item and click 'Return to the store', which will get him to paypal.php?action=success as specified with $p->add_field('return', $this_script.'?action=success');
    5/ PAYPAL CALLS paypal.php?action=ipn to validate the IPN (this is specified with $p->add_field('notify_url', $this_script.'?action=ipn');)
    ______________ Solution 2 _______________________
    4/ The buyer, during the payment process, click cancel. Then he will be redirected to paypal.php?action=cancel

  62. ashish Says:

    Hello Micah,

    your script is nice and it's working well. but i have a problem. in your script there is switch case ipn. for example when any user click on the pay button on my website and the system goes to the paypal's site. then user input the information and then submit. i think ipn works in this stage i.e. when user pay the amount then paypal notify the ipn url that the paypemt is successed. but i don't get any notification. i set the notification url in the sandbox account and also set a url in the code. so i can't update the users database in backend cause i don't get any notification.

    if u help me about ipn more then it helps me a lot.

  63. Mustafa Says:

    Hi,

    This is really a cool script, but the only thing that I would like to know is how can I submit multiple items in one order.

    Example
    My cart contains two items

    product: Mobile Phone
    Quantity:1
    price: $23

    product: book
    Quantity: 2
    price: $32

    Any help will be highly appreciated.

    Regards,
    Mustafa Jalil.

  64. JasonB Says:

    Hey, Is it possible for this to submit a Subscription payment? I am trying to create a subscription with my order form using Paypal. Is there something that I can pass to Paypal to state that this is a subscription payment?

  65. Jason A. Says:

    Here is an example of how I got this class to support multiple items. My store was built to sell 1 shirt and 5 different sized shirts all saved in a mysql db.

    // GET THE TOTAL PRICE
    global $db;
    $cart = $_SESSION['cart'];

    $items = explode(',',$cart); // get the items from shopping cart
    $contents = array();
    foreach ($items as $item) {
    $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
    }
    $i=1;

    foreach ($contents as $id=>$qty) {
    $sql = 'SELECT * FROM shirts WHERE id = '.$id;
    $result = $db->query($sql);
    $row = $result->fetch();
    extract($row);
    $total += $price * $qty;

    // now add the multiple items to ipn checkout
    $p->add_field('item_number_' . $i, $i);
    $p->add_field('item_name_'.$i, $row['title'] . ' - ' . $row['size']);
    $p->add_field('quantity_'.$i,$qty);
    $p->add_field('amount_'.$i, $price);
    $i++;
    }

    $total_amount = $total; // my total price
    $p->add_field('cmd', '_cart'); // you need this for multiple items
    $p->add_field('txn_type', 'cart'); // you need this for multiple items
    $p->add_field('upload', 1);
    $p->add_field('payment_gross', $total_amount);
    $p->add_field('num_cart_items', $i-1);
    $p->add_field('business', 'jason_1204649129_biz@towerbridgetech.com');
    $p->add_field('return', $this_script.'?action=success');
    $p->add_field('cancel_return', $this_script.'?action=cancel');
    $p->add_field('notify_url', $this_script.'?action=ipn');
    $p->add_field('currency_code', 'USD');

    // the old 1 item only version
    /*
    $p->add_field('item_name', 'My Good Luck Shirt');
    $p->add_field('quantity', $qty);
    $p->add_field('amount', $price);
    */
    $p->add_field('custom', $referer); // my custom field
    $p->submit_paypal_post(); // submit the fields to paypal

    Hopefully you can figure it out because it has been a while since I've messed with this IPN script.

    Good luck!

  66. Tim Says:

    Mustafa -
    This is how I add multiple items:

    After you have added all your fields to field array, loop through your items as below
    This code assumes your items are in array $order_items. Read on to see how to create this. You will need to change the column names ("txt_item_name") to suit your mysql table where your items are stored

    $number='1';
    foreach ($order_items as $item)
    {
    $p->add_field('item_name_'.$number, $item['txt_item_name']);
    $p->add_field('amount_'.$number, $item['int_item_amount']);
    $p->add_field('quantity_'.$number, $item['int_item_quantity']);
    $p->add_field('shipping_'.$number, $item['int_item_shipping']);

    $number++;
    }

    To create the array $order_items I do the following:

    // sql to pull items from your cart. Obviously you will need to change this to suit

    $order_recordset_items = mysql_query("select * from tbl_shopping_order_details where tbl_shopping_order_details.int_order_id = '". $this->order_id ."'");

    // add each item to the array

    $order_items = array();
    while ($item_row = mysql_fetch_assoc($order_recordset_items))
    {
    $this->order_items[] = $item_row;
    }
    }

    This assumes your items are added added to your database in your shopping cart scripts

  67. Rory Says:

    Hi Micah,

    Thank you for this, it is a great help for something I have always found to be very confusing. I think I have it all set up and working correctly, but I just wanted to check...
    I'm sandboxing at the moment and have created a simple form that passes "item_name" and "amount" to paypal.php. This is processed and I'm sent to Paypal, I process my payment and then click the return to merchant link and I see the success page with all the variables. I also receive an email, but on both of these pages, "payment_status" is listed as pending. Am I doing something wrong? Is there a step I'm missing, or is that email all I should receive in confirmation from Paypal? Also, is there something in your script that I can alter to have the buyer automatically returned to my site without having to click the return to merchant link?

    Thanks again for making this information available.

    Rory

  68. Tim Says:

    Micah has done a great job with this script. I had no problems at all integration it into my shopping cart. Most of the issues other people are having seem unrelated to the class. Do yourself a favor and read the PayPal integration guide.

    This class is not a shopping cart and is not a plug and play script. You need to understand PayPal and modify the fields you are sending to suit your application.

    https://www.paypalobjects.com/WEBSCR-510-20080402-1/en_US/pdf/PP_WebsitePaymentsStandard_IntegrationGuide.pdf

    Checkout page 161 in the above PDF. It lists all the variables and when to use them.

    Hope this helps some people

  69. breaker of stuff, destoryer of things, sometimes ninja | php paypal ipn class Says:

    [...] check it out : http://www.micahcarrick.com/04-19-2005/php-paypal-ipn-integration-class.html [...]

  70. 10 projects every php developer should use « Renganathan’s Weblog Says:

    [...] know paypal has a nice API for developers who want to integrate paypal payments in their sites. The paypal IPN integration class helps you make use of it and start accepting payments in 20 [...]

  71. srihari Says:

    Hi Micah,

    i used your code for single item i worked well, now i am working on shopping cart what changes required on the same code for multiple items plz. help me out

    thanks

  72. Kris Says:

    Hi there,,

    ok,, I may be not so coding savvy... but I don't quite get how to use your script or how to integrate it into a payment process...

    Is there a file that would describe the implementation of the class a bit,, or am I missing something?

  73. Gary Says:

    On my Payment for I have 3 additional fields, Domain_IP, Domain_URL and Folder,
    When trying to reference these variables in the sendmail function of the IPN the variables are coming back blank. Am I doing somthing wrong?

    Thanks
    Gary

  74. BBH Says:

    Thank you for your script, it helped me a lot. Wish you all best.

    Thanks.

  75. newbie Says:

    hello guys out here... thanks again for the script micah, it was great. I'm a newbie on php programming.. my question is.. why is it when the shopper finish the transaction the content of success page is the only shown? and supposedly it it go to the ipn page also as you commented that it is where we'll update the database... and the content of success page works fine also... can i update my database at the success page?

    Thanks.
    newbei

  76. Un script PHP para integrar pagos con PayPal a tu sitio web | Desen Web Says:

    [...] PHP Paypal IPN Integration Class, obtendrás un archivo .zip que contiene todo lo que necesitas para comenzar a disfrutar este [...]

  77. Sigmawidgets Says:

    Many thanks. It's the best ipn script in PHP I'v ever seen

  78. Tracy Says:

    Hello Micah, I'm using your paypal class for my very first web site.
    I tested it through sandbox and it was working just fine and I was receiving all IPN notifications through POST method from paypal... but now as soon as I've put it alive in real mode and testing it with my real paypal account, I find that after completing the transaction on paypal, paypal is redirecting the user to the main site and forwarding only a limited variables through GET while all variables are in the url... Also, it says... if you aren't redirected to the site in 10 seconds, click on the link below.... and the link carries those variables for transferring them to the site through GET method! I believe its insecure, but paypal is doing that right now in that way...

    I'm getting the following material in the url from paypal to my thankyou.php page :

    action=success&tx=0FS74310PM366620C&st=Completed&amt=0.02&cc=USD&cm=&item_number=&sig=v%2bUR5VjDGgEHjTLNxKnXcTv%2bMeNHXEdcF8RJCknrIkL2s1Mwqx1LMj%2bwyCS7t3Aqq8maca5mQVcqRq3Bdur3bJczFk48GbwIPOMCfGM2S4kvxYJ3nUCXCmaEDiHXy2T%2f8PNaphck4QwR7x3KLgWqpSzTIBYPhaLXneMmuHX%2b3D4%3d

    All I can do is, store the VERIFIED IPN info in the database and tally it with the transaction id that I receive in the above link.

    Now if someone tampers with the above info, there can be trouble to be addressed!

    Is there any way to force paypal to send user back to the site at the end of transaction and forwarding all info using POST?

    Please help!

    Thanks.
    Tracy.

  79. Adam Says:

    I have receve one error from my server.

    url : http://127.0.0.1/paypal.php?action=ipn
    Error :

    Notice: Use of undefined constant host - assumed 'host' in d:\web_project\www\paypal.class.php on line 162

    Please Help my.

  80. jer166 Says:

    This code is working great for me. I have had several people complain that they did not get an email after payment. I would like to modify the code so I get a copy of the same email that is sent ot the buyer so I can verify the email was sent. Can anyone help. Thanks.

  81. Adam Says:

    Hello,
    And the Money In Euro?
    Thks

  82. alojaweb Says:

    Any ideas of paypal pro ?
    Thanks excellent article.

  83. Martin Says:

    Hello, I'm using your script and I have a problem sending the variable "invoice" to represent the number of invoice. As I send the bill number?

    Thank you

  84. snthelion Says:

    Hi
    Thanks for your code, it is pretty simple and organizes stuff well.

    I am able to integrate this into my code, i am able to complete the transaction at the sandbox and get a success message, but where is the IPN message ? I can't see it, since it is sent by paypal i am guessing something should happen on my screen that shows "Thank you for your order.", am I missing something.

    Since i was able to complete the transaction and got a success page, I am assuming I have setup thing right.

    Please help

    Regards
    snthelion

  85. snthelion Says:

    I figured this out, it is trying to send me an email, I believe the email is not setup on my side so I tred using database insert, and that does not work either.

    Is there any other way of finding if an IPN message actually made it to my site outside of this code ? anything that I can see at my hosting providers logs ?

    Please help

    Regards
    snthelion

  86. SoHail Says:

    To Martin:

    I'm afraid I had problem with Invoice field, besides it has nothing to do with Micah's paypal class, it actually refers to IPN server that expects to receive a STRING variable in Invoice field (Check variable types here :

    https://www.paypal.com/IntegrationCenter/ic_ipn-pdt-variable-reference.html

    ), if you are passing a number (INTEGER) to IPN using Invoice field try another structure for that like converting "1234" to "I-1234", then detach "I-" part when IPN calls your script, in that case it will work like a champ ;)

    Good Luck ;)

  87. Selling Digital Goods/Ebooks With Paypal IPN and PHP | NGCoders - Next Generation Coders Says:

    [...] . We are going to use one of the many Paypal Classes available freely, I have taken one from micah carrick .This class handles the request which Paypal send back to us.So the validation code which will be [...]

  88. tino Says:

    Hello, how can i get the request from paypal to insert this in mysql?
    I would like save the item_name and the amount to mysql.

    This doesn´t work ... like:

    echo $p->ipn_data['payer_email'];
    echo $p->item_name;

    Can you help me?

    dear

    Tino

  89. Amila Says:

    Thank you Micah,
    really useful, helped me a lot.
    May you gain more and more knowledge each day for the good work you done here.

    Amila

  90. Amila Says:

    Rated your script at Hotscripts, keep the good work mate

    Amila

  91. john Says:

    I like it and the background and colors make it easy to read

  92. Iyas Says:

    Micah, thanks. Your PHP Class is very useful. It helps me a lot.

    tino, try this:

    echo $p->ipn_data['payer_email'];
    echo $p->ipn_data['item_name'];

    Iyas

  93. tom Says:

    you know what i've noticed... if you refund someone's payment in paypal, it sends a notification to the IPN interface that it interprets as "Success". is there another IPN response it should be looking for? i'm wondering why it's interpreting the response as success. i've been digging around my apache logs to see what Paypal is sending, if I figure it out i will let you know.

  94. Nancy Says:

    Hi...

    Plz anyone help me to get a simple example for paypal in php script... I have searched a lot of codes.. But yet I didnt get a clear idea in this... Plz someone help me to get a clear idea in paypal with a simple example... thanks for your timely help...

  95. Dick Leung Says:

    Hello, I got a problem , basically the script is every thing fine, except my member ID $_SESSION['userid'] this field can not store in my database, also is nothing.

    How can i solve that ? Hope you can help, thank you!

    //=====================================================

    if ($p->validate_ipn()) {
    $subject = 'Instant Payment Notification - Recieved Payment';
    $to = 'email@email.com'; // your email
    $createdate=$p->ipn_data['payment_date'];
    $bank = "PAYPAL PAYMENT";
    $query = "INSERT INTO pay ( memberid, pay, bank, bankn, paydate ) values ({$_SESSION['userid']},$p->ipn_data['mc_gross']},'{$bank}','{$p->ipn_data['payer_id']}','{$createdate}' )";
    mail($to, $subject, $query);

  96. Dick Leung Says:

    I have found out the solution as below:

    1) $p->add_field('custom',$_SESSION['userid']);
    2) $p->ipn_data['custom']

    Is work, but how may this "custom field" i can setting , have already try another method
    $p->add_field('custom1',$_SESSION['userid']);
    $p->add_field('custom2',$_SESSION['userid']);

    Is not work , just only setting "custom" is work fine , Can you help me ?

    Thank you
    Dick Leung

  97. john Says:

    can you send me a php shopping cart?

  98. tom Says:

    fyi, i found that if you want to check to make sure the VERIFIED ipn responses you get back from paypal are refunds and not payments (or other status checks) you can throw a little extra IF statement in the verified IPN section to check on the $p->ipn_data['payment_status'] value...

    i.e. if ($p->ipn_data['payment_status'] =="Refunded") { do this} else { mark as paid }..

    you can get other information from the return ipn_data, such as ascertaining whether something is a direct payment or an echeck.

  99. Micah Says:

    john:

    I don't have a "php shopping cart" on hand to send you. Sorry. This code is intended to be used by intermediate/advanced coders to more quickly implement their own shopping carts.

  100. Micah Says:

    tom:

    Yes, the sample provided is just the starting point. You will need to add your own logic for ensuring the post back is valid and processing the data returned as outlined in the Paypal Integration Guide.

  101. adriano Says:

    Great script! thank you, you saved my day.

  102. 10 projects every php developer should use « HMV.co.in Says:

    [...] know paypal has a nice API for developers who want to integrate paypal payments in their sites. The paypal IPN integration class helps you make use of it and start accepting payments in 20 [...]

  103. Shahbaz Says:

    Hi Micah,

    i am some problem i have included else condition like this.

    the problem is paypal is constantly mailling me test data that i used months ago in sandbox even i have removed that.

    the second thing is when today i got the error i got the mail of this ERROR.

    it is not validating ipn it is going in else condition.

    please let me know.

    thanks.

    if ($p->validate_ipn()) {

    foreach ($p->ipn_data as $key => $value) {
    $body .= "\n$key: $value";
    }

    require('reservation-letter.php');

    mail($to,$subject, $body, $headers);

    }

    else{
    $headers .= 'From: Estate400 ' . "\r\n";
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    foreach ($p->ipn_data as $key => $value) { $body .= "\n$key: $value"; }
    mail('--------------------','Error',$body, $headers);
    }

  104. Integra pagos de Paypal con PHP - Monjes - Cultura libre Says:

    [...] Integra pagos de Paypal con PHP Micah Carric desarrollo una clase (class) en PHP que permite a los desarrolladores obtener un mayor control en las

  105. Yu An Litimco Says:

    Hi Micah, I'm currently using your class I hope that you cold help me out with this one.. I could say i'm in the middle of a Newbie/Intermediate when it comes to php. I'm somehow confused with using it. Here's what I want to came up with my website i'm currently working on:

    - a customer needs to verify his/her paypal account by transferring $5 to my paypal, so i created a buy button. but i assured my customer that after 5 days he/she will have his/her $5 refund. so he/she'll be hitting the buy button, access his/her paypal account, pay $5, then goes back to my website.

    i'm already done with adding the buy buton & confirming the transaction, now here's the hard part: i want to use the PHP Paypal IPN Integration Class (paypal.class.php & paypal.php) to allow me to grab the Unique Transaction ID and the IPN after confirming the payment and goes back to my site...

    I already read the "Website Payments Standard Integration Guide" and i already have the idea of its flow, but if you could provide like links and other resources that i could use with this that would be so cool... thanks in advance.

  106. What’s in your Bookmarks? « Blackstone Media Blog Says:

    [...] PHP Paypal Integration Class This was very helpful on a php site I had to do a paypal checkout for, if only the LinkPoint integration had gone so easy. [...]

  107. Shotta Says:

    Hey Guys,
    Im new to programming and paypay ipn. I got the class to work and also update a database but I just cannot configure it to work with recurring/monthly subscription.

    Can I get some help.

  108. swati Says:

    i am having problem in using your class.I have given a url in "process" case as $p->add_field('return', $this_script.'?action=success');
    after successfull payment ,on clicking "Return to merchant" button it going to this page.

    Then when the "success" case will be executed.I want to redirect the user to "thankyou.php" page after successful payment.Please help.

    Also when the case "cancel" will beexecuted.Because when i click on the link "Cancel and return to ----", iam going to the page that i have specified with $p->add_field('cancel_return', $this_script.'?action=cancel');

  109. bimo Says:

    Hi Micah,
    I hope you can help. I'm a newbie in Pay Pal and trying to set up a 'Paypal Express Checkout', it seems that I've put every code in place, but when I test it, this message show up:

    ACK=Failure&L_ERRORCODE0=81002&L_SHORTMESSAGE0=Unspecified%20Method&L_LONGMESSAGE0=Method%20Specified%20is%20not%20Supported&L_SEVERITYCODE0=Error

    A clue would really help.Thanks

  110. subash Says:

    Here is an example of how I got this class to support multiple items. My store was built to sell 1 shirt and 5 different sized shirts all saved in a mysql db.

    // GET THE TOTAL PRICE
    global $db;
    $cart = $_SESSION['cart'];

    $items = explode(',',$cart); // get the items from shopping cart
    $contents = array();
    foreach ($items as $item) {
    $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
    }
    $i=1;

    foreach ($contents as $id=>$qty) {
    $sql = 'SELECT * FROM shirts WHERE id = '.$id;
    $result = $db->query($sql);
    $row = $result->fetch();
    extract($row);
    $total += $price * $qty;

    // now add the multiple items to ipn checkout
    $p->add_field('item_number_' . $i, $i);
    $p->add_field('item_name_'.$i, $row['title'] . ' - ' . $row['size']);
    $p->add_field('quantity_'.$i,$qty);
    $p->add_field('amount_'.$i, $price);
    $i++;
    }

    $total_amount = $total; // my total price
    $p->add_field('cmd', '_cart'); // you need this for multiple items
    $p->add_field('txn_type', 'cart'); // you need this for multiple items
    $p->add_field('upload', 1);
    $p->add_field('payment_gross', $total_amount);
    $p->add_field('num_cart_items', $i-1);
    $p->add_field('business', 'jason_1204649129_biz@towerbridgetech.com');
    $p->add_field('return', $this_script.'?action=success');
    $p->add_field('cancel_return', $this_script.'?action=cancel');
    $p->add_field('notify_url', $this_script.'?action=ipn');
    $p->add_field('currency_code', 'USD');

    // the old 1 item only version
    /*
    $p->add_field('item_name', 'My Good Luck Shirt');
    $p->add_field('quantity', $qty);
    $p->add_field('amount', $price);
    */
    $p->add_field('custom', $referer); // my custom field
    $p->submit_paypal_post(); // submit the fields to paypal

    Hopefully you can figure it out because it has been a while since I've messed with this IPN script.

    thank for given sript i use one site

  111. Kurniawan Says:

    Hi, Micah.

    I found your PayPal class from some forum. Thanks for making this.

  112. bryon Says:

    Hi Micah, does this script now support the 200 ok back to Paypal? Thanks.

  113. William Says:

    How would I implement an IPN check for payment_status = Completed?

  114. sunil Says:

    hi there,
    i have installed the paypal-1.3.0 on localhost.on successful transaction success ins areturned.but "case:ipn" is not working at all.i ahve tried to echo some lines at the start of loop and after the "if ($p->validate_ipn()) {" ,but no line is echoed.any suggestions.what variables are to posted to make case:ipn working.thanks in advance.

  115. Henk Says:

    First of all thanks for this great class!

    I only was wondering (like Sunil) if you coud (or sombady else) help me with the IPN.
    The whole script (except the IPN part) works.
    In the IPN I want to write a line in my database (I have checked that code and that works) but in the IPN is doenst places anything in the database. I also get no errors.
    Even when i place the mysql_query outside the if ($p->validate_ipn()) { it wont work.
    ** I am testing on localhost **

  116. Harvy Says:

    Very neat and nice class

  117. Harvy Says:

    Sunil,

    Paypal cant communicate with your localhost during the ipn validation.

  118. Ryan Bayne Says:

    Hi

    First time using IPN and your Class is the best I have found so far but there is something I just don't understand so any word of help would be great.

    To me your suggesting that I should process the payment and insert it to database THREE times and I just dont get that at all!

    1. The line, case 'ipn' in paypal.php: Your example already includes emailing and commented code suggests processing.

    2. Then in checkpayment.php has this and also suggest processing the data...

    $isPaid = $doCheck->checkPayment($_POST);
    if($isPaid == true)

    3. function checkPayment($_POST) in paypal.class.php also states that the payment should be processed.

    All three indicate some sort of database or email activity but its totally confused me and I only see number 2 being the place to save to database and send emails.

  119. Xrvel Says:

    One of the best simple PHP class. Great job.

  120. Lawrence Shafer Says:

    Hey Guys, Here's an example of a way to get subscriptions working.

    The custom field holds the uid of my customer (who is already in database)

    a1, p1, t1 are the trial settings. In my case, $amount, 10, D(ays)
    a3, p3, t3 are the subscription settings. Again, $amount, 1, M(onth)

    Have Fun!

    //////////////////////////////////////////////////
    $p->add_field('first_name', $first_name);
    $p->add_field('last_name', $last_name);
    $p->add_field('custom', $uid);
    $p->add_field('cmd', '_xclick-subscriptions');
    $p->add_field('business', $paypal_mail);
    $p->add_field('item_name', $item_name);
    $p->add_field('no_shipping', '1');
    $p->add_field('no_note', '1');
    $p->add_field('currency_code', 'USD');
    $p->add_field('lc','US');
    $p->add_field('bn', 'PP-SubscriptionsBF');
    $p->add_field('a1', $trial_amount);
    $p->add_field('p1', '10');
    $p->add_field('t1', 'D');
    $p->add_field('a3', $subscription_amount);
    $p->add_field('p3', '1');
    $p->add_field('t3', 'M');
    $p->add_field('src', '1');
    $p->add_field('sra', '1');

    $p->add_field('return', $this_script.'?id=scripts/paypal_ipn&action=success');
    $p->add_field('cancel_return', $this_script.'?id=scripts/paypal_ipn&action=cancel');
    $p->add_field('notify_url', $this_script.'?id=scripts/paypal_ipn&action=ipn');
    $p->submit_paypal_post(); // submit the fields to paypal
    //$p->dump_fields(); // for debugging, output a table of all the fields
    break;
    /////////////////////////////////////////////////

  121. hakan iyice Says:

    @Henk

    to get ipn from paypal when your code is on localhost, you should set your "return_url" field with your ip. something like http://localhost/.../paypal.php won't work because you're not localhost to paypal :) so do it like http://your IP/.../paypal.php and then it works. additionally, you may have to set DMZ Host thing on your modem.

    @William

    the ipn_data holds everythng that comes from paypal. so there's ipn_data['payment_status'] which is set to VERIFIED when the payment is complete.

    ____

    by the way, the post variables that is sent to paypal via clicking paypal button can be altered/changed using some debugging tools. so you should check the details after the payment is complete.
    this is important because you won't like the customer to pay 1$ for something that costs 100$.
    so you could do 2 things to preserve yourself from fraud:

    1) log the variables on buy button pressed and compare them with the ipn. post back the original values to paypal on ipn stage.

    2) log the variables on ipn stage and check them after the verification is complete.

    the point of doing these stuff is to make sure that the amount and the receiver is not changed.

    good luck with your work everybody..

  122. hakan iyice Says:

    --correction--
    ipn_data['payment_status'] = Completed if payment is successful

  123. lorem ipsum Says:

    what if submitted variables are changed? how do we check it?

  124. Eugene K. Says:

    Hi Micah !

    firts of all thanks for your paypal class, it works great!

    But i have one problem, anybody tried to use it with GoDaddy hosting? This script works just fine anywhere else, but not on their servers.

    I've spent last 3 days trying all those solutions with curl, proxies, etc. AND still i can't get it working....

    Guys, have anyone tried to implement this class at godaddy? Any advice would help because i'm getting crazy already..

  125. Parsi Says:

    Hi, great script. Thank you very much. Worked on 1st time. It is easy to work with, BUT! for some reason I have the problem to dump the data if I do a auto redirect back on my page and also IPN case is able only to send email, but not process the data and insert/update the database. Do you have clue how around this. Any help would be great! Many thanks.

  126. karan Says:

    Hi

    I hav made a hotel booking script. When the payment is complete and paypal confirms , I get a email which says status pending. Why is this.

    Secondly , after the payment is complete i want to update my database. For this i want to update dates for which the booking has been made. I am storing the dates in variable called $to_date and $from_date. My problem is the data is not being passed from paypal and back to my site after payment confirmation.

    PLS help.

  127. Jim Says:

    Is someone able to assist with the format that would be required for the php mail to be sent from the sender found in the IPN info.

    The format required would be like this to get the correct headers in the email:
    $From = "Firstname Lastname ";

    The IPN info is coming back in the following:
    email address:
    $p->ipn_data['option_selection10']
    Firstname:
    $p->ipn_data['option_selection3'].
    Lastname:
    $p->ipn_data['option_selection1']

  128. sandesh Says:

    i use ur class its very effective

  129. Kumar Says:

    I recommend PHP Express Checkout Wizard to simplify PayPal Express Checkout integration: PHP Express Checkout Wizard. cURL is not required and it works with IPN as well.

  130. Joseph Says:

    I'm a newbie at php and need some help troubleshooting an IPN issue. The payment transaction works fine and the buyer is directed to the thank you page, however, my notifications to me and the buyer are not working. All the scripting is error free and correct. I believe the issue is either with Paypal or my Hosting.
    PayPal: I have a Premier account. I have enabled IPN and directed it to http://tools4fantasy.com/paypal.php
    This includes a settings.php file. From what I understand, this is all I have to do in PayPal.
    Hosting: This is where I think the problem may be. The server is using version PHP 5.4.2 I've tested the email using a contact page and that works fine. I don't know if there are any specific settings in the PHP configuration I need to check.
    The class refers to an error log "ipn_log_file" but I haven't been able to locate this log. I have checked every directory via ftp but no joy.
    I have spent 5 weeks using trial and error to resolve but just cannot get it to work. Any help would be greatly appreciated and would gladly make a donation.

  131. chaminda Says:

    Why this class not work with https://www.sandbox.paypal.com/cgi-bin/webscr'. ? Its not redirect to paypal sand box.

  132. Panagiotis Kosmidis Says:

    Hello, I converted your Paypal Class into Zend Framework Helper so I could use it in my Controllers. Everything works great except the IPN process. I test it on my localhost with a sandbox testing company account (seller) and a sandbox testing personal account (buyer) but it seems that IPN process never called. There isn't anything on .ipn_results.log except if I trigger the IPN url manually.

  133. Nick Says:

    The IPN of the script works only if I use :

    mysql_connect("dsfdsfd","fdsfd","sdffd") or die("Unable to connect to database");
    mysql_select_db("sfdsdb") or die("Unable to select database");
    $sql="UPDATE payment SET payment.pay_received_amt='".$p->ipn_data['mc_gross']."', payment.paypal_txn_num='".$p->ipn_data['txn_id']."' WHERE payment.quoteNum='".$p->ipn_data['item_number']."'";
    mysql_query($sql);

    but if I use:

    require_once('config.inc.php');
    require_once('mysql.class.php');
    require_once('order.class.php');
    require_once('showorders.class.php');
    require_once('customer.class.php');
    require_once('paypal.class.php'); // include the class file
    $p = new paypal_class;
    $order= new Order($mysql);

    and
    if ($p->validate_ipn()) {

    $quoteNum=$p->ipn_data['item_number'];
    $payment=$p->ipn_data['mc_gross'];
    $txn_id=$p->ipn_data['txn_id'];
    $order->setPaymentStatus($quoteNum,$payment,$txn_id);

    it does not get to sending out the IPN email.

    Does anyone have any example of using an instance of an another class in the script?

    Thank you in advance.

  134. Varun Says:

    Hai Micah,

    I am using your ipn script, its working fine for me, i am getting the mail, and my database gets updated. But the problem is that when a customer who has no account uses the paypal's direct credit card payment. the auto return does not work for it, so it does not return to my Websites Thank You Page. i have added my affiliate tracking code to the thanks page to sent the sale amount and other details to the affiliate. Unless it returns to the thanks page affiliate tracking doesn't work.
    Can u pls help me

    can i add that tracking script in the paypal.php file

    can anyone help me to sort it out.....

  135. nathan Says:

    Hi, great class.

    I insert order details to DB before submitting to paypal, then on successful notification I want to update the order status field of my db. Im tryin the following:

    mysql_query("UPDATE entries SET ORDERSTATUS = 'payment received' WHERE ORDERID='$invoice' ") or die (mysql_error());

    The problem is that i can't cant get the value for the invoice number to select the relevant entry to update. Any pointers??

  136. testuser Says:

    can yu please tell me step by step procedure(flow) & setting how this class is working? its urgent.....

  137. sniperstealth Says:

    hi mica i'm still new at this kind of php language with paypal i was wondering why is it that everytime i redirect to my site the steps is always like this cannot find ssl ?i hope you can help me with this. i really need this asap thanks..good tutorial

  138. nsplender Says:

    I tried this paypal ipn class.......but i have problem for multiple product(items). paypal can't dispaly item listing .....see my code for listing

    $inumber =1;

    foreach($OrderContent as $items)
    {
    $p->add_field('item_name_'.$inumber, $items['pd_od']);

    // $p->add_field('item_number'.$inumber, $SessionId);

    $p->add_field('amount_'.$inumber, $items['od_id']);

    $p->add_field('quantity_'.$inumber, $items['od_qty']);

    $inumber++;
    }

    if i remove _'.$inumber then it ia taking one items details...but not show item list for multiple. Give me suggestion

  139. Dane Says:

    Micah-

    I hope you can answer my question: I run a newspaper and am looking for a way customers can place their classified ads online and charge it to their paypal or credit card account, then have the text of the ad forwarded to my email to be put in the paper's print edition. Is this what your script does, or do you know of one that does this that I can purchase ? Please reply to my email above.

    Thanks, Dane Hicks
    Publisher
    The Anderson County Review

  140. mehdi Says:

    Hi Your paypal class is'nt working on dreamhost issue on fsockopen. how i can fix it? many thanks

  141. sergio Says:

    Hello.

    Thank you so much for such a great paypal code! I'm newbie in PHP and I was wondering if you could please tell me how can I get the variable 'payer_email' that the paypal.com site will send to my website to send the email to my customer.

    I tryed the following code but no success:

    mail ($p->ipn_data['payer_email'], $email_subject, $email_message, $headers))

    Once again, thank you so much!!!

  142. Dream Reaper Says:

    Micah, thanks for this excellent piece of code which has helped me integrate PayPal to my website (I wonder why Paypal did not provide a simple wrapper class like this themselves in the first place). The Paypal documentation is at best confusing, and at worst misleading.

    To all those who are asking silly PHP/MySQL/Paypal specific questions, please give Micah a break. This is code that Micah has given freely, if you want to use the code, do yourself a favour and read up on the PayPal HTML and IPN variable documentation. Also, I think its unreasonable to expect Micah to answer your PHP/MySQL related questions.

  143. ahmet vardar Says:

    hey man, great class, thx !

    but you suggested to do DB stuff in IPN validation part, but sometimes paypal sends IPN data multiple times and 4-5 or more data goes to DB, what about this ?

    thanks

  144. Umair Says:

    i used the class.

    I m getting a problem, when the site goes live, i m receiving too many IPN emails (sounds paypal is hitting the script again and again) so my IPN code is executing too many time or each single order. I can see my custom variable it contain same primary key!

    any idea why paypal is doing so, why its hitting the script many time? should i echo some thing in ipn part so that paypal can read some response from script and stop retrying?

  145. Deqn Says:

    Thank you for the script :) , i make it work with my wow system (to automatic insert donate points in DB),It works perfect

  146. seo submit manual Says:

    not working this script

  147. Adam F. Says:

    Micah (or anyone else that knows)

    How can I simply output the form data (not the ipn data) into the mail message?

    thanks very much in advance-
    -Adam F.

  148. diseño web Says:

    By the commentaries that I read this very well but some example?

  149. Charlie Collins Says:

    Very nice little script, worked well, thanks!

  150. Adarsh Says:

    Hello Micah ,

    I am using you class. I am facing with problem ipn validation...
    Here I want to update my database, but I am not able to update database. I hope my notify_url is not called by paypal. I checked ipn_log text file.....
    What is problem I don't know . I hope you understand my problem....... Please give me reply as soon as possible
    Thank You
    Adarsh

  151. Kim Says:

    *Yo shit is da bomb!*

    I implemented this class in one of our corporate websites, and it just works perfect!
    I did have some problems figuring out how to implement this in a wordpress plugin, and what the precise flow between order-actions / steps should be...

    I did it like this:
    1. Orderform
    -- Validate Orderform
    OR
    -- Continue to "Review"
    2. Reviewform
    -- Submit to "Processing"
    This saves all order data and
    if payment method == "paypal", I echo the redirect form.
    else step = "Success"
    3. Success / Cancel
    The same pages as where Paypal customers would be redirected to when coming back from Paypal.

    Just added this little "scheme", hoping to help others!

    Kind regards, and thanks again,
    Kim

Leave a Reply