Skip to content
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
10 changes: 9 additions & 1 deletion src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
28 changes: 23 additions & 5 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(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Check this if static is required or not. Also test if values are getting overriden.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@ndhaka007 static keyword is required because when i removed static, I get this error
Warning: Undefined variable $options in /Applications/MAMP/htdocs/razorpay-php/src/Request.php on line 57

Fatal error: Uncaught TypeError: array_merge(): Argument #1 must be of type array, null given in /Applications/MAMP/htdocs/razorpay-php/src/Request.php:59

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@ndhaka007 also the timeout values are getting override
Screenshot 2022-09-20 at 1 32 35 PM

'timeout' => 60,
);

/**
* Fires a request to the API
* @param string $method HTTP Verb
Expand All @@ -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);
Expand Down