Skip to content
This repository has been archived by the owner on Jul 20, 2020. It is now read-only.

Update PHP to allow caller to set curl options #140

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion php/PaypalIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param resource $curl_handler (optional) cURL session handle
* @param resource|null $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).
Expand Down Expand Up @@ -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);
Expand Down