From 2894f97184c765feecadcb9918bedf18c3f88d33 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Fri, 6 Dec 2024 17:41:43 +0100 Subject: [PATCH 1/2] Fix for invoices without expiry tag Signed-off-by: Djuri Baars --- src/Encoder/PaymentRequestDecoder.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Encoder/PaymentRequestDecoder.php b/src/Encoder/PaymentRequestDecoder.php index 757b443..4ce4844 100644 --- a/src/Encoder/PaymentRequestDecoder.php +++ b/src/Encoder/PaymentRequestDecoder.php @@ -167,9 +167,13 @@ public function decode(string $paymentRequest): array $timeExpireDate = $timeExpireDateString = null; if ($this->tagsContainItem($tags, $this->tagNames[6])) { $timeExpireDate = $timestamp + $this->tagsItems($tags, $this->tagNames[6]); - $timeExpireDateString = date(\DateTime::ATOM, $timeExpireDate); + } else { + // Default is 3600 (1 hour) if not specified. + $timeExpireDate = $timestamp + 3600; } + $timeExpireDateString = date(\DateTime::ATOM, $timeExpireDate); + $toSign = Buffertools::concat( new Buffer($prefix), $this->wordsToBuffer($wordsWithoutSignature, false), From 91c2c2989eff6680e0b8f03e3d26451ca86f148a Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Sat, 4 Jan 2025 14:52:15 +0100 Subject: [PATCH 2/2] Add test for invoices without expiry tag #12 --- tests/Encoder/PaymentRequestDecoderTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Encoder/PaymentRequestDecoderTest.php b/tests/Encoder/PaymentRequestDecoderTest.php index c045408..6b5cf53 100644 --- a/tests/Encoder/PaymentRequestDecoderTest.php +++ b/tests/Encoder/PaymentRequestDecoderTest.php @@ -49,6 +49,13 @@ protected function setUp(): void public function providerOfSuccessScenarios(): array { return [ + 'Invoice without expiry value' => [ + 'lnbc20u1pvjluezhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqspp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqfppqw508d6qejxtdg4y5r3zarvary0c5xw7ksp5m6kmam774klwlh4dhmhaatd7al02m0h0m6kmam774klwlh4dhmhs9qypqqqxqrrsscqpfck3fd5pdf7ermq4ajdr7eawzxzzspr8f2fqtw8kewj5f57l4uexxwgdy3xftzqm8a0yh7rnt6wsuzay8tqauq0cufzmamfu0y8zplhqpgpuvpj', + [ + 'prefix' => 'lnbc20u', + 'expiry_timestamp' => (1496314658 + 3600) + ], + ], 'Please make a donation of any amount using payment_hash 0001020304050607080900010203040506070809000102030405060708090102 to me @03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad' => [ 'lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ecky03ylcqca784w', [