Download the PHP package stevethomas/paypal-ipn without Composer
On this page you can find all versions of the php package stevethomas/paypal-ipn. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download stevethomas/paypal-ipn
More information about stevethomas/paypal-ipn
Files in stevethomas/paypal-ipn
Package paypal-ipn
Short Description A composer compatible PHP >=5.3.0 PayPal IPN Listener.
License
Informations about the package paypal-ipn
PayPal IPN Listener 
A PayPal IPN (Instant Payment Notification) listener for PHP >=5.3.0. If you are looking for a < 5.3.0 compatible PayPal IPN Listener i highly recommend - https://github.com/Quixotix/PHP-PayPal-IPN (This package is heavily based around this).
Features
- Flexible, extensible, component based architecture
- Easily switch between sandbox and production mode
- Generate useful reports (request & response)
Prerequisites
- PHP >=5.3.0
- A good understanding of how the PayPal Instant Payment Notification system works. see https://cms.paypal.com/cms_content/US/en_US/files/developer/IPNGuide.pdf
- This package can be installed using composer or can be integrated manually. If you are not using an autoloader make sure you include all of the php files in the
src
directory.
Note: All of the code examples in the rest of this document assume you have the required files above included manually or autoloaded.
Architecture
This package is built out of a few components that work together:
Listener
- Listens for and processes the IPNRequest
- Communicates with PayPalResponse
- Handles response from PayPal
The request and response components are swappable. If you have a certain way you need to implement the request, or handle the response you can do this by extending the base classes: PayPal\Ipn\Request
and PayPal\Ipn\Response
.
PayPal\Ipn\Request
is abstract and must be extended.
By default 2 request components are provided:
PayPal\Ipn\Request\Curl
- sends the request to PayPal via CurlPayPal\Ipn\Request\Socket
- sends the request to PayPal via sockets (fsock)
1 response component is provided:
PayPal\Ipn\Response
- saves the HTTP status and body from the response from PayPal
Workflow
- Create an instance of the request component you want to use to communicate with PayPal. If you want to use a custom repsonse component, instantiate this first and pass to the request components constructor.
- Configure any properties required on the request component (set custom request properties etc.)
- Create an instance of the listener component and pass it the request component in its constructor.
- Configure any properties required on the listener component (set mode etc.)
- Get the listener component to verify the IPN by calling the
verifyIpn()
method. If the IPN is verified this method will return true, otherwise it will return false. This should be done in a try catch block as the listener or request components may throw exceptions. - You can use the method
getReport()
to get the details of the request and the response.
A report will look like:
You can switch between sandbox or production mode. You do this by calling setMode($mode)
on the listener component. Valid values for $mode
are sandbox
or production
. This will set where the request is made too (PayPals sandbox server or production server). Internally this calls the setHost()
method of the request component.
By default the mode is set to production
(this is done in the listener / request component constructor).
Creating Custom Request Components
To create a custom request component you must extend PayPal\Ipn\Request
as this has the base methods and properties that the listener component is dependent on. There is only 1 abstract method that needs to be implemented: send()
. This is the method that makes the request to PayPal.
Creating Custom Response Components
To create a custom response component you should extend PayPal\Ipn\Response
as this has the base methods and properties that the request component is dependent on. There are no abstract methods that need to be implemented, but any custom setters for for the statusCode
or body
must set the respective protected properties.
Using Custom Components
Request
Using your custom request component is as simple as
- create an instance of the component
- configure the component
- pass to the constructor of the listener component
Response
Using your custom response component is as simple as
- create an instance of the component
- configure the component
- pass to the constructor of the request component
Note: The request component constructor accepts 2 parameters: custom set of data and custom response object. For the request component to just use the data in the $_POST
array pass false (if passing a custom response). See notes below.
Notes
Data Source
By default the data in the $_POST
array will be used to verify the IPN. In some situations you may not have access to $_POST
(some frameworks unset this and use custom accessors). To get around this you can pass an array of data to the constructor of the request component:
Testing
PayPal provide an Instant Payment Notification (IPN) simulator here: https://developer.paypal.com/webapps/developer/applications/ipn_simulator
The simulator only tells you if the IPN was sent successfully. To get more information about the status of the IPN (what data was sent, what response it got etc.) you need to record this somewhere (use the listener components getStatus()
method and write to file somewhere etc).