From e9f27e12dc5eeb4717ddfde0fb6408576d0df385 Mon Sep 17 00:00:00 2001 From: "Jose M. Valera Reales" Date: Sun, 25 May 2025 14:28:10 +0200 Subject: [PATCH] refactor: unify invoice memo with description --- lightning-config.dist.php | 1 - src/Config/LightningConfig.php | 11 ----------- src/Invoice/Application/InvoiceGenerator.php | 3 +-- src/Invoice/InvoiceConfig.php | 5 ----- src/Invoice/InvoiceFactory.php | 1 - .../Domain/LnAddress/InvoiceGeneratorTest.php | 16 ++++++---------- 6 files changed, 7 insertions(+), 30 deletions(-) diff --git a/lightning-config.dist.php b/lightning-config.dist.php index 1ce8000..31cd26e 100644 --- a/lightning-config.dist.php +++ b/lightning-config.dist.php @@ -9,7 +9,6 @@ ->setReceiver('default-receiver') ->setDescriptionTemplate('Pay to %s') ->setSuccessMessage('Payment received!') - ->setInvoiceMemo('') ->setSendableRange(min: 100_000, max: 10_000_000_000) ->setCallbackUrl('localhost:8000/callback') ->addBackendsFile(getcwd() . DIRECTORY_SEPARATOR . 'nostr.json'); diff --git a/src/Config/LightningConfig.php b/src/Config/LightningConfig.php index 7b50481..4870405 100644 --- a/src/Config/LightningConfig.php +++ b/src/Config/LightningConfig.php @@ -18,7 +18,6 @@ final class LightningConfig implements JsonSerializable private ?string $callbackUrl = null; private ?string $descriptionTemplate = null; private ?string $successMessage = null; - private ?string $invoiceMemo = null; public function setDomain(string $domain): self { @@ -57,12 +56,6 @@ public function setSuccessMessage(string $message): self return $this; } - public function setInvoiceMemo(string $memo): self - { - $this->invoiceMemo = $memo; - return $this; - } - public function addBackendsFile(string $path): self { $this->backends ??= new BackendsConfig(); @@ -119,10 +112,6 @@ public function jsonSerialize(): array if ($this->successMessage !== null) { $result['success-message'] = $this->successMessage; } - if ($this->invoiceMemo !== null) { - $result['invoice-memo'] = $this->invoiceMemo; - } - return $result; } } diff --git a/src/Invoice/Application/InvoiceGenerator.php b/src/Invoice/Application/InvoiceGenerator.php index 4c3dbd1..b0471d7 100644 --- a/src/Invoice/Application/InvoiceGenerator.php +++ b/src/Invoice/Application/InvoiceGenerator.php @@ -19,7 +19,6 @@ public function __construct( private string $lnAddress, private string $descriptionTemplate, private string $successMessage, - private string $memo, ) { } @@ -37,7 +36,7 @@ public function generateInvoice(int $milliSats): array $imageMetadata = ''; $metadata = '[["text/plain","' . $description . '"],["text/identifier","' . $this->lnAddress . '"]' . $imageMetadata . ']'; - $invoice = $this->backendInvoice->requestInvoice((int)($milliSats / 1000), $metadata, $this->memo); + $invoice = $this->backendInvoice->requestInvoice((int)($milliSats / 1000), $metadata, $description); return $this->mapResponseAsArray($invoice); } diff --git a/src/Invoice/InvoiceConfig.php b/src/Invoice/InvoiceConfig.php index 11766ec..3342419 100644 --- a/src/Invoice/InvoiceConfig.php +++ b/src/Invoice/InvoiceConfig.php @@ -64,11 +64,6 @@ public function getSuccessMessage(): string return (string)$this->get('success-message', 'Payment received!'); } - public function getInvoiceMemo(): string - { - return (string)$this->get('invoice-memo', ''); - } - public function getDomain(): string { return (string)$this->get('domain', $_SERVER['HTTP_HOST'] ?? 'localhost'); diff --git a/src/Invoice/InvoiceFactory.php b/src/Invoice/InvoiceFactory.php index 3418d45..8e84734 100644 --- a/src/Invoice/InvoiceFactory.php +++ b/src/Invoice/InvoiceFactory.php @@ -41,7 +41,6 @@ public function createInvoiceGenerator(string $username): InvoiceGenerator $this->getConfig()->getDefaultLnAddress(), $this->getConfig()->getDescriptionTemplate(), $this->getConfig()->getSuccessMessage(), - $this->getConfig()->getInvoiceMemo(), ); } diff --git a/tests/Unit/Invoice/Domain/LnAddress/InvoiceGeneratorTest.php b/tests/Unit/Invoice/Domain/LnAddress/InvoiceGeneratorTest.php index d08c772..e1a72c0 100644 --- a/tests/Unit/Invoice/Domain/LnAddress/InvoiceGeneratorTest.php +++ b/tests/Unit/Invoice/Domain/LnAddress/InvoiceGeneratorTest.php @@ -22,8 +22,7 @@ public function test_invalid_amount(): void SendableRange::withMinMax(1_000, 3_000), 'ln@address', 'Pay to %s', - 'Payment received!', - '', + 'Payment received!' ); $actual = $invoice->generateInvoice(100); @@ -44,8 +43,7 @@ public function test_unknown_backend(): void SendableRange::withMinMax(1_000, 3_000), 'ln@address', 'Pay to %s', - 'Payment received!', - '', + 'Payment received!' ); $actual = $invoice->generateInvoice(2_000); @@ -74,8 +72,7 @@ public function test_successful_payment_request_with_amount(): void SendableRange::withMinMax(1_000, 3_000), 'ln@address', 'Pay to %s', - 'Payment received!', - '', + 'Payment received!' ); $actual = $invoice->generateInvoice(2_000); @@ -93,12 +90,12 @@ public function test_successful_payment_request_with_amount(): void ], $actual); } - public function test_passes_memo_to_backend(): void + public function test_passes_description_as_memo_to_backend(): void { $backend = $this->createMock(BackendInvoiceInterface::class); $backend->expects(self::once()) ->method('requestInvoice') - ->with(2, $this->anything(), 'Custom memo') + ->with(2, $this->anything(), 'Pay to ln@address') ->willReturn(new InvoiceTransfer()); $invoice = new InvoiceGenerator( @@ -106,8 +103,7 @@ public function test_passes_memo_to_backend(): void SendableRange::withMinMax(1_000, 3_000), 'ln@address', 'Pay to %s', - 'Payment received!', - 'Custom memo', + 'Payment received!' ); $invoice->generateInvoice(2_000);