Пример #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);
 }
Пример #2
0
 /**
  * Gets info for a subscription.
  *
  * @return array|null
  */
 public function info()
 {
     if (!$this->id || !$this->local_customer) {
         return null;
     }
     if (!$this->local_subscription) {
         $this->local_subscription = $this->local_customer->subscriptions()->where('id', $this->id)->first();
         $this->gateway->apiDelay();
         if ($this->local_subscription) {
             $this->local_subscription->process();
         }
     }
     if (!$this->local_subscription) {
         return null;
     }
     if ($this->local_subscription->gracePeriodEnded()) {
         return $this->local_subscription = null;
     }
     $discounts = array();
     if ($this->local_subscription->coupon) {
         $started_at = $this->local_subscription->subscription->created_at;
         $ends_at = null;
         if ($this->local_subscription->coupon->duration_in_months) {
             $ends_at = $started_at->copy()->addMonths($this->local_subscription->coupon->duration_in_months);
         }
         $discounts[] = array('coupon' => $this->local_subscription->coupon->code, 'amount_off' => $this->local_subscription->coupon->amount_off, 'percent_off' => $this->local_subscription->coupon->percent_off, 'started_at' => (string) $started_at, 'ends_at' => $ends_at ? (string) $ends_at : null);
     }
     return array('id' => $this->id, 'plan' => $this->local_subscription->plan->key, 'amount' => $this->local_subscription->plan->amount, 'interval' => $this->local_subscription->plan->interval, 'active' => $this->local_subscription->cancel_at ? false : true, 'quantity' => $this->local_subscription->quantity, 'started_at' => (string) $this->local_subscription->created_at, 'period_started_at' => (string) $this->local_subscription->period_started_at, 'period_ends_at' => (string) $this->local_subscription->period_ends_at, 'trial_ends_at' => $this->local_subscription->trial_ends_at ? (string) $this->local_subscription->trial_ends_at : null, 'card' => $this->local_subscription->card_id, 'discounts' => $discounts);
 }
Пример #3
0
 /**
  * Gets info for a charge.
  *
  * @return array|null
  */
 public function info()
 {
     if (!$this->id || !$this->local_customer) {
         return null;
     }
     if (!$this->local_charge) {
         $this->local_charge = $this->local_customer->charges()->where('id', $this->id)->first();
         $this->gateway->apiDelay();
     }
     if (!$this->local_charge) {
         return null;
     }
     return array('id' => $this->id, 'created_at' => (string) $this->local_charge->created_at, 'amount' => $this->local_charge->amount, 'paid' => $this->local_charge->paid, 'refunded' => $this->local_charge->refunded, 'captured' => $this->local_charge->captured, 'card' => $this->local_charge->card_id, 'invoice_id' => null, 'description' => $this->local_charge->description);
 }
Пример #4
0
 /**
  * Gets info for a card.
  *
  * @return array|null
  */
 public function info()
 {
     if (!$this->id || !$this->local_customer) {
         return null;
     }
     if (!$this->local_card) {
         $this->local_card = $this->local_customer->cards()->where('id', $this->id)->first();
         $this->gateway->apiDelay();
     }
     if (!$this->local_card) {
         return null;
     }
     return array('id' => $this->id, 'last4' => $this->local_card->last4, 'brand' => $this->local_card->brand, 'exp_month' => $this->local_card->exp_month, 'exp_year' => $this->local_card->exp_year, 'name' => $this->local_card->name, 'address_line1' => $this->local_card->address_line1, 'address_line2' => $this->local_card->address_line2, 'address_city' => $this->local_card->address_city, 'address_state' => $this->local_card->address_state, 'address_zip' => $this->local_card->address_zip, 'address_country' => $this->local_card->address_country);
 }
Пример #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;
 }