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
7 changes: 7 additions & 0 deletions LiqPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function api($path, $params = array(), $timeout = 15)
if ($server_output == NULL) {
return array('error' => 'Invalid URL or connection timeout');
}
$this->_server_response_code = $this->curlRequester->get_response_code();
return json_decode($server_output);
}

Expand Down Expand Up @@ -292,6 +293,8 @@ public function str_to_sign($str)

class CurlRequester
{
private $_server_response_code;

/**
* make_curl_request
* @param $url string
Expand All @@ -317,5 +320,9 @@ public function make_curl_request($url, $postfields, $timeout = 15) {
}
return $server_output;
}

public function get_response_code() {
return $this->_server_response_code;
}
}

19 changes: 12 additions & 7 deletions tests/LiqPayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,18 @@ public function testGetResponseCode()
$privateKey = 'your_private_key';
$apiUrl = 'https://api.example.com';
$liqPay = new LiqPay($publicKey, $privateKey, $apiUrl);

// Set a value to _server_response_code for testing
$reflection = new ReflectionClass($liqPay);
$property = $reflection->getProperty('_server_response_code');
$property->setAccessible(true);
$property->setValue($liqPay, 200); // Example response code


// Mock CURL results
$mockCurlRequester = $this->createMock(CurlRequester::class);
$mockCurlRequester->expects($this->once())
->method('make_curl_request')
->willReturn('{"success":true}');
$mockCurlRequester->expects($this->once())
->method('get_response_code')
->willReturn(200);
$liqPay->curlRequester = $mockCurlRequester;

$liqPay->api('/testpath', ['version' => 3, 'action' => 'test']);
$responseCode = $liqPay->get_response_code();

$this->assertEquals(200, $responseCode);
Expand Down