Exemplo n.º 1
0
 /**
  * Gets info for an invoice.
  *
  * @return array|null
  */
 public function info()
 {
     if (!$this->id || !$this->local_customer) {
         return null;
     }
     if (!$this->local_invoice) {
         $this->local_invoice = $this->local_customer->invoices()->where('id', $this->id)->first();
         $this->gateway->apiDelay();
     }
     if (!$this->local_invoice) {
         return null;
     }
     $discounts = array();
     if ($this->local_invoice->coupon) {
         $started_at = $this->local_invoice->subscription ? $this->local_invoice->subscription->created_at : $this->local_invoice->customer->created_at;
         $ends_at = null;
         if ($this->local_invoice->coupon->duration_in_months) {
             if ($this->local_invoice->subscription) {
                 $ends_at = $this->local_invoice->subscription->created_at->copy()->addMonths($this->local_invoice->coupon->duration_in_months);
             } else {
                 $ends_at = $this->local_invoice->customer->created_at->copy()->addMonths($this->local_invoice->coupon->duration_in_months);
             }
         }
         $discounts[] = array('coupon' => $this->local_invoice->coupon->code, 'amount_off' => $this->local_invoice->coupon->amount_off, 'percent_off' => $this->local_invoice->coupon->percent_off, 'started_at' => (string) $started_at, 'ends_at' => $ends_at ? (string) $ends_at : null);
     }
     $items = array();
     foreach ($this->local_invoice->items as $line) {
         $item = array('id' => $line->id, 'amount' => $line->amount, 'period_start' => $line->period_started_at ? (string) $line->period_started_at : null, 'period_end' => $line->period_ends_at ? (string) $line->period_ends_at : null, 'description' => $line->description, 'subscription_id' => $line->subscription_id, 'quantity' => $line->quantity);
         $items[] = $item;
     }
     return array('id' => $this->id, 'date' => (string) $this->local_invoice->period_started_at, 'total' => $this->local_invoice->subtotal, 'subtotal' => $this->local_invoice->subtotal, 'amount' => $this->local_invoice->amount, 'starting_balance' => 0, 'ending_balance' => 0, 'closed' => $this->local_invoice->closed, 'paid' => $this->local_invoice->paid, 'discounts' => $discounts, 'items' => $items);
 }
Exemplo n.º 2
0
 /**
  * Gets all invoices for a customer.
  *
  * @return array
  */
 public function invoices()
 {
     $this->info();
     if (!$this->local_customer) {
         return array();
     }
     foreach ($this->local_customer->subscriptions as $subscription) {
         if ($subscription->gracePeriodEnded()) {
             continue;
         }
         $subscription->process();
     }
     $invoices = $this->local_customer->invoices()->limit(100)->get();
     $this->gateway->apiDelay();
     $invoices_array = array();
     foreach ($invoices as $invoice) {
         $invoices_array[] = $this->invoice($invoice);
     }
     return $invoices_array;
 }