From f2dab2455fcb6ea733913f09726455ac525725e3 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Tue, 24 Jul 2018 16:53:53 -0700 Subject: [PATCH 1/2] Update PHP to allow caller to set curl options Many production environments restrict outgoing network access on their servers that deal with payments, only allowing such access through proxies that vet the destinations before allowing access. This patch provides an option for the caller of verifyIPN() to provide the curl object for verifyIPN() to use instead of allocating its own curl object. This allows the caller to set any proxy options, or other options, that may be required in order to allow the connection back to Paypal to work. --- php/PaypalIPN.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/php/PaypalIPN.php b/php/PaypalIPN.php index edc580e..9904965 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 curl handler */ + private $curl_handler = null; /** Production Postback URL */ const VERIFY_URI = 'https://ipnpb.paypal.com/cgi-bin/webscr'; @@ -17,6 +19,11 @@ class PaypalIPN /** Response from PayPal indicating validation failed */ const INVALID = 'INVALID'; + 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 +103,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); From e6d223c0cf5de1be320c626417c73216590e25a2 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Wed, 25 Jul 2018 09:44:26 -0700 Subject: [PATCH 2/2] Add missing phpDocumentor comments for $curl_handler and __construct. --- php/PaypalIPN.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/php/PaypalIPN.php b/php/PaypalIPN.php index 9904965..28ec6a6 100644 --- a/php/PaypalIPN.php +++ b/php/PaypalIPN.php @@ -6,7 +6,7 @@ class PaypalIPN private $use_sandbox = false; /** @var bool Indicates if the local certificates are used. */ private $use_local_certs = true; - /** @var curl handler */ + /** @var resource cURL session handle */ private $curl_handler = null; /** Production Postback URL */ @@ -19,6 +19,14 @@ 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;