Conditions | 2 |
Paths | 2 |
Total Lines | 25 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 20 |
CRAP Score | 2 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | 4 | public function requestInvoice(int $satsAmount, string $metadata = ''): InvoiceTransfer |
|
22 | { |
||
23 | 4 | $endpoint = $this->options['api_endpoint'] . '/api/v1/payments'; |
|
24 | |||
25 | 4 | $content = [ |
|
26 | 4 | 'out' => false, |
|
27 | 4 | 'amount' => $satsAmount, |
|
28 | 4 | 'unhashed_description' => bin2hex($metadata), |
|
29 | 4 | 'description_hash' => hash('sha256', $metadata), |
|
30 | 4 | ]; |
|
31 | |||
32 | 4 | $response = $this->httpApi->postRequestInvoice( |
|
33 | 4 | $endpoint, |
|
34 | 4 | body: json_encode($content, JSON_THROW_ON_ERROR), |
|
35 | 4 | headers: [ |
|
36 | 4 | 'Content-Type' => 'application/json', |
|
37 | 4 | 'X-Api-Key' => $this->options['api_key'], |
|
38 | 4 | ], |
|
39 | 4 | ); |
|
40 | |||
41 | 4 | if ($response === null) { |
|
42 | 1 | return new InvoiceTransfer(status: 'ERROR', error: 'Backend "LnBits" unreachable'); |
|
43 | 1 | } |
|
44 | 1 | ||
45 | return InvoiceTransfer::fromArray($response); |
||
46 | } |
||
48 |