Skip to content

Commit c7ff91c

Browse files
authored
Merge pull request #26 from storefront-bvba/serverinfo
Added ServerInfo call
2 parents d080672 + 9854760 commit c7ff91c

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

src/Client/Server.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BTCPayServer\Client;
6+
7+
use BTCPayServer\Result\ServerInfo;
8+
9+
class Server extends AbstractClient
10+
{
11+
public function getInfo(): ServerInfo
12+
{
13+
$url = $this->getApiUrl() . 'server/info';
14+
$headers = $this->getRequestHeaders();
15+
$method = 'GET';
16+
$response = $this->getHttpClient()->request($method, $url, $headers);
17+
18+
if ($response->getStatus() === 200) {
19+
return new ServerInfo(json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR));
20+
} else {
21+
throw $this->getExceptionByStatusCode($method, $url, $response);
22+
}
23+
}
24+
}

src/Result/ServerInfo.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BTCPayServer\Result;
6+
7+
class ServerInfo extends AbstractResult
8+
{
9+
public function getVersion(): string
10+
{
11+
return $this->getData()['version'];
12+
}
13+
14+
/**
15+
* @return string
16+
*/
17+
public function getOnionUrl(): string
18+
{
19+
return $this->getData()['onion'];
20+
}
21+
22+
public function isFullySynced(): bool
23+
{
24+
return $this->getData()['fullySynched'];
25+
}
26+
27+
/**
28+
* @return string[] Example: ['BTC', 'BTC_LightningLike']
29+
*/
30+
public function getSupportedPaymentMethods(): array
31+
{
32+
return $this->getData()['supportedPaymentMethods'];
33+
}
34+
35+
// TODO add "syncStatus" structure
36+
}

0 commit comments

Comments
 (0)