/** * 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); }
/** * @return RangeNode */ public function createdAt() { return TransactionSearch::createdAt(); }
public function test_rangeNode_createdAt_handlesUTCDateTimes() { $transaction = Braintree\Transaction::saleNoValidate(['amount' => '1000.00', 'creditCard' => ['cardholderName' => 'Pingu Penguin' . rand(), 'number' => '5105105105105100', 'expirationDate' => '05/12']]); $ten_min_ago = date_create("now -10 minutes", new DateTimeZone("UTC")); $ten_min_from_now = date_create("now +10 minutes", new DateTimeZone("UTC")); $collection = Braintree\Transaction::search([Braintree\TransactionSearch::id()->is($transaction->id), Braintree\TransactionSearch::createdAt()->between($ten_min_ago, $ten_min_from_now)]); $this->assertEquals(1, $collection->maximumCount()); $this->assertEquals($transaction->id, $collection->firstItem()->id); }