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
 /**
  * Refund a charge.
  *
  * @param array $properties
  * 
  * @return Charge
  */
 public function refund(array $properties = array())
 {
     $this->info();
     $this->local_charge->refund();
     $this->gateway->apiDelay();
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Delete a card.
  *
  * @return Card
  */
 public function delete()
 {
     $this->info();
     $this->local_card->delete();
     $this->gateway->apiDelay();
     $this->local_card = null;
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Cancel a subscription.
  *
  * @param bool $at_period_end
  * 
  * @return Subscription
  */
 public function cancel($at_period_end = true)
 {
     $this->info();
     if ($at_period_end) {
         $this->local_subscription->cancel_at = $this->local_subscription->period_ends_at;
         $this->local_subscription->save();
     } else {
         $this->local_subscription->delete();
         $this->local_subscription = null;
     }
     $this->gateway->apiDelay();
     return $this;
 }
Exemplo n.º 5
0
 /**
  * Gets all charges for a customer.
  *
  * @return array
  */
 public function charges()
 {
     $this->info();
     if (!$this->local_customer) {
         return array();
     }
     $charges = $this->local_customer->charges()->limit(100)->get();
     $this->gateway->apiDelay();
     $charges_array = array();
     foreach ($charges as $charge) {
         $charges_array[] = $this->charge($charge);
     }
     return $charges_array;
 }