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