Skip to content

Commit

Permalink
Pass-through all properties when creating invoices.
Browse files Browse the repository at this point in the history
To support the new `currency` and `amount` fields added in
ElementsProject/lightning-charge@4f4b1d5
  • Loading branch information
shesek committed Nov 19, 2017
1 parent c4351aa commit 2f68f51
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# lightning-strike-client-js
# lightning-strike-client-php

PHP client for the Lightning Strike REST API.

Expand All @@ -15,12 +15,15 @@ $ composer require elementsproject/lightning-strike-client-php
$strike = new LightingStrikeClient('http://localhost:8009');

// Create invoice
$invoice = $strike->invoice(/*msatoshi*/ 50, /*metadata*/ [ 'customer' => 'Satoshi', 'products' => [ 'potato', 'chips' ]]);
$invoice = $strike->invoice([ 'msatoshi' => 50, 'metadata' => [ 'customer' => 'Satoshi', 'products' => [ 'potato', 'chips' ] ] ]);

tell_user("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');

// Create invoice denominated in USD
$invoice = $strike->invoice([ 'currency' => 'USD', 'amount' => 0.15 ]);
```

TODO: document missing methods
Expand Down
6 changes: 2 additions & 4 deletions client.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ public function __construct($url) {
* @param object $metadata
* @return object the invoice
*/
public function invoice($msatoshi, $metadata=null) {
$res = $this->api->post('/invoice',
json_encode([ 'msatoshi' => $msatoshi, 'metadata' => $metadata ]),
[ 'Content-Type' => 'application/json' ]);
public function invoice($props) {
$res = $this->api->post('/invoice', json_encode($props), [ 'Content-Type' => 'application/json' ]);

if ($res->info->http_code !== 201) throw new Exception('saving invoice failed');

Expand Down
8 changes: 4 additions & 4 deletions test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class LightningStrikeClientTest extends \PHPUnit\Framework\TestCase {

public function test_create_invoice(){
$strike = new LightningStrikeClient(getenv('STRIKE_URL'));
$invoice = $strike->invoice(50, [ 'customer' => 'Satoshi', 'products' => [ 'potato', 'chips' ]]);
$invoice = $strike->invoice([ 'msatoshi' => 50, 'metadata' => [ 'customer' => 'Satoshi', 'products' => [ 'potato', 'chips' ] ] ]);

$this->assertObjectHasAttribute('id', $invoice);
$this->assertObjectHasAttribute('rhash', $invoice);
Expand All @@ -17,18 +17,18 @@ public function test_create_invoice(){

public function test_fetch_invoice(){
$strike = new LightningStrikeClient(getenv('STRIKE_URL'));
$saved = $strike->invoice(50, 9999);
$saved = $strike->invoice( [ 'msatoshi' => 50, 'metadata' => 'test_fetch_invoice' ]);
$loaded = $strike->fetch($saved->id);

$this->assertEquals($saved->id, $loaded->id);
$this->assertEquals($saved->rhash, $loaded->rhash);
$this->assertEquals($loaded->metadata, 9999);
$this->assertEquals($loaded->metadata, 'test_fetch_invoice');
$this->assertEquals($loaded->msatoshi, '50');
}

public function test_register_webhook(){
$strike = new LightningStrikeClient(getenv('STRIKE_URL'));
$invoice = $strike->invoice(50);
$invoice = $strike->invoice([ 'msatoshi' => 50 ]);
$this->assertTrue($strike->registerHook($invoice->id, 'http://example.com/'));
}
}

0 comments on commit 2f68f51

Please sign in to comment.