Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added proxy as request options #208

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ 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(
Expand Down
33 changes: 30 additions & 3 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,11 +53,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,
);
));

$headers = $this->getRequestHeaders();

Expand All @@ -60,6 +67,26 @@ 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;
}

/**
* Returns all options attached so far
* @return array options
*/
protected function getRequestOptions()
Copy link
Contributor

Choose a reason for hiding this comment

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

@chiragkatare what is the use of this function ?

{
return self::$options;
}

public function setCurlSslOpts($curl)
{
curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_1);
Expand Down