SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IPN modification question

    Hey, I'm building a PHP subscription script and i'm currently working on implementing PayPal. When my IPN script is called is there anyway of calling cookies or say sessions from it? Or even get the users ip address? Thanks in advance

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Paypal lets you pass an arbitrary id when you send the user off to paypals website. Paypal will send it back to you when it sends the POST to your ipn script. This can be used to identify the user if you don't want to use the other data paypal sends. The id could be a session id if you wanted it to be.

  3. #3
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay i've been looking for an example of this but can't find one. Can it be accessed by using $_POST?

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You really should make sure you thoroughly understand thier system and api if you're going to attempt this. A good start is to read thier documentation.

    https://www.paypal.com/ipn

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The IPN script can be called up to four or so days after the person who started the purchase made their request. There is no guarantee that the person will be anywhere near a computer on the day the IPN script runs and no way of telling which computer they are on if they are. Trying to do anything with sessions or anything else apart from the fields that Paypal passes into the script is therefore meaningless.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Up to 4 days after? I've been testing my script out on the sandbox and it's being called straight away. Or are you referring to a real purchase?

  7. #7
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's a lot of reasons why paypal, or a user may not be able to access your website immediately, even though the user was just on your website. Servers and networks are not always available. Most of the time the paypal post comes right away though.

    It won't hurt anything so long as you have a way to connect that id back to the users order whenever paypal posts the data to you. This probably means you saved the id to the database. Make sure the user isn't required to retain the session cookie. Hopefully you establish some more durable method of identifying them(like, a log in, and optionally set a seperate, longer living cookie as a convenience). People's browsers do get closed unexpectedly.

  8. #8
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by tom-90 View Post
    Up to 4 days after? I've been testing my script out on the sandbox and it's being called straight away. Or are you referring to a real purchase?
    It depends on how they pay for the real purchase. The slowest is where the payment is made by echeck where paypal usually take about 4 days to clear the payment. In that instance the IPN script gets called twice - once straight away to acknowledge that the payment has been started and the second time once the payment is cleared which is usually about 4 days later. If you provide access to their purchased product after the first call without waiting for the payment to be completed then you run the risk of the payment not completing - particularly if the account they are paying from does not have sufficient funds for the purchase.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  9. #9
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Problem solved! Initially I wanted to get the buyers first and last name. I've since looked at the PayPal documentation and realized I can use the first_name and last_name varibles. Thanks for the help any way though appreciate it!

  10. #10
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You can actually pass as much info as you want to collect. Paypal have a couple of custom fields you can use for whatever you like to pass information across. The simplest solution is to capture all the fields you want and store them in a database and pass the key to that record in one of the custom fields. You can then use that to do database lookups from the IPN script to retrieve all the info.

    Note that the first_name and last_name Paypal provides is that of the account owner which may or may not be the name of the person making the purchase. For example I have a Paypal IPN script handling new and renewal memberships for a club and often the member gets their wife to use their Paypal account to make the payment as they don't have one of their own.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  11. #11
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    These custom fields do they go into the button HTML? say... <input type="hidden" name="custom" value="Example Name" />

  12. #12
    SitePoint Enthusiast
    Join Date
    May 2005
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The IPN script returns all the information about the purchase. Be careful, it will ping you more then once per purchase, with Pending and Completed states.

    The IPN script pings your server, it doesn't know anything about the customer browser cookies, sessions, etc, unless you specifically used the custom field of the PayPal for to pass it all along the purchase, in which case the IPN script returns the information back to you.

  13. #13
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, for the custom fields do I need to add anything to the button HTML? Say something like the example I posted before.

  14. #14
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    As long as you use one of the custom field names that Paypal specifically provides and don't try to put more data into them than Paypal allows for then a hidden field is the easiest way. 'custom' is probably the easiest one to use but Paypal does also provide a couple more for if one isn't enough. If you save all the info you need into a database first and just save the key in the custom field then your IPN script can use that to read all the rest of the data back from the database allowing you to pass as much data as you need..
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  15. #15
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay thanks, I've think i've just about got it now. Thanks appreciate the help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •