PDA

View Full Version : Integrating Paypal


jabbic
01-14-2006, 12:23 PM
Could anyone help me integrate paypal into my user signup script or suggest a tutorial.

Thanks :)

mr_ego
01-14-2006, 01:49 PM
Integrating Paypal into a website is usually a little bit of a skilled task. Here's some general recommendations that I would make (about how I would go about using Paypal in my scripts).



TIP ONE:
Using a database, store the session information (regardless of whether or not they've signed up).

For Example:

TABLE: sessions
FIELDS:
session_id [VARCHAR 32],
session_ip [VARCHAR 11],
session_expire [DATETIME],
user_id [NULL]

If the user has not logged in, the user_id field would be of NULL value.
Example:

a8648bfef79d99398fe999349cedf344
1411454150
2006-01-25 01:11:03
NULL


a8648bfef79d99398fe999349cedf345
1411454153
2006-01-25 01:11:03
45949

a8648bfef79d99398fe999349cedf346
1411454151
2006-01-25 01:11:03
1

TIP TWO:
Store the information about what they are purchasing in a table (for example, if it's one premium or platnum membership). This will act as a quote for Paypal.

TABLE: sessions_quotes
FIELDS:
session_id [VARCHAR 32],
order_line [SMALLINT],
line_summary [VARCHAR 127],
line_unit [DECIMAL],
line_qty [TINYINT],
line_cost [DECIMAL]

a8648bfef79d99398fe999349cedf344
1
MEMBERSHIP COST
10.00
1
10.00

WHY THIS WORKS:
This works because all the information you need to know about the order is stored in YOUR database, that way, all you have to send to paypal is: the "session_id" that you're using for this person, and the "total cost" (with a label of "purchases").

It works really well because if someone tries to jib you (hypothetically) and tries to pay $0.01 instead of $100.00 for an item (or for membership), you've got their session information on file and you know how much they're supposed to pay. This way, they've basically "donated" money to you, and they're not paying off their bill.

WHY THIS COULD BE MESSY:
This could get a little messy because your session information (if not cleared out properly/regularly) could clutter up and you'd have many lines of meaningless information. A basic but really easy thing to do would be to write and SQL statement that gets executed every time a page loads:


DELETE FROM sessions WHERE session_expire < Now() ....
DELETE FROM sessions_quotes WHERE session_id NOT IN (SELECT ... ) ... (etc)

(Also remember that only MySQL MaxDB supports the IN statement).

You would also have to keep in mind that certain people could signup for two accounts in one session (hypothetically). How could you handle this?

Also, make sure you're sending the right amount of monies owed to paypal. This way they can't say to you "well hey, i payed $50.10" when the actual price is "$50.50" because of a calculation error in your database. It's best to store the amount they owe you (in total for the whole bill) in your database.

HOW THIS COULD BE IMPROVED:
You could (hypothetically) make it so people pay a subscription for entry to your website. All of this information would be stored in your database and (providing you kept your session information passing through correctly) you can use this method to keep people doing recursive payments.



Hope this helps.


Remember this is a very simplified version of what you *should* be doing, it's probably not the 100% best approach, but you know. Whatever floats your boat.

If anyone has any ideas for this, I'd love to hear them.

jabbic
01-14-2006, 03:42 PM
Ummm ok.

Velox Letum
01-14-2006, 06:54 PM
Mr_ego gave you a rather comprehensive overview of what you needed to do, and very well done. Google the Paypal IPN as well, they have PHP examples which you can tie in to this system mr_ego came up with.

felgall
01-14-2006, 09:38 PM
The way I came up with for my Paypal integration was to set up an IPN script that emails the purchased file to the buyer after confirming that the correct payment has been received. That way there is no information that needs to be stored in a database and it can handle echeck payments where the purchase takes up to a week to go through.