Overview
  • Namespace
  • Class

Namespaces

  • PayPal
    • Api
    • Auth
    • Cache
    • Common
    • Converter
    • Core
    • Exception
    • Handler
    • Log
    • Rest
    • Security
    • Transport
    • Validation

Classes

  • PayPal\Api\Address
  • PayPal\Api\Agreement
  • PayPal\Api\AgreementDetails
  • PayPal\Api\AgreementStateDescriptor
  • PayPal\Api\AgreementTransaction
  • PayPal\Api\AgreementTransactions
  • PayPal\Api\AlternatePayment
  • PayPal\Api\Amount
  • PayPal\Api\Authorization
  • PayPal\Api\BankAccount
  • PayPal\Api\BankAccountsList
  • PayPal\Api\BankToken
  • PayPal\Api\BaseAddress
  • PayPal\Api\Billing
  • PayPal\Api\BillingAgreementToken
  • PayPal\Api\BillingInfo
  • PayPal\Api\CancelNotification
  • PayPal\Api\Capture
  • PayPal\Api\CarrierAccount
  • PayPal\Api\CarrierAccountToken
  • PayPal\Api\CartBase
  • PayPal\Api\ChargeModel
  • PayPal\Api\Cost
  • PayPal\Api\CountryCode
  • PayPal\Api\CreateProfileResponse
  • PayPal\Api\Credit
  • PayPal\Api\CreditCard
  • PayPal\Api\CreditCardHistory
  • PayPal\Api\CreditCardList
  • PayPal\Api\CreditCardToken
  • PayPal\Api\CreditFinancingOffered
  • PayPal\Api\Currency
  • PayPal\Api\CurrencyConversion
  • PayPal\Api\CustomAmount
  • PayPal\Api\DetailedRefund
  • PayPal\Api\Details
  • PayPal\Api\Error
  • PayPal\Api\ErrorDetails
  • PayPal\Api\ExtendedBankAccount
  • PayPal\Api\ExternalFunding
  • PayPal\Api\FileAttachment
  • PayPal\Api\FlowConfig
  • PayPal\Api\FmfDetails
  • PayPal\Api\FundingDetail
  • PayPal\Api\FundingInstrument
  • PayPal\Api\FundingOption
  • PayPal\Api\FundingSource
  • PayPal\Api\FuturePayment
  • PayPal\Api\HyperSchema
  • PayPal\Api\Image
  • PayPal\Api\Incentive
  • PayPal\Api\InputFields
  • PayPal\Api\InstallmentInfo
  • PayPal\Api\InstallmentOption
  • PayPal\Api\Invoice
  • PayPal\Api\InvoiceAddress
  • PayPal\Api\InvoiceItem
  • PayPal\Api\InvoiceNumber
  • PayPal\Api\InvoiceSearchResponse
  • PayPal\Api\Item
  • PayPal\Api\ItemList
  • PayPal\Api\Links
  • PayPal\Api\Measurement
  • PayPal\Api\MerchantInfo
  • PayPal\Api\MerchantPreferences
  • PayPal\Api\Metadata
  • PayPal\Api\NameValuePair
  • PayPal\Api\Notification
  • PayPal\Api\OpenIdAddress
  • PayPal\Api\OpenIdError
  • PayPal\Api\OpenIdSession
  • PayPal\Api\OpenIdTokeninfo
  • PayPal\Api\OpenIdUserinfo
  • PayPal\Api\Order
  • PayPal\Api\OverrideChargeModel
  • PayPal\Api\Participant
  • PayPal\Api\Patch
  • PayPal\Api\PatchRequest
  • PayPal\Api\Payee
  • PayPal\Api\Payer
  • PayPal\Api\PayerInfo
  • PayPal\Api\Payment
  • PayPal\Api\PaymentCard
  • PayPal\Api\PaymentCardToken
  • PayPal\Api\PaymentDefinition
  • PayPal\Api\PaymentDetail
  • PayPal\Api\PaymentExecution
  • PayPal\Api\PaymentHistory
  • PayPal\Api\PaymentInstruction
  • PayPal\Api\PaymentOptions
  • PayPal\Api\PaymentSummary
  • PayPal\Api\PaymentTerm
  • PayPal\Api\Payout
  • PayPal\Api\PayoutBatch
  • PayPal\Api\PayoutBatchHeader
  • PayPal\Api\PayoutItem
  • PayPal\Api\PayoutItemDetails
  • PayPal\Api\PayoutSenderBatchHeader
  • PayPal\Api\Phone
  • PayPal\Api\Plan
  • PayPal\Api\PlanList
  • PayPal\Api\PotentialPayerInfo
  • PayPal\Api\Presentation
  • PayPal\Api\PrivateLabelCard
  • PayPal\Api\ProcessorResponse
  • PayPal\Api\RecipientBankingInstruction
  • PayPal\Api\RedirectUrls
  • PayPal\Api\Refund
  • PayPal\Api\RefundDetail
  • PayPal\Api\RefundRequest
  • PayPal\Api\RelatedResources
  • PayPal\Api\Sale
  • PayPal\Api\Search
  • PayPal\Api\ShippingAddress
  • PayPal\Api\ShippingCost
  • PayPal\Api\ShippingInfo
  • PayPal\Api\Tax
  • PayPal\Api\Template
  • PayPal\Api\TemplateData
  • PayPal\Api\Templates
  • PayPal\Api\TemplateSettings
  • PayPal\Api\TemplateSettingsMetadata
  • PayPal\Api\Terms
  • PayPal\Api\Transaction
  • PayPal\Api\TransactionBase
  • PayPal\Api\Transactions
  • PayPal\Api\VerifyWebhookSignature
  • PayPal\Api\VerifyWebhookSignatureResponse
  • PayPal\Api\Webhook
  • PayPal\Api\WebhookEvent
  • PayPal\Api\WebhookEventList
  • PayPal\Api\WebhookEventType
  • PayPal\Api\WebhookEventTypeList
  • PayPal\Api\WebhookList
  • PayPal\Api\WebProfile
  • PayPal\Auth\OAuthTokenCredential
  • PayPal\Cache\AuthorizationCache
  • PayPal\Common\ArrayUtil
  • PayPal\Common\PayPalModel
  • PayPal\Common\PayPalResourceModel
  • PayPal\Common\PayPalUserAgent
  • PayPal\Common\ReflectionUtil
  • PayPal\Converter\FormatConverter
  • PayPal\Core\PayPalConfigManager
  • PayPal\Core\PayPalConstants
  • PayPal\Core\PayPalCredentialManager
  • PayPal\Core\PayPalHttpConfig
  • PayPal\Core\PayPalHttpConnection
  • PayPal\Core\PayPalLoggingManager
  • PayPal\Handler\OauthHandler
  • PayPal\Handler\RestHandler
  • PayPal\Log\PayPalDefaultLogFactory
  • PayPal\Log\PayPalLogger
  • PayPal\Rest\ApiContext
  • PayPal\Security\Cipher
  • PayPal\Transport\PayPalRestCall
  • PayPal\Validation\ArgumentValidator
  • PayPal\Validation\JsonValidator
  • PayPal\Validation\NumericValidator
  • PayPal\Validation\UrlValidator

Interfaces

  • PayPal\Handler\IPayPalHandler
  • PayPal\Log\PayPalLogFactory
  • PayPal\Rest\IResource

Exceptions

  • PayPal\Exception\PayPalConfigurationException
  • PayPal\Exception\PayPalConnectionException
  • PayPal\Exception\PayPalInvalidCredentialException
  • PayPal\Exception\PayPalMissingCredentialException
  1 <?php
  2 
  3 namespace PayPal\Core;
  4 
  5 use PayPal\Exception\PayPalConfigurationException;
  6 
  7 /**
  8  * Class PayPalHttpConfig
  9  * Http Configuration Class
 10  *
 11  * @package PayPal\Core
 12  */
 13 class PayPalHttpConfig
 14 {
 15     /**
 16      * Some default options for curl
 17      * These are typically overridden by PayPalConnectionManager
 18      *
 19      * @var array
 20      */
 21     public static $defaultCurlOptions = array(
 22         CURLOPT_SSLVERSION => 6,
 23         CURLOPT_CONNECTTIMEOUT => 10,
 24         CURLOPT_RETURNTRANSFER => true,
 25         CURLOPT_TIMEOUT => 60,    // maximum number of seconds to allow cURL functions to execute
 26         CURLOPT_USERAGENT => 'PayPal-PHP-SDK',
 27         CURLOPT_HTTPHEADER => array(),
 28         CURLOPT_SSL_VERIFYHOST => 2,
 29         CURLOPT_SSL_VERIFYPEER => 1,
 30         CURLOPT_SSL_CIPHER_LIST => 'TLSv1:TLSv1.2'
 31         //Allowing TLSv1 cipher list.
 32         //Adding it like this for backward compatibility with older versions of curl
 33     );
 34 
 35     const HEADER_SEPARATOR = ';';
 36     const HTTP_GET = 'GET';
 37     const HTTP_POST = 'POST';
 38 
 39     private $headers = array();
 40 
 41     private $curlOptions;
 42 
 43     private $url;
 44 
 45     private $method;
 46 
 47     /***
 48      * Number of times to retry a failed HTTP call
 49      */
 50     private $retryCount = 0;
 51 
 52     /**
 53      * Default Constructor
 54      *
 55      * @param string $url
 56      * @param string $method HTTP method (GET, POST etc) defaults to POST
 57      * @param array $configs All Configurations
 58      */
 59     public function __construct($url = null, $method = self::HTTP_POST, $configs = array())
 60     {
 61         $this->url = $url;
 62         $this->method = $method;
 63         $this->curlOptions = $this->getHttpConstantsFromConfigs($configs, 'http.') + self::$defaultCurlOptions;
 64         // Update the Cipher List based on OpenSSL or NSS settings
 65         $curl = curl_version();
 66         $sslVersion = isset($curl['ssl_version']) ? $curl['ssl_version'] : '';
 67         if($sslVersion && substr_compare($sslVersion, "NSS/", 0, strlen("NSS/")) === 0) {
 68             //Remove the Cipher List for NSS
 69             $this->removeCurlOption(CURLOPT_SSL_CIPHER_LIST);
 70         }
 71     }
 72 
 73     /**
 74      * Gets Url
 75      *
 76      * @return null|string
 77      */
 78     public function getUrl()
 79     {
 80         return $this->url;
 81     }
 82 
 83     /**
 84      * Gets Method
 85      *
 86      * @return string
 87      */
 88     public function getMethod()
 89     {
 90         return $this->method;
 91     }
 92 
 93     /**
 94      * Gets all Headers
 95      *
 96      * @return array
 97      */
 98     public function getHeaders()
 99     {
100         return $this->headers;
101     }
102 
103     /**
104      * Get Header by Name
105      *
106      * @param $name
107      * @return string|null
108      */
109     public function getHeader($name)
110     {
111         if (array_key_exists($name, $this->headers)) {
112             return $this->headers[$name];
113         }
114         return null;
115     }
116 
117     /**
118      * Sets Url
119      *
120      * @param $url
121      */
122     public function setUrl($url)
123     {
124         $this->url = $url;
125     }
126 
127     /**
128      * Set Headers
129      *
130      * @param array $headers
131      */
132     public function setHeaders(array $headers = array())
133     {
134         $this->headers = $headers;
135     }
136 
137     /**
138      * Adds a Header
139      *
140      * @param      $name
141      * @param      $value
142      * @param bool $overWrite allows you to override header value
143      */
144     public function addHeader($name, $value, $overWrite = true)
145     {
146         if (!array_key_exists($name, $this->headers) || $overWrite) {
147             $this->headers[$name] = $value;
148         } else {
149             $this->headers[$name] = $this->headers[$name] . self::HEADER_SEPARATOR . $value;
150         }
151     }
152 
153     /**
154      * Removes a Header
155      *
156      * @param $name
157      */
158     public function removeHeader($name)
159     {
160         unset($this->headers[$name]);
161     }
162 
163     /**
164      * Gets all curl options
165      *
166      * @return array
167      */
168     public function getCurlOptions()
169     {
170         return $this->curlOptions;
171     }
172 
173     /**
174      * Add Curl Option
175      *
176      * @param string $name
177      * @param mixed  $value
178      */
179     public function addCurlOption($name, $value)
180     {
181         $this->curlOptions[$name] = $value;
182     }
183 
184     /**
185      * Removes a curl option from the list
186      *
187      * @param $name
188      */
189     public function removeCurlOption($name)
190     {
191         unset($this->curlOptions[$name]);
192     }
193 
194     /**
195      * Set Curl Options. Overrides all curl options
196      *
197      * @param $options
198      */
199     public function setCurlOptions($options)
200     {
201         $this->curlOptions = $options;
202     }
203 
204     /**
205      * Set ssl parameters for certificate based client authentication
206      *
207      * @param      $certPath
208      * @param null $passPhrase
209      */
210     public function setSSLCert($certPath, $passPhrase = null)
211     {
212         $this->curlOptions[CURLOPT_SSLCERT] = realpath($certPath);
213         if (isset($passPhrase) && trim($passPhrase) != "") {
214             $this->curlOptions[CURLOPT_SSLCERTPASSWD] = $passPhrase;
215         }
216     }
217 
218     /**
219      * Set connection timeout in seconds
220      *
221      * @param integer $timeout
222      */
223     public function setHttpTimeout($timeout)
224     {
225         $this->curlOptions[CURLOPT_CONNECTTIMEOUT] = $timeout;
226     }
227 
228     /**
229      * Set HTTP proxy information
230      *
231      * @param string $proxy
232      * @throws PayPalConfigurationException
233      */
234     public function setHttpProxy($proxy)
235     {
236         $urlParts = parse_url($proxy);
237         if ($urlParts == false || !array_key_exists("host", $urlParts)) {
238             throw new PayPalConfigurationException("Invalid proxy configuration " . $proxy);
239         }
240         $this->curlOptions[CURLOPT_PROXY] = $urlParts["host"];
241         if (isset($urlParts["port"])) {
242             $this->curlOptions[CURLOPT_PROXY] .= ":" . $urlParts["port"];
243         }
244         if (isset($urlParts["user"])) {
245             $this->curlOptions[CURLOPT_PROXYUSERPWD] = $urlParts["user"] . ":" . $urlParts["pass"];
246         }
247     }
248 
249     /**
250      * Set Http Retry Counts
251      *
252      * @param int $retryCount
253      */
254     public function setHttpRetryCount($retryCount)
255     {
256         $this->retryCount = $retryCount;
257     }
258 
259     /**
260      * Get Http Retry Counts
261      *
262      * @return int
263      */
264     public function getHttpRetryCount()
265     {
266         return $this->retryCount;
267     }
268 
269     /**
270      * Sets the User-Agent string on the HTTP request
271      *
272      * @param string $userAgentString
273      */
274     public function setUserAgent($userAgentString)
275     {
276         $this->curlOptions[CURLOPT_USERAGENT] = $userAgentString;
277     }
278 
279     /**
280      * Retrieves an array of constant key, and value based on Prefix
281      *
282      * @param array $configs
283      * @param       $prefix
284      * @return array
285      */
286     public function getHttpConstantsFromConfigs($configs = array(), $prefix)
287     {
288         $arr = array();
289         if ($prefix != null && is_array($configs)) {
290             foreach ($configs as $k => $v) {
291                 // Check if it startsWith
292                 if (substr($k, 0, strlen($prefix)) === $prefix) {
293                     $newKey = ltrim($k, $prefix);
294                     if (defined($newKey)) {
295                         $arr[constant($newKey)] = $v;
296                     }
297                 }
298             }
299         }
300         return $arr;
301     }
302 }
303 
API documentation generated by ApiGen