protected function failedValidation(Validator $validator)
 {
     $messages = $validator->errors();
     if ($messages->has('email', '<p>:The email has already been taken.</p>')) {
         $subscription = Subscription::where('email', $this->request->get('email'))->first();
         if (!$subscription->confirmed) {
             $this->mailer->sendEmailConfirmationFor($subscription);
         } else {
             $messages = ['email.unique:subscriptions' => 'That email address is already signed up'];
             $validator->getMessageBag()->merge($messages);
             $this->mailer->sendEmailRejectionFor($subscription);
         }
     }
     throw new HttpResponseException($this->response($this->formatErrors($validator)));
 }
Beispiel #2
0
 /**
  * Create a new event instance.
  *
  * @param $subscription
  */
 public function __construct($subscription)
 {
     $this->subscription = $subscription;
     // Get user id
     $query = Subscription::where('paymill_subscription_id', $subscription['id'])->first();
     $this->userId = $query->user_id;
 }
 /**
  * Handle the event.
  *
  * @param  SubscriptionFailed  $event
  * @return void
  */
 public function handle(SubscriptionFailed $event)
 {
     // Stop event propagation if subscription does not exists
     if (!$event->userId) {
         return false;
     }
     Subscription::where('paymill_subscription_id', $event->subscription['id'])->update(['status' => 'failed']);
 }
Beispiel #4
0
 /**
  * Handle the event.
  *
  * @param  SubscriptionDeleted  $event
  * @return void
  */
 public function handle(SubscriptionDeleted $event)
 {
     // Stop event propagation if subscription does not exists
     if ($event->userId) {
         return false;
     }
     Subscription::where('paymill_subscription_id', $event->subscription['id'])->delete();
 }
Beispiel #5
0
 /**
  * Create a new event instance.
  *
  * @param $subscription
  * @param $transaction
  */
 public function __construct($subscription, $transaction)
 {
     $this->subscription = $subscription;
     $this->transaction = $transaction;
     // Get user id
     $query = Subscription::where('paymill_susbcription_id', $subscription['id'])->first();
     if ($query->user_id) {
         $this->userId = null;
     }
 }
 /**
  * Paginate subscriptions.
  *
  * @param $status
  * @return mixed
  */
 public function get($status)
 {
     // Make sure given status is allowed
     $allowedStatuses = ['active', 'canceled', 'failed', 'waiting'];
     if (!in_array($status, $allowedStatuses)) {
         $status = 'active';
     }
     // todo select only required fields
     $query = Subscription::where('subscriptions.status', $status)->leftJoin('users', 'users.id', '=', 'subscriptions.user_id')->leftJoin('transactions', 'transactions.subscription_id', '=', 'subscriptions.id')->paginate();
     return $query;
 }
 /**
  * Handle the event.
  *
  * @param  SubscriptionSucceeded  $event
  * @return void
  */
 public function handle(SubscriptionSucceeded $event)
 {
     // Get subscription id
     $query = Subscription::where('paymill_subscription_id', $event->subscription['id'])->first();
     $transaction = new Transaction();
     $transaction->paymill_transaction_id = $event->transaction['id'];
     $transaction->user_id = $event->userId;
     $transaction->subscription_id = $query->id;
     $transaction->amount = $event->transaction['amount'];
     $transaction->status = $event->transaction['status'];
     $transaction->response_code = $event->transaction['response_code'];
     $transaction->save();
 }
Beispiel #8
0
 /**
  * Handle the event.
  *
  * @param  SubscriptionFailed  $event
  * @return void
  */
 public function handle(SubscriptionFailed $event)
 {
     // Stop event propagation if subscription does not exists
     if (!$event->userId) {
         return false;
     }
     // Get subscription id
     $subscriptionQuery = Subscription::where('paymill_subscription_id', $event->subscription['id'])->first();
     $transaction = new Transaction();
     $transaction->paymill_transaction_id = $event->transaction['id'];
     $transaction->subscription_id = $subscriptionQuery->id;
     $transaction->user_id = $event->userId;
     $transaction->amount = $event->transaction['amount'];
     $transaction->status = $event->transaction['status'];
     $transaction->response_code = $event->transaction['response_code'];
     $transaction->save();
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function subscribe($id)
 {
     if (Auth::guest()) {
         return Redirect::to('/auth/login');
     } else {
         $subs = Subscription::where("subscriber_id", $id)->where("subscribed_id", Auth::user()->id)->get();
         if (!$subs) {
             return back();
         } else {
             $subscription = new Subscription();
             $subscription->subscriber_id = $id;
             $subscription->subscribed_id = Auth::user()->id;
             $subscription->save();
             return back();
         }
     }
 }
 /**
  * Handle the event.
  *
  * @param  SubscriptionSucceeded  $event
  * @return void
  */
 public function handle(SubscriptionSucceeded $event)
 {
     Subscription::where('paymill_subscription_id', $event->subscription['id'])->update(['status' => 'active']);
 }
Beispiel #11
0
 /**
  * Handles updating subscriptions
  * @return REDIRECT subscriptions
  */
 public function updateSubscriptions()
 {
     $data = Request::only(['allSubscriptions']);
     // Trim and replace all extranneous whitespace then explode the array
     $data = explode(' ', trim(preg_replace('/\\s+/', ' ', $data['allSubscriptions'])));
     foreach ($data as $societyID) {
         if (1 <= $societyID && $societyID <= Setting::where('name', 'number_of_societies')->first()->setting) {
             try {
                 // If subscription exists, cancel it
                 $currentSubscription = Subscription::where('user_id', Auth::user()->id)->where('society_id', $societyID)->firstOrFail();
                 $currentSubscription->delete();
             } catch (ModelNotFoundException $e) {
                 // If subscription doesn't exist, create one
                 Subscription::create(['society_id' => $societyID, 'user_id' => Auth::user()->id]);
             }
         }
     }
     return Redirect::route('subscriptions');
 }
Beispiel #12
0
 public function notifyAllSubs($id)
 {
     $subs = Subscription::where('subscriber_id', $id)->get()->subscribed_id;
     return $subs;
 }
Beispiel #13
0
 /**
  * Allow admin to delete user account.
  *
  * @param int $userId
  * @param DeleteUserAccountRequest $request
  * @return mixed
  */
 public function deleteUserAccount($userId, DeleteUserAccountRequest $request)
 {
     $response = new AjaxResponse();
     // Make sure user id exists
     if (!User::where('id', $userId)->count()) {
         $response->setFailMessage(trans('users_manager.user_not_found'));
         return response($response->get())->header('Content-Type', 'application/json');
     }
     Subscription::where('user_id', $userId)->delete();
     User::where('id', $userId)->delete();
     $response->setSuccessMessage(trans('users_manager.account_deleted'));
     return response($response->get())->header('Content-Type', 'application/json');
 }
 /**
  * Attempts to fetch the subscriber
  *
  * @param  string  $email
  * @param  string  $key
  * @return \Illuminate\Http\Response
  */
 private function fetchSubscription($email, $key)
 {
     return Subscription::where('email', $email)->where('key', $key)->firstOrFail();
 }