From 541f0e3e6fc96de768d1e69efde524ba186fed57 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 12 Sep 2022 13:33:32 +0530 Subject: [PATCH 1/2] added proxy support --- src/Api.php | 10 +++++++++- src/Request.php | 26 ++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) 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..3a163cf4 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,11 +54,10 @@ public function request($method, $url, $data = array()) $hooks->register('curl.before_send', array($this, 'setCurlSslOpts')); - $options = array( + $options = array_merge(self::$options,array( 'auth' => array(Api::getKey(), Api::getSecret()), - 'hook' => $hooks, - 'timeout' => 60 - ); + 'hook' => $hooks + )); $headers = $this->getRequestHeaders(); @@ -60,6 +67,17 @@ public function request($method, $url, $data = array()) 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); From 84f85906d9eef4676ce9cf9aafe678ffa7de376f Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 20 Sep 2022 14:43:23 +0530 Subject: [PATCH 2/2] change option variable name --- src/Request.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Request.php b/src/Request.php index 3a163cf4..68b767e4 100644 --- a/src/Request.php +++ b/src/Request.php @@ -54,14 +54,14 @@ public function request($method, $url, $data = array()) $hooks->register('curl.before_send', array($this, 'setCurlSslOpts')); - $options = array_merge(self::$options,array( + $opts = array_merge(self::$options,array( 'auth' => array(Api::getKey(), Api::getSecret()), '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);