|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace PhpLightning\Invoice; |
|
6
|
|
|
|
|
7
|
|
|
use Gacela\Framework\AbstractConfig; |
|
8
|
|
|
use PhpLightning\Shared\Value\SendableRange; |
|
9
|
|
|
use RuntimeException; |
|
10
|
|
|
|
|
11
|
|
|
final class InvoiceConfig extends AbstractConfig |
|
12
|
|
|
{ |
|
13
|
1 |
|
public function getCallback(): string |
|
14
|
|
|
{ |
|
15
|
1 |
|
return (string)$this->get('callback-url', 'undefined:callback-url'); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
2 |
|
public function getDefaultLnAddress(): string |
|
19
|
|
|
{ |
|
20
|
2 |
|
return sprintf('%s@%s', $this->getReceiver(), $this->getDomain()); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @return array<string,array> |
|
25
|
|
|
*/ |
|
26
|
2 |
|
public function getBackends(): array |
|
27
|
|
|
{ |
|
28
|
|
|
/** @psalm-suppress MixedReturnTypeCoercion */ |
|
29
|
2 |
|
return (array)$this->get('backends'); // @phpstan-ignore-line |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @return array{ |
|
|
|
|
|
|
34
|
|
|
* api_endpoint: string, |
|
35
|
|
|
* api_key: string, |
|
36
|
|
|
* } |
|
37
|
|
|
*/ |
|
38
|
2 |
|
public function getBackendOptionsFor(string $username): array |
|
39
|
|
|
{ |
|
40
|
|
|
/** @var array{api_endpoint?: string, api_key?: string} $result */ |
|
41
|
2 |
|
$result = $this->getBackends()[$username] ?? []; |
|
42
|
|
|
|
|
43
|
2 |
|
if (!isset($result['api_endpoint'], $result['api_key'])) { |
|
44
|
|
|
throw new RuntimeException('Missing backend options for ' . $username); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
2 |
|
return $result; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
2 |
|
public function getSendableRange(): SendableRange |
|
51
|
|
|
{ |
|
52
|
2 |
|
return $this->get('sendable-range', SendableRange::default()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
2 |
|
public function getDomain(): string |
|
56
|
|
|
{ |
|
57
|
2 |
|
return (string)$this->get('domain', $_SERVER['HTTP_HOST'] ?? 'localhost'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
2 |
|
private function getReceiver(): string |
|
61
|
|
|
{ |
|
62
|
2 |
|
return (string)$this->get('receiver', $_SERVER['REQUEST_URI'] ?? 'unknown-receiver'); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|