/**
  * Return the gateway subscription object for this model.
  *
  * @return Mmanos\Billing\Gateways\SubscriptionInterface
  */
 public function gatewaySubscription()
 {
     if (!$this->everSubscribed()) {
         return null;
     }
     if ($customer = $this->customer()) {
         $customer = $customer->gatewayCustomer();
     }
     return Billing::subscription($this->billing_subscription, $customer);
 }
예제 #2
0
 /**
  * Create this subscription in the billing gateway.
  *
  * @param array $properties
  *
  * @return Subscription
  */
 public function create(array $properties = array())
 {
     if ($this->is_free || $this->canLocalTrial()) {
         return $this->storeLocal(array('quantity' => Arr::get($properties, 'quantity', 1)));
     }
     if ($this->model->billingIsActive()) {
         return $this;
     }
     if ($customer = $this->model->customer()) {
         if (!$customer->readyForBilling()) {
             if ($this->card_token) {
                 $customer->billing()->withCardToken($this->card_token)->create($properties);
                 if (!empty($customer->billing_cards)) {
                     $this->card_token = null;
                 }
             } else {
                 $customer->billing()->create($properties);
             }
         } else {
             if ($this->card_token) {
                 $this->card = $customer->creditcards()->create($this->card_token)->id;
                 $this->card_token = null;
             }
         }
     }
     $this->subscription = Billing::subscription(null, $customer ? $customer->gatewayCustomer() : null)->create($this->plan, array_merge($properties, array('trial_ends_at' => $this->skip_trial ? date('Y-m-d H:i:s') : $this->model->billing_trial_ends_at, 'coupon' => $this->coupon, 'quantity' => Arr::get($properties, 'quantity', 1), 'card_token' => $this->card_token, 'card' => $this->card)));
     $this->model->billing_subscription_ends_at = null;
     $this->model->save();
     $this->refresh();
     return $this;
 }
예제 #3
0
 /**
  * Resume a canceled subscription in the billing gateway.
  *
  * @param int $quantity
  * 
  * @return Subscription
  */
 public function resume($quantity = null)
 {
     if (null === $quantity) {
         $quantity = $this->model->billing_quantity;
     }
     if ($this->is_free || $this->canLocalTrial()) {
         return $this->storeLocal(array('quantity' => $quantity));
     }
     if (!$this->model->canceled()) {
         return $this;
     }
     if (($customer = $this->model->customer()) && $this->card_token) {
         $this->card = $customer->creditcards()->create($this->card_token)->id;
         $this->card_token = null;
     }
     $this->subscription = Billing::subscription($this->model->billing_subscription, $customer ? $customer->gatewayCustomer() : null);
     if ($this->subscription->info()) {
         $this->subscription->update(array('plan' => $this->plan, 'trial_ends_at' => $this->skip_trial ? date('Y-m-d H:i:s') : $this->model->billing_trial_ends_at, 'prorate' => false, 'quantity' => $quantity, 'card_token' => $this->card_token, 'source' => $this->card, 'billing_active' => 1));
     } else {
         $this->subscription = Billing::subscription(null, $customer ? $customer->gatewayCustomer() : null)->create($this->plan, array('trial_ends_at' => $this->skip_trial ? date('Y-m-d H:i:s') : $this->model->billing_trial_ends_at, 'quantity' => $quantity, 'card_token' => $this->card_token, 'card' => $this->card));
     }
     $this->refresh();
     return $this;
 }