diff --git a/README.md b/README.md index 7e33415..7099b90 100644 --- a/README.md +++ b/README.md @@ -12,24 +12,30 @@ $ composer require elementsproject/lightning-charge-client-php ```php 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"); +// Create invoice denominated in USD +$invoice = $charge->invoice([ 'currency' => 'USD', 'amount' => 0.15 ]); + // Fetch invoice by id $invoice = $charge->fetch('m51vlVWuIKGumTLbJ1RPb'); -// Create invoice denominated in USD -$invoice = $charge->invoice([ 'currency' => 'USD', 'amount' => 0.15 ]); +// Fetch all invoices +$invoice = $charge->fetchAll(); + +// Register web hook +$charge->registerHook('m51vlVWuIKGumTLbJ1RPb', 'http://my-server.com/my-callback-url'); ``` -TODO: document missing methods +*TODO*: document `wait` ## Test diff --git a/client.php b/client.php index afe2924..e0cf388 100644 --- a/client.php +++ b/client.php @@ -21,7 +21,7 @@ public function __construct($url, $api_token=null) { 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'); + if ($res->info->http_code !== 201) throw new Exception('failed saving invoice'); return $res->decode_response(); } @@ -34,10 +34,22 @@ public function invoice($props) { */ public function fetch($invoice_id) { $res = $this->api->get('/invoice/' . urlencode($invoice_id)); - if ($res->info->http_code !== 200) throw new Exception('fetching invoice failed'); + if ($res->info->http_code !== 200) throw new Exception('failed fetching invoice'); return $res->decode_response(); } + /** + * Fetch all invoices + * + * @return array + */ + public function fetchAll() { + $res = $this->api->get('/invoices'); + if ($res->info->http_code !== 200) throw new Exception('failed fetching invoices'); + return $res->decode_response(); + } + + /** * Wait for an invoice to be paid. *