+ Reply to Thread
Results 1 to 10 of 10
Like Tree3Likes
  • 1 Post By essellar
  • 1 Post By essellar
  • 1 Post By essellar

Thread: PayPal IPN Listeners

  1. #1
    learning_brain is offline x10 Sophmore learning_brain is an unknown quantity at this point
    Join Date
    Apr 2010
    Location
    UK, Midlands
    Posts
    170

    PayPal IPN Listeners

    Hi all

    I'm confused and tired and need some help....

    I have an ecommerce site, which is pretty much done now - providing a CMS for the client and then dynamically generating item lists.

    I'm using the PayPal buttons "add to cart" form/hidden variable technique, which works great and has been tested.

    My problem is....

    In order to update the database that the item has been sold, I need an "IPN listener" which is a piece of code that waits for paypal to send information. When this information is received, the listener then sends back EXACTLY the same info (I believe) at which point PayPal returns a valid or invalid response.

    On receiving a valid response, I need to use that (if,then) to update the associated records to say that they are no longer for sale.

    There is a bunch of stuff under the PayPal implementation site, but the sample code is a bit over my head.

    Does anyone know of a similar listener (php) that I can copy/paste and configure fairly simply?

    Either than or a good simple tut I can follow.

    Rich

  2. #2
    nirma1230 is offline x10Hosting Member nirma1230 is an unknown quantity at this point
    Join Date
    Jun 2011
    Posts
    4

    Re: PayPal IPN Listeners

    i am also using paypal, thank you to share the great infomration about the paypal, its really help full, keep it up
    Documents translation

  3. #3
    hieufpt156 is offline x10Hosting Member hieufpt156 is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    19

    Re: PayPal IPN Listeners

    you Can write detail, I don't understand

  4. #4
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: PayPal IPN Listeners

    Checking the payment_status and receiver_email values is very straightforward, but the other stuff you need to check before you return the okey-dokey depends on how your database is structured, what db you're using, whether you have an ORM layer between your application and your database, and so forth. You need to look in your transactions to see whether the current transaction ID (that's what the txn_id variable is) has been processed or not, confirm that the article purchased (item_number) is valid and that the price being paid actually matches the price you were charging (malicious users may want a discount you weren't planning to offer).

    If all of that is valid, then you need to process the transaction. If you're selling hard goods, that means removing the purchased goods from the inventory, beginning the fulfillment process, and adding the amount paid into your "income" pile, along with creating a transaction record detailing the purchase. (With downloads there's no inventory to handle, but you may need to generate a license key or enable a download link.) Again, the code will be specific to your site (or to your eCommerce package); there's no generic code you can just paste in beyond what PayPal gave you in the IPN_PHP text file. Those five commented-out lines can represent a complex bunch of code.

    We can help, but we need more to work with. (And you may find the PayPal developer community to be more help than we are here. Not that we all suck, but this is the first comment in the thread with any content and I'm two days late to the party -- and I may be of no great help over the long run for reasons beyond my control.)
    learning_brain likes this.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  5. #5
    hieufpt156 is offline x10Hosting Member hieufpt156 is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    19

    Re: PayPal IPN Listeners

    you must write detail as using image or code template

  6. #6
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: PayPal IPN Listeners

    Actually, getting the code template from the PayPal developer site is *really* easy -- posting it here isn't all that helpful:

    PHP Code:
    // PHP 4.1

    // read the post from PayPal system and add 'cmd'
    $req 'cmd=_notify-validate';

    foreach (
    $_POST as $key => $value) {
    $value urlencode(stripslashes($value));
    $req .= "&$key=$value";
    }

    // post back to PayPal system to validate
    $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " strlen($req) . "\r\n\r\n";
    $fp fsockopen ('ssl://www.paypal.com'443$errno$errstr30);

    // assign posted variables to local variables
    $item_name $_POST['item_name'];
    $item_number $_POST['item_number'];
    $payment_status $_POST['payment_status'];
    $payment_amount $_POST['mc_gross'];
    $payment_currency $_POST['mc_currency'];
    $txn_id $_POST['txn_id'];
    $receiver_email $_POST['receiver_email'];
    $payer_email $_POST['payer_email'];

    if (!
    $fp) {
    // HTTP ERROR
    } else {
    fputs ($fp$header $req);
    while (!
    feof($fp)) {
    $res fgets ($fp1024);
    if (
    strcmp ($res"VERIFIED") == 0) {
    // check the payment_status is Completed
    // check that txn_id has not been previously processed
    // check that receiver_email is your Primary PayPal email
    // check that payment_amount/payment_currency are correct
    // process payment
    }
    else if (
    strcmp ($res"INVALID") == 0) {
    // log for manual investigation
    }
    }
    fclose ($fp);
    }
    ?> 
    It's filling in the details specific to a site that gets hard, and it depends (as I said) on the way the site's data (and data object APIs if an ORM is in play) are structured. The top-level code only deals with the message content -- the problem space is integration.
    theone48 likes this.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  7. #7
    learning_brain is offline x10 Sophmore learning_brain is an unknown quantity at this point
    Join Date
    Apr 2010
    Location
    UK, Midlands
    Posts
    170

    Re: PayPal IPN Listeners

    Thanks Essellar (do I see a clever photography letter-play in your username BTW?? )

    I didn't see any quick responses so guessed this was probably out of the field of the helpful guys/gals on here. I did post on the paypal forum - with NO response at all.

    Yes - the script wasn't too tricky to copy, but as you say, it's integrating it in with the site that proves tricky.

    My first problem was to get validation back from Paypal. I was getting the first post data, but when it was sent back, I wasn't getting a reply so couldn't validate the sender. Even with a sandbox account, this got strangely quite confusing.

    Anyway - I'm there now with a check for already processed ID's and a check on price by pulling in a recordset based on item_number - or whatever it was.

    I had to switch to "buy now" rather than "add to basket" option as it made my life easier with simple single returned id's and, considering the site content, isn't going to be a major headache.

    Process registers item as "SOLD" or "RESERVED" and stores some registration info like transaction id, name, e-mail etc.. to cross-reference the paypal account.

    Thanks for your efforts.

    Rich

  8. #8
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: PayPal IPN Listeners

    Photography, yes, but they're also my initials. I remember bragging about a monogrammed camera when I was a young lad (my friends -- those that had cameras, at least -- all had Brownies, Instamatics or, in one case, a Rolleiflex TLR).

    Sorry I didn't see your question early enough, Rich -- we might have baked a solution.

    Stan
    learning_brain likes this.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

  9. #9
    learning_brain is offline x10 Sophmore learning_brain is an unknown quantity at this point
    Join Date
    Apr 2010
    Location
    UK, Midlands
    Posts
    170

    Re: PayPal IPN Listeners

    Thanks Stan

    To be honest, I probably learned more going through it the hard way rather than a baked solution, but thanks again for the consideration.

    I've only recently got back into photography. In my early days, I had a Practica which had such a dodgy shutter release, I always had motion blur, despite the tripod/weights I was using for macro work (on tubes - yuk).

    Now moved on to (dare I say it) Nikon DSLR with my new Manfrotto toy! Life is so much easier with VR and without film!!

    Rich

  10. #10
    theone48's Avatar
    theone48 is offline x10 Sophmore theone48 is an unknown quantity at this point
    Join Date
    Jun 2011
    Posts
    221

    Thumbs up Re: PayPal IPN Listeners

    There is great info on this thread for anyone setting-up PayPal. I'll be sure to keep this one in mind.
    T1 Need Help? Add me to your friend's list & message anytime!
    If you believe this a good post, please click the star icon below. Thanks!
    Remember, help is only a step away in the forums or on Live Chat.

+ Reply to Thread

Similar Threads

  1. About Paypal
    By Wizet in forum Off Topic
    Replies: 8
    Last Post: 03-24-2009, 04:45 PM
  2. Paypal buy.
    By Jonthefisherman in forum Scripts & 3rd Party Apps
    Replies: 4
    Last Post: 03-14-2009, 06:45 AM
  3. Paypal
    By bunglebrown in forum Earning Money
    Replies: 4
    Last Post: 09-09-2008, 02:52 PM
  4. I got paypal phishing email from paypal.pcriot.com
    By yorije in forum Feedback and Suggestions
    Replies: 5
    Last Post: 10-03-2007, 02:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers