Skip to content

Commit 4f8eff6

Browse files
authored
Merge pull request #15 from php-lightning/add-callback-url-to-config
partial change to make callback url user-configured
2 parents 5abd56f + c5d97bc commit 4f8eff6

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

lightning-config.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
->setDomain('your-domain.com')
1010
->setReceiver('custom-receiver')
1111
->setSendableRange(min: 100_000, max: 10_000_000_000)
12+
->setCallbackUrl('https://your-domain.com/path/to/index.php')
1213
->addBackend(
1314
(new LnBitsBackendConfig())
1415
->setApiEndpoint('http://localhost:5000')

src/Config/LightningConfig.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ final class LightningConfig implements JsonSerializable
1313
private ?string $domain = null;
1414
private ?string $receiver = null;
1515
private ?SendableRange $sendableRange = null;
16+
private ?string $callbackUrl = null;
1617
private ?BackendsConfig $backends = null;
1718

1819
public function setDomain(string $domain): self
@@ -34,6 +35,12 @@ public function setSendableRange(int $min, int $max): self
3435
return $this;
3536
}
3637

38+
public function setCallbackUrl(string $callbackUrl): self
39+
{
40+
$this->callbackUrl = $callbackUrl;
41+
return $this;
42+
}
43+
3744
public function addBackend(BackendConfigInterface $backendConfig): self
3845
{
3946
$this->backends ??= new BackendsConfig();
@@ -56,6 +63,9 @@ public function jsonSerialize(): array
5663
if ($this->sendableRange !== null) {
5764
$result['sendable-range'] = $this->sendableRange;
5865
}
66+
if ($this->callbackUrl !== null) {
67+
$result['callback-url'] = $this->callbackUrl;
68+
}
5969

6070
return $result;
6171
}

src/Invoice/InvoiceConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ final class InvoiceConfig extends AbstractConfig
1212
{
1313
public function getCallback(): string
1414
{
15-
return sprintf('https://%s/%s', $this->getDomain(), $this->getReceiver());
15+
return (string)$this->get('callback-url', 'undefined:callback-url');
1616
}
1717

1818
public function getLnAddress(): string

tests/Feature/LightningFeature.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function test_get_get_callback_url(): void
2626
$json = Lightning::getCallbackUrl();
2727

2828
self::assertEquals([
29-
'callback' => 'https://domain.com/receiver',
29+
'callback' => 'https://callback.url/receiver',
3030
'maxSendable' => 10_000,
3131
'minSendable' => 1_000,
3232
'metadata' => '[["text/plain","Pay to [email protected]"],["text/identifier","[email protected]"]]',
@@ -60,6 +60,7 @@ private function bootstrapGacela(): void
6060
$config->resetInMemoryCache();
6161
$config->addAppConfigKeyValues(
6262
(new LightningConfig())
63+
->setCallbackUrl('https://callback.url/receiver')
6364
->setDomain('domain.com')
6465
->setReceiver('receiver')
6566
->setSendableRange(1_000, 10_000)

0 commit comments

Comments
 (0)