Permalink
Browse files

Added Response::getCustomerOutstandingInvoice() as a convenience for …

…checking if the customer has a past-due invoice(s). Added UNPROCESSABLE_ENTITY constant in Response_Exception.
  • Loading branch information...
Marc Guyer
Marc Guyer committed Mar 2, 2010
1 parent 4d90e1b commit 821c85bfa52024531c182902baaf963ec638561c
Showing with 22 additions and 1 deletion.
  1. +20 −0 Response.php
  2. +2 −1 Response/Exception.php
View
@@ -253,6 +253,26 @@ public function getCustomerInvoice($code = null) {
return current($subscription['invoices']);
}
/**
* Get an array representation of a single customer's outstanding invoices
*
* @throws CheddarGetter_Response_Exception if the response type is incompatible or if a $code is not provided and the response contains more than one customer
* @return array|false
*/
public function getCustomerOutstandingInvoices($code = null) {
$subscription = $this->getCustomerSubscription($code);
foreach ($subscription['invoices'] as $key => $i) {
// if the billing date is in the future or has been paid
if ($i['paidTransactionId'] || strtotime($i['billingDatetime']) > time()) {
unset($subscription['invoices'][$key]);
}
}
if ($subscription['invoices']) {
return $subscription['invoices'];
}
return false;
}
/**
* Get an array of a customer's item quantity and quantity included
*
View
@@ -14,8 +14,9 @@
class CheddarGetter_Response_Exception extends Exception {
const REQUEST_INVALID = 400;
const PRECONDITION_FAILED = 412;
const NOT_FOUND = 404;
const PRECONDITION_FAILED = 412;
const UNPROCESSABLE_ENTITY = 422;
const DATA_INVALID = 500;
const USAGE_INVALID = 500;
const UNKNOWN = 500;

0 comments on commit 821c85b

Please sign in to comment.