-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 170a3eb
Showing
6 changed files
with
2,587 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# lightning-strike-client-js | ||
|
||
PHP client for the Lightning Strike REST API. | ||
|
||
## Install | ||
|
||
```bash | ||
$ composer install blockstream/lightning-strike-client | ||
``` | ||
|
||
## Use | ||
|
||
```php | ||
<?php | ||
// initialize client | ||
$strike = new LightingStrikeClient('http://localhost:8009'); | ||
|
||
// create invoice | ||
$invoice = $strike->invoice(/*msatoshi*/ 50, /*metadata*/ [ 'customer' => 'Satoshi', 'products' => [ 'potato', 'chips' ]]); | ||
|
||
echo "to pay, send $invoice->msatoshi milli-satoshis with rhash $invoice->rhash, or copy the BOLT11 payment request: $invoice->payreq" | ||
|
||
// fetch invoice by id | ||
$invoice = $strike->fetch('m51vlVWuIKGumTLbJ1RPb'); | ||
``` | ||
|
||
## Test | ||
|
||
```bash | ||
$ STRIKE_URL=http://localhost:8009 phpunit test | ||
``` | ||
|
||
## License | ||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
require_once __DIR__.'/vendor/autoload.php'; | ||
|
||
class LightningStrikeClient { | ||
protected $api; | ||
|
||
public function __construct($url) { | ||
$this->api = new RestClient([ 'base_url' => $url, 'format' => 'json' ]); | ||
} | ||
|
||
public function invoice($msatoshi, $metadata=null) { | ||
$res = $this->api->post('/invoice', | ||
json_encode([ 'msatoshi' => $msatoshi, 'metadata' => $metadata ]), | ||
[ 'Content-Type' => 'application/json' ]); | ||
|
||
if ($res->info->http_code !== 201) | ||
throw new Exception('cannot create invoice'); | ||
|
||
return $res->decode_response(); | ||
} | ||
|
||
public function fetch($invoice_id) { | ||
$res = $this->api->get('/invoice/' . urlencode($invoice_id)); | ||
if ($res->info->http_code !== 200) | ||
throw new Exception('unable to fetch invoice'); | ||
return $res->decode_response(); | ||
} | ||
|
||
public function registerHook($invoice_id, $url) { | ||
$res = $this->api->post('/invoice/' . urlencode($invoice_id) . '/webhook', [ 'url' => $url ]); | ||
if ($res->info->http_code !== 201) | ||
throw new Exception('unable to register hook'); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "elementsproject/lightning-strike-client-php", | ||
"description": "PHP client for the Lightning Strike REST API", | ||
"license": "MIT", | ||
"repositories": [{ | ||
"type": "vcs", | ||
"url": "https://github.com/shesek/php-restclient.git" | ||
}], | ||
"require": { | ||
"tcdent/php-restclient": "dev-master" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^6.4", | ||
"clue/phar-composer": "^1.0" | ||
}, | ||
"autoload": { | ||
"files": ["client.php"] | ||
} | ||
} |
Oops, something went wrong.