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