1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpLightning\Invoice; |
6
|
|
|
|
7
|
|
|
use Gacela\Framework\AbstractFactory; |
8
|
|
|
use PhpLightning\Invoice\Domain\BackendInvoice\BackendInvoiceInterface; |
9
|
|
|
use PhpLightning\Invoice\Domain\BackendInvoice\LnbitsBackendInvoice; |
10
|
|
|
use PhpLightning\Invoice\Domain\CallbackUrl\CallbackUrl; |
11
|
|
|
use PhpLightning\Invoice\Domain\CallbackUrl\CallbackUrlInterface; |
12
|
|
|
use PhpLightning\Invoice\Domain\CallbackUrl\LnAddressGenerator; |
13
|
|
|
use PhpLightning\Invoice\Domain\CallbackUrl\LnAddressGeneratorInterface; |
14
|
|
|
use PhpLightning\Invoice\Domain\Http\HttpApiInterface; |
15
|
|
|
use PhpLightning\Invoice\Domain\LnAddress\InvoiceGenerator; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @method InvoiceConfig getConfig() |
19
|
|
|
*/ |
20
|
|
|
final class InvoiceFactory extends AbstractFactory |
21
|
|
|
{ |
22
|
|
|
public function createCallbackUrl(): CallbackUrlInterface |
23
|
|
|
{ |
24
|
|
|
return new CallbackUrl( |
25
|
|
|
$this->getConfig()->getSendableRange(), |
26
|
|
|
$this->createLnAddressGenerator(), |
27
|
|
|
$this->getConfig()->getCallback(), |
28
|
|
|
); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function createInvoiceGenerator(string $username): InvoiceGenerator |
32
|
|
|
{ |
33
|
|
|
return new InvoiceGenerator( |
34
|
|
|
$this->getBackendForUser($username), |
35
|
|
|
$this->getConfig()->getSendableRange(), |
36
|
|
|
$this->getConfig()->getDefaultLnAddress(), |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
private function createLnAddressGenerator(): LnAddressGeneratorInterface |
41
|
|
|
{ |
42
|
|
|
return new LnAddressGenerator( |
43
|
|
|
$this->getConfig()->getDefaultLnAddress(), |
44
|
|
|
$this->getConfig()->getDomain(), |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
private function getBackendForUser(string $username): BackendInvoiceInterface |
49
|
|
|
{ |
50
|
|
|
return new LnbitsBackendInvoice( |
51
|
|
|
$this->getHttpApi(), |
52
|
|
|
$this->getConfig()->getBackendOptionsFor($username), |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
private function getHttpApi(): HttpApiInterface |
57
|
|
|
{ |
58
|
|
|
return $this->getProvidedDependency(InvoiceDependencyProvider::HTTP_API); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|