Skip to content

Commit

Permalink
Differentiate expired and unpaid-but-still-valid invoices
Browse files Browse the repository at this point in the history
  • Loading branch information
shesek committed Dec 29, 2017
1 parent 2ca4a9f commit 9f41dca
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion client.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ public function fetch($invoice_id) {
*
* @param string $invoice_id
* @param int $timeout the timeout in seconds
* @return object|bool the paid invoice if paid, false otherwise.
* @return object|bool|null the paid invoice if paid, false if the invoice expired, or null if the timeout is reached.
*/
public function wait($invoice_id, $timeout) {
$res = $this->api->get('/invoice/' . urlencode($invoice_id) . '/wait?timeout=' . (int)$timeout);

// 402 Payment Required: timeout reached without payment, invoice is still payable
if ($res->info->http_code === 402)
return null;
// 410 Gone: invoice expired and can not longer be paid
else if ($res->info->http_code === 410)
return false;
// 200 OK: invoice is paid, returns the updated invoice
else if ($res->info->http_code === 200)
return $res->decode_response();
else
Expand Down

0 comments on commit 9f41dca

Please sign in to comment.