diff --git a/src/Api.php b/src/Api.php index 372ba87a..3a43558d 100644 --- a/src/Api.php +++ b/src/Api.php @@ -35,7 +35,15 @@ public function setHeader($header, $value) { Request::addHeader($header, $value); } - + + /* + * Set Options + */ + public function addRequestOptions($key, $value) + { + Request::addRequestOptions($key, $value); + } + public function setAppDetails($title, $version = null) { $app = array( diff --git a/src/Request.php b/src/Request.php index 78ea5919..68b767e4 100644 --- a/src/Request.php +++ b/src/Request.php @@ -29,6 +29,14 @@ class Request 'Razorpay-API' => 1 ); + /** + * Headers to be sent with every http request to the API + * @var array + */ + protected static $options = array( + 'timeout' => 60, + ); + /** * Fires a request to the API * @param string $method HTTP Verb @@ -46,20 +54,30 @@ public function request($method, $url, $data = array()) $hooks->register('curl.before_send', array($this, 'setCurlSslOpts')); - $options = array( + $opts = array_merge(self::$options,array( 'auth' => array(Api::getKey(), Api::getSecret()), - 'hook' => $hooks, - 'timeout' => 60 - ); + 'hook' => $hooks + )); $headers = $this->getRequestHeaders(); - $response = Requests::request($url, $headers, $data, $method, $options); + $response = Requests::request($url, $headers, $data, $method, $opts); $this->checkErrors($response); return json_decode($response->body, true); } + /** + * Adds an additional header to all API requests + * @param string $key Header key + * @param string|array $value Header value + * @return null + */ + public static function addRequestOptions($key, $value) + { + self::$options[$key] = $value; + } + public function setCurlSslOpts($curl) { curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_1);