Skip to content

Commit

Permalink
Add docblock documentation for class methods
Browse files Browse the repository at this point in the history
  • Loading branch information
shesek committed Nov 15, 2017
1 parent 882e71f commit 9c422c6
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions client.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,46 @@ public function __construct($url) {
$this->api = new RestClient([ 'base_url' => rtrim($url, '/'), 'format' => 'json' ]);
}

/**
* Create a new invoice.
*
* @param string|int $msatoshi
* @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' ]);

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

return $res->decode_response();
}

/**
* Fetch invoice by ID
*
* @param string $invoice_id
* @return object the invoice
*/
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');
if ($res->info->http_code !== 200) throw new Exception('fetching invoice failed');
return $res->decode_response();
}

/**
* Register a new webhook.
*
* @param string $invoice_id
* @param string $url
* @return bool
*/
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');
throw new Exception('register hook failed');
return true;
}
}
Expand Down

0 comments on commit 9c422c6

Please sign in to comment.