コード例 #1
0
 /**
  * disconnect
  * --------------------------------------------------
  * Disconnecting the user from braintree.
  * @throws StripeNotConnected
  * --------------------------------------------------
  */
 public function disconnect()
 {
     /* Check valid connection */
     if (!$this->user->isStripeConnected()) {
         throw new StripeNotConnected();
     }
     /* Deleting connection */
     $this->user->connections()->where('service', 'stripe')->delete();
     /* Deleting all widgets, plans, subscribtions */
     foreach ($this->user->widgets() as $widget) {
         if ($widget->descriptor->category == 'stripe') {
             /* Saving data while it is accessible. */
             $dataID = 0;
             if (!is_null($widget->data)) {
                 $dataID = $widget->data->id;
             }
             $widget->delete();
             /* Deleting data if it was present. */
             if ($dataID > 0) {
                 Data::find($dataID)->delete();
             }
         }
     }
     /* Deleting all plans. */
     foreach ($this->user->stripePlans as $stripePlan) {
         StripeSubscription::where('plan_id', $stripePlan->id)->delete();
         $stripePlan->delete();
     }
 }
コード例 #2
0
 /**
  * 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);
 }
コード例 #3
0
 /**
  * handleSubscriptionCreation
  * --------------------------------------------------
  * Handling subscription creation.
  * On creation we'll have to delete a subscription.
  * @param eventThe specific stripe event.
  * --------------------------------------------------
  */
 private function handleSubscriptionCreation($event)
 {
     $subscriptionData = $event['data']['object'];
     StripeSubscription::where('subscription_id', $subscriptionData['id'])->first()->delete();
 }