1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpLightning\Invoice\Domain\CallbackUrl; |
6
|
|
|
|
7
|
|
|
use PhpLightning\Invoice\Domain\Transfer\SendableRange; |
8
|
|
|
|
9
|
|
|
final class CallbackUrl implements CallbackUrlInterface |
10
|
|
|
{ |
11
|
|
|
private const TAG_PAY_REQUEST = 'payRequest'; |
12
|
|
|
|
13
|
3 |
|
public function __construct( |
14
|
|
|
private SendableRange $sendableRange, |
15
|
|
|
private string $lnAddress, |
16
|
|
|
private string $callback, |
17
|
|
|
) { |
18
|
3 |
|
} |
19
|
|
|
|
20
|
3 |
|
public function getCallbackUrl(): array |
21
|
|
|
{ |
22
|
|
|
// Modify the description if you want to custom it |
23
|
|
|
// This will be the description on the wallet that pays your ln address |
24
|
|
|
// TODO: Make this customizable from some external configuration file |
25
|
3 |
|
$description = 'Pay to ' . $this->lnAddress; |
26
|
|
|
|
27
|
|
|
// TODO: images not implemented yet; `',["image/jpeg;base64","' . base64_encode($response) . '"]';` |
28
|
3 |
|
$imageMetadata = ''; |
29
|
3 |
|
$metadata = '[["text/plain","' . $description . '"],["text/identifier","' . $this->lnAddress . '"]' . $imageMetadata . ']'; |
30
|
|
|
|
31
|
|
|
// payRequest json data, spec : https://github.com/lnurl/luds/blob/luds/06.md |
32
|
3 |
|
return [ |
33
|
3 |
|
'callback' => $this->callback, |
34
|
3 |
|
'maxSendable' => $this->sendableRange->max(), |
35
|
3 |
|
'minSendable' => $this->sendableRange->min(), |
36
|
3 |
|
'metadata' => $metadata, |
37
|
3 |
|
'tag' => self::TAG_PAY_REQUEST, |
38
|
3 |
|
'commentAllowed' => false, // TODO: Not implemented yet |
39
|
3 |
|
]; |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|