1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpLightning\Invoice\Domain\CallbackUrl; |
6
|
|
|
|
7
|
|
|
use PhpLightning\Http\HttpFacadeInterface; |
8
|
|
|
|
9
|
|
|
final class CallbackUrl implements CallbackUrlInterface |
10
|
|
|
{ |
11
|
|
|
/** @var int 100 Minimum in msat (sat/1000) */ |
12
|
|
|
public const MIN_SENDABLE = 100_000; |
|
|
|
|
13
|
|
|
|
14
|
|
|
/** @var int 10 000 000 Max in msat (sat/1000) */ |
15
|
|
|
public const MAX_SENDABLE = 10_000_000_000; |
|
|
|
|
16
|
|
|
|
17
|
|
|
private const TAG_PAY_REQUEST = 'payRequest'; |
18
|
|
|
|
19
|
2 |
|
public function __construct( |
20
|
|
|
private HttpFacadeInterface $httpFacade, |
21
|
|
|
private string $lnAddress, |
22
|
|
|
private string $callback, |
23
|
|
|
) { |
24
|
2 |
|
} |
25
|
|
|
|
26
|
2 |
|
public function getCallbackUrl(string $imageFile = ''): array |
27
|
|
|
{ |
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
|
2 |
|
$description = 'Pay to ' . $this->lnAddress; |
32
|
|
|
|
33
|
2 |
|
$imageMetadata = $this->generateImageMetadata($imageFile); |
34
|
2 |
|
$metadata = '[["text/plain","' . $description . '"],["text/identifier","' . $this->lnAddress . '"]' . $imageMetadata . ']'; |
35
|
|
|
|
36
|
|
|
// payRequest json data, spec : https://github.com/lnurl/luds/blob/luds/06.md |
37
|
2 |
|
return [ |
38
|
2 |
|
'callback' => $this->callback, |
39
|
2 |
|
'maxSendable' => self::MAX_SENDABLE, |
40
|
2 |
|
'minSendable' => self::MIN_SENDABLE, |
41
|
2 |
|
'metadata' => $metadata, |
42
|
2 |
|
'tag' => self::TAG_PAY_REQUEST, |
43
|
2 |
|
'commentAllowed' => false, // TODO: Not implemented yet |
44
|
2 |
|
]; |
45
|
|
|
} |
46
|
|
|
|
47
|
2 |
|
private function generateImageMetadata(string $imageFile): string |
48
|
|
|
{ |
49
|
2 |
|
if ($imageFile === '') { |
50
|
2 |
|
return ''; |
51
|
|
|
} |
52
|
|
|
$response = $this->httpFacade->get($imageFile); |
53
|
|
|
if ($response === null) { |
54
|
|
|
return ''; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return ',["image/jpeg;base64","' . base64_encode($response) . '"]'; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|