diff --git a/php/PaypalIPN.php b/php/PaypalIPN.php index edc580e..28ec6a6 100644 --- a/php/PaypalIPN.php +++ b/php/PaypalIPN.php @@ -6,6 +6,8 @@ class PaypalIPN private $use_sandbox = false; /** @var bool Indicates if the local certificates are used. */ private $use_local_certs = true; + /** @var resource cURL session handle */ + private $curl_handler = null; /** Production Postback URL */ const VERIFY_URI = 'https://ipnpb.paypal.com/cgi-bin/webscr'; @@ -17,6 +19,19 @@ class PaypalIPN /** Response from PayPal indicating validation failed */ const INVALID = 'INVALID'; + /** + * Construct a PaypalIPN instance that will use the cURL session + * handle that you supply, as opposed to creating a new cURL session + * handle like the default constructor does. + * + * @param resource $curl_handler (optional) cURL session handle + * @return void + */ + public function __construct($curl_handler = null) + { + $this->curl_handler = $curl_handler; + } + /** * Sets the IPN verification to sandbox mode (for use when testing, * should not be enabled in production). @@ -96,7 +111,8 @@ public function verifyIPN() } // Post the data back to PayPal, using curl. Throw exceptions if errors occur. - $ch = curl_init($this->getPaypalUri()); + $ch = isset($this->curl_handler) ? $this->curl_handler : curl_init(); + curl_setopt($ch, CURLOPT_URL, $this->getPaypalUri()); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);