/**
* Get a collection of the entity's invoices.
*
* @param bool $includePending
* @param array $parameters
* @return \Illuminate\Support\Collection
*/
public function invoices($includePending = false, $parameters = [])
{
$invoices = [];
$customer = $this->asBraintreeCustomer();
$parameters = array_merge([TransactionSearch::customerId()->is($customer->id), TransactionSearch::createdAt()->between(Carbon::today()->subYears(2)->format('m/d/Y H:s'), Carbon::tomorrow()->format('m/d/Y H:s'))], $parameters);
$transactions = BraintreeTransaction::search($parameters);
// Here we will loop through the Braintree invoices and create our own custom Invoice
// instance that gets more helper methods and is generally more convenient to work
// work than the plain Braintree objects are. Then, we'll return the full array.
if (!is_null($transactions)) {
foreach ($transactions as $transaction) {
if ($transaction->status == BraintreeTransaction::SETTLED || $includePending) {
$invoices[] = new Invoice($this, $transaction);
}
}
}
return new Collection($invoices);
}