User management for the world wide web

Main Page | Alphabetical List | Class List | File List | Class Members

PayPal Class Reference

For all your programming needs contact:. More...

List of all members.

Public Member Functions

 PayPal ()
 Basic no-arg constructor.

 log_file ($filename=FALSE)
 Set the log file for output, if you set this, information will be sent to the log file.

 logit ($level, $message)
 Logs a message.

 status_completed ()
 Transaction/Payment completed.

 status_pending ()
 Pending.

 status_cancel_reverse ()
 Won a dispute.

 status_denied ()
 Merchant denied payment.

 status_failed ()
 Transaction failed.

 status_refunded ()
 Merchant refunded payment.

 status_reversed ()
 Charges reversed.

 debug_response ($filename)
 Use this to "fake" a VALID/INVALID response from paypal, for debugging purposes.

 paypal_host ($timeout=45, $host="www.paypal.com", $port=80)
 Set the host that will be contacted for payment corroboration.

 connect_paypal ()
 Perform a connection to paypals website.

 test_form ($form_tags=TRUE)
 Generate a testing form.

 processIPN ()
 The Grand-Daddy method, this is the actor..

 errstr ($code)
 Fetch a string that tells what the returned error code from processIPN means.

 check_amount ($item_no, $amount, $currency)
 Check that the amount/currency is correct for item_id.

 check_txn_id ($id)
 Check txn_id has not already been used.

 check_email ($email)
 Check email address for validity.


Detailed Description

For all your programming needs contact:.

http://www.geniegate.com/es_contact.php

Friendly -/- Decent Rates -/- Decent Quality

Java -/- Perl -/- PHP -/- XML -/- Databases -/- UNIX

This is a base-class IPN handler for PayPal. It does nothing on it's own except provide a skeleton class to be derived from. It's not GenieGate specific in any way. It provides a more "object oriented" approach to paypal IPN using handlers. This generic approach makes it usable by GenieGate, but can be also used anywhere someone requires paypal support. (Shopping carts, download areas, etc..)

The general idea is to inherit from this class, provide the methods you are interested in. (such as check_txn_id, check_email, check_amount)

Populate your class with configuration, database connections, or other resources/initialization as required in your unique situation.

In general, you shouldn't modify this file. Create your own class file and *inherit* from this one, (using extends)

Call processIPN() to actually process a paypal IPN. This will invoke your custom, application specific methods. The return value from proceessIPN() will < 0 on failure. If it is <0 use the errstr() to report the cause. (and/or override logit() to store the logs)

-/- Testing and debugging -/-

It provides debugging support in which to test your "handler class" by way of a generic form.

The debug support also allows one to use a file in place of the response from paypal's web site. This is useful for running lots of tests that aren't really paypal centric, or testing on an intranet without a public IP number prior to hammering paypals web site. (although you should use paypals web site to do your final testing)

Call the log_file() method with a filename to log diagnostic information. Nothing is logged unless you do this. (and/or override logit() to send this information in email, etc..)

-/- Legal dogma and fine print. -/-

Copyright (C) Jamie Hoglund 2004. All rights reserved.

Feel free to use this file. An advertisement link in the form of User Management is always appreciated, but not required for using this paypal IPN class. (Note that the ad link *IS* required for using free versions of GenieGate, this class is not GeniGate and does not fall under that restriction)

This class may not be used as part of another product which is offered for resale. It is for personal (or single business) use only. Please use the contact form at http://www.geniegate.com/contact.php if there are any questions or comments. (Hint: my main concern is that I don't want a competitor to use it against me.)

** Use at your own risk **

I neither claim nor do I accept any responsibility for any hardships it may cause anyone. There is no warranty expressed or implied. Use at your own risk.

If it should happen to cause hardships or problems, or if you are having difficulty with it, I would appreciate hearing from you. Any contact we may have does NOT constitute, imply or otherwise indicate any acceptance of liability.

-------------------------------------------------------------------

Definition at line 81 of file PayPal.php.


Constructor & Destructor Documentation

PayPal  ) 
 

Basic no-arg constructor.

Definition at line 114 of file PayPal.php.


Member Function Documentation

check_amount item_no,
amount,
currency
 

Check that the amount/currency is correct for item_id.

You should override this method to ensure the amount is correct.

Parameters:
$item_no - The item number.
$amount - Same as mc_gross, the amount being paid.
$currency - Currency code that amount is in.
Returns:
TRUE / FALSE.

Definition at line 458 of file PayPal.php.

References logit().

Referenced by processIPN().

check_email email  ) 
 

Check email address for validity.

Override this method to make sure you are the one being paid.

Parameters:
$email - The email who is about to recieve payment.
Returns:
TRUE/FALSE

Definition at line 482 of file PayPal.php.

References logit().

Referenced by processIPN().

check_txn_id id  ) 
 

Check txn_id has not already been used.

Override this method to ensure txn_id is not a duplicate.

Parameters:
$id - The transaction ID from paypal.
Returns:
TRUE/FALSE.

Definition at line 470 of file PayPal.php.

References logit().

Referenced by processIPN().

connect_paypal  ) 
 

Perform a connection to paypals website.

Must return a resource pointer to a socket or handle. See debug_response() for a technique to debug using a fake response from paypal, see paypal_host() to set the timeout,host,port details.

Definition at line 245 of file PayPal.php.

References errstr(), and logit().

Referenced by processIPN().

debug_response filename  ) 
 

Use this to "fake" a VALID/INVALID response from paypal, for debugging purposes.

Set the filename to be used for debugging, if set, it should be a filename that contains the headers and such that would be returned by paypal's web site.

Obvious Note: Don't use this on a production system..

Definition at line 226 of file PayPal.php.

errstr code  ) 
 

Fetch a string that tells what the returned error code from processIPN means.

(Use for logging or error reporting)

Parameters:
$code - Numeric code that represents an error. (Must be negative)

Definition at line 443 of file PayPal.php.

Referenced by connect_paypal().

log_file filename = FALSE  ) 
 

Set the log file for output, if you set this, information will be sent to the log file.

Definition at line 121 of file PayPal.php.

logit level,
message
 

Logs a message.

Override this method to be notified of Errors,Info or Debug messages. (Can also use log_file() to simply store them in a file some place)

Parameters:
$level - One of I,D,E
$message - Text of message to be logged.

Definition at line 137 of file PayPal.php.

Referenced by check_amount(), check_email(), check_txn_id(), connect_paypal(), processIPN(), status_cancel_reverse(), status_completed(), status_denied(), status_failed(), status_pending(), status_refunded(), and status_reversed().

paypal_host timeout = 45,
host = "www.paypal.com",
port = 80
 

Set the host that will be contacted for payment corroboration.

Normally, this is 45,www.paypal.com,80

Definition at line 233 of file PayPal.php.

processIPN  ) 
 

The Grand-Daddy method, this is the actor..

returns > -1 on success, or one of the following codes for an error

-1 - Socket problem. -2 - check_email() failed. -3 - txn_id is a duplicate. -4 - check_amount() failed. -5 - payment_status not recognized. -6 - INVALID response. -7 - The status_* method. didn't return TRUE. -8 - Neither VERIFIED nor INVALID were found in paypal response.

Use errstr() for a brief sentance explaining the error.

Returns:
error code or zero if no error.

Definition at line 353 of file PayPal.php.

References check_amount(), check_email(), check_txn_id(), connect_paypal(), and logit().

status_cancel_reverse  ) 
 

Won a dispute.

return TRUE - All went OK.

Definition at line 180 of file PayPal.php.

References logit().

status_completed  ) 
 

Transaction/Payment completed.

This is typically the only method you'll need to override to perform some sort of action when a successful transaction has been completed.

You could override the other status's (such as reverse or denied) to reverse whatever was done, but that could interfere if you're denying a payment or refunding someone for a good reason. In those cases, it's probably best to simply do whatever steps are required manually.

Returns:
TRUE - All went OK.

Definition at line 162 of file PayPal.php.

References logit().

status_denied  ) 
 

Merchant denied payment.

Returns:
TRUE - All went OK.

Definition at line 188 of file PayPal.php.

References logit().

status_failed  ) 
 

Transaction failed.

return TRUE - All went OK.

Definition at line 196 of file PayPal.php.

References logit().

status_pending  ) 
 

Pending.

Need to do something else? Look at $_POST[pending_reason].

Returns:
TRUE - All went OK.

Definition at line 172 of file PayPal.php.

References logit().

status_refunded  ) 
 

Merchant refunded payment.

Returns:
TRUE - All went OK.

Definition at line 204 of file PayPal.php.

References logit().

status_reversed  ) 
 

Charges reversed.

Returns:
TRUE - All went OK.

Definition at line 212 of file PayPal.php.

References logit().

test_form form_tags = TRUE  ) 
 

Generate a testing form.

The form is useful for debugging your handler class.

Use test_form(FALSE) to create just the input variables. (this is useful if you are using more than the basics presented here)

Definition at line 269 of file PayPal.php.


The documentation for this class was generated from the following file:
DoxyGen Documentation generated by DoxyGen