Passed
Push — main ( 36fa87...8ed71a )
by Chema
01:06 queued 13s
created

CallbackUrl::getCallbackUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 19
ccs 11
cts 11
cp 1
crap 1
rs 9.9332
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