SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: PayPal Question

  1. #1
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PayPal Question

    I am about to build a form that will accept donations for a charity using PayPal. Now, it's easy enough to just collect money and put it into PayPal. What I need to do, however, is collect information about the person making the donation (name, email, etc.) and insert that into a mySQL database.

    Should I look into PayPal IPN, or is there an easier way to do this?

    Thanks!

  2. #2
    SitePoint Guru risoknop's Avatar
    Join Date
    Feb 2008
    Location
    end($world)
    Posts
    834
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can make it a 2-step process.

    First page is a form for name, email and other personal information. After submitting the form, the info gets saved into database and you redirect to the second page with the Paypal checkout button.

    This however has one problem:

    If they decide not to continue with the donation on the second page, their information will stay in the database and you don't know if they did or didn't donate without manually looking it up in Paypal account.

    So I recommend looking into IPN.

  3. #3
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I have the IPN system working. The problem is that it takes me to the paypal site. What I'd LIKE to do is create the form on my site and, behind the scenes, have paypal process it - never leaving my site. Shopping cart programs can do this, can I?

    1. user fills out form
    2. user clicks submit
    3. paypal processes it behind the scenes
    4. IPN validation message is sent back to my script
    5. I display appropriate message to user

  4. #4
    SitePoint Evangelist simshaun's Avatar
    Join Date
    Apr 2008
    Location
    North Carolina
    Posts
    438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes it is possible. Link

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,839
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    What I do where I have that situation is to have a form where I collect all the information I need to collect relating to the payment. I also generate an invoice number that gets saved to the database with the information and which is also passed into Paypal for Paypal to use for the payment processing. The invoice number in the saved data can then be matched to the invoice number of the Paypal payment in order to match the collected details to the payment.

    You can use an IPN script to update the existing database record that you saved with the payment details by matching on the invoice number.
    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 Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    What I do where I have that situation is to have a form where I collect all the information I need to collect relating to the payment. I also generate an invoice number that gets saved to the database with the information and which is also passed into Paypal for Paypal to use for the payment processing. The invoice number in the saved data can then be matched to the invoice number of the Paypal payment in order to match the collected details to the payment.

    You can use an IPN script to update the existing database record that you saved with the payment details by matching on the invoice number.
    Could you explain this a little further? I must not be looking in the right places. I've gone through the IPN docs and can only find one custom field ('custom') for passing data back and forth to paypal. Are you using a temporary table that holds the order information and then pass the invoice number via the custom field?

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,839
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by tgavin View Post
    Are you using a temporary table that holds the order information and then pass the invoice number via the custom field?
    No I am using the invoice field not the custom field. By using the invoice field all the Paypal info that is recorded uses the same invoice number as well.
    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="^$">

  8. #8
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    No I am using the invoice field not the custom field. By using the invoice field all the Paypal info that is recorded uses the same invoice number as well.
    OK, but where are you storing that info? If you insert it into the db and the transaction fails, what do you do? That's why I was asking about the temp table.

    I still don't understand about passing the transaction behind the scenes without having to go to paypal. I checked the link above, and already have a website payments pro account, which I'm using with the sandbox.

  9. #9
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,839
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    I have the insert process set up so that it also looks for any records in the table that were added over a week ago and which have not yet had a payment processed for them and delete those entries back out of the table. It is easier to do the cleanup when the next insert happens rather than having to set up a cron job to do the deletes.

    I also have the reporting set up so it just ignores any records from the table that don't have a payment attached.

    Just got an email now from Paypal regarding one record added via this process where Paypal expect to add the payment in about four days time (which is why I don't delete for a week since if I deleted that record now due to it having been added an hour or so ago and still doesn't have a payment attached then there would be no record for Paypal to update in four days time). If you expect to get lots of incomplete requests then you could add a pending flag to the database and flag pending records so as to be able to delete records not paid or pending after say two hours instead of waiting a week but unless you have a high volume of weekly entries it isn't going to make much difference.
    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="^$">

  10. #10
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good advice! Thanks

    After reading a little bit about website payments pro, I'm starting to think that I am going down the wrong path by using the IPN, and that I need to use the website payments pro API instead. Does that sound correct?


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
  •