From 9f41dcaddab3a0014835e3f55e235bccc8b2da4a Mon Sep 17 00:00:00 2001 From: Nadav Ivgi Date: Fri, 29 Dec 2017 21:13:46 +0200 Subject: [PATCH] Differentiate expired and unpaid-but-still-valid invoices --- client.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client.php b/client.php index 0bd74d1..17ae676 100644 --- a/client.php +++ b/client.php @@ -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