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

Add missing query parameters to URL on CurlClient #46

Merged
merged 1 commit into from
Sep 2, 2022
Merged
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
19 changes: 18 additions & 1 deletion src/Util/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(string $baseUrl, int $timeout)
public function request(string $method, string $uri, array $options)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->baseUrl . $uri);
curl_setopt($curl, CURLOPT_URL, $this->buildUrl($uri, $options));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
Expand Down Expand Up @@ -55,6 +55,23 @@ public function request(string $method, string $uri, array $options)
return $curlResponse;
}

/**
* Build URL by prefixing endpoint with base URL and possible query parameters.
*
* @param string $uri
* @param array $options
* @return string
*/
private function buildUrl(string $uri, array $options): string
{
$query = '';
if (isset($options['query'])) {
$uri .= '?' . http_build_query($options['query']);
}

return $this->baseUrl . $uri . $query;
}

/**
* Parse Key => Value headers as Key: Value array for curl.
* @param $options
Expand Down
7 changes: 7 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,4 +562,11 @@ public function testGetSettlementsWithInvalidDateThrowsException()
$this->expectException(ValidationException::class);
$this->client->getSettlements('30.5.2022');
}

public function testGetGroupedPaymentProvidersAcceptsLanguageParameters()
{
$providers = $this->client->getGroupedPaymentProviders(100, 'EN');
$this->assertIsArray($providers);
$this->assertEquals('Mobile payment methods', $providers['groups'][0]['name']);
}
}