/**
  * getNumberOfCustomers
  * --------------------------------------------------
  * Getting the number of customers.
  * @return The number of customers.
  * @throws StripeNotConnected
  * --------------------------------------------------
  */
 public function getNumberOfCustomers($update = False)
 {
     if ($update) {
         $this->updateSubscriptions();
     }
     $customerIDs = array();
     foreach (StripePlan::where('user_id', $this->user->id)->get() as $stripePlan) {
         foreach (StripeSubscription::where('plan_id', $stripePlan->id)->get() as $subscription) {
             if (!in_array($subscription->customer, $customerIDs)) {
                 array_push($customerIDs, $subscription->customer);
             }
         }
     }
     return count($customerIDs);
 }
 /**
  * handleSubscriptionUpdate
  * --------------------------------------------------
  * Handling subscription update.
  * @param eventThe specific stripe event.
  * --------------------------------------------------
  */
 private function handleSubscriptionUpdate($event)
 {
     /* Check if a plan's been changed./ */
     if (isset($event['data']['previous_attributes']['plan'])) {
         $subscriptionData = $event['data']['object'];
         $subscription = StripeSubscription::where('subscription_id', $subscriptionData['id'])->first();
         $newPlan = StripePlan::where('user_id', $this->user->id)->where('plan_id', $subscriptionData['plan']['id'])->first();
         $subscription->plan()->associate($newPlan);
         $subscription->save();
     }
 }