/**
  * is the current period subscription paid
  *
  * @param SubscriptionSubscriber $subscriber
  *
  * @return bool
  */
 public function paid(SubscriptionSubscriber $subscriber)
 {
     $this->current($subscriber);
     if (null === $this->subscription) {
         return false;
     }
     return $this->subscription->paid();
 }
 /**
  * saves a subscription to database
  *
  * @param \vvMalko\Subscriptions\Subscription\Subscription $subscription
  * @param \vvMalko\Subscriptions\Plans\Plan $plan
  * @param \vvMalko\Subscriptions\Plans\PaymentOption $paymentOption
  * @param \Carbon\Carbon $startDate
  * @param string $mode
  *
  * @return \vvMalko\Subscriptions\Subscription\Subscription
  */
 private function saveSubscription(Subscription $subscription, Plan $plan, PaymentOption $paymentOption, Carbon $startDate = null, $mode)
 {
     if ($startDate === null) {
         $startDate = Carbon::now();
     }
     $subscription->trial_ends_at = with(clone $startDate)->addDays($paymentOption->period());
     $subscription->subscription_ends_at = with(clone $startDate)->addDays($paymentOption->days());
     if ($subscription->save()) {
         $period = new Period(['start' => $startDate, 'end' => $subscription->subscription_ends_at, 'invoice_sum' => $plan->getPeriodSum($paymentOption), 'invoice_date' => Carbon::now(), 'state' => Period::STATE_UNPAID]);
         $subscription->periods()->save($period);
         $event = $mode === self::MODE_CREATE ? new SubscriptionWasCreated($subscription, $plan, $paymentOption) : new SubscriptionWasUpdated($subscription, $plan, $paymentOption);
         $subscription->raise($event);
         if ($plan->isFree()) {
             $period->markAsPaid('');
             //  assign period events to be raised via the subscription raising method
             $events = $period->releaseEvents();
             foreach ($events as $event) {
                 $subscription->raise($event);
             }
         }
     }
     return $subscription;
 }
 /**
  * returns all subscriptions for given plans for a subscriber
  *
  * @param SubscriptionSubscriber $subscriber
  * @param array $plans
  *
  * @return array|static[]|Subscription[]|Collection
  */
 public function allBySubscriberForPlans(SubscriptionSubscriber $subscriber, array $plans)
 {
     return $this->subscription->whereModelId($subscriber->getSubscriberId())->whereModelClass($subscriber->getSubscriberModel())->whereIn('plan', $plans)->orderBy('id')->get();
 }