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)));
 }
 public function initializeBilling(InitializeBillingRequest $request)
 {
     //TODO FAIRE UN SERVICE NON et des repository ?
     $category = $request->get('category');
     $uuid = base64_encode(time());
     $plan = config("plans.pricing.{$category}");
     $users_sup = $request->get('users');
     $plan['limits']['base'] = +$users_sup;
     $subscription = new Subscription();
     $subscription->price_base = $plan['price'];
     $subscription->category = $category;
     $subscription->price_current = $plan['price'] + $users_sup;
     //TODO CALCUL SAVANT
     $subscription->values = json_encode($plan);
     $subscription->is_active = false;
     $subscription->last_billing_uuid = $uuid;
     $billing = new Billing();
     $billing->uuid = $uuid;
     $billing->status = "NOT-BILLED";
     $billing->price = $subscription->price_current;
     $billing->is_billed = false;
     $subscription->organization()->associate($this->organization);
     $subscription->save();
     $billing->subscription()->associate($subscription);
     $billing->organization()->associate($this->organization);
     $billing->save();
     return redirect();
     //TODO ENV REDIRECT URL
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $subscription_data = Subscription::all();
     $subscription = $subscription_data->toJson();
     echo $subscription;
     die;
 }
示例#4
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;
 }
示例#5
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();
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     foreach (Society::all() as $society) {
         Subscription::create(['user_id' => $this->user->id, 'society_id' => $society->id]);
     }
     $this->user->processing = 'no';
     $this->user->save();
 }
 /**
  * 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']);
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $user = User::findOrFail($id);
     //$subscription = Subscription::all()->toArray();
     $subscription = Subscription::lists('subscription_name', 'id');
     //print_r($subscription);die;
     return view('users.edit', compact('user', 'subscription'));
 }
示例#9
0
 /**
  * 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();
         }
     }
 }
示例#10
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;
     }
 }
示例#11
0
 /**
  * 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;
 }
示例#12
0
 /**
  * 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();
 }
示例#13
0
 public function process(ProcessRequest $request)
 {
     // Initialize paymill request
     // Create credit card payment
     $payment = new Payment();
     $payment->setToken($request->get('token'));
     $paymentResponse = $paymillRequest->create($payment);
     // Create subscription
     $subscription = new Subscription();
     $subscription->setAmount(30)->setPayment($paymentResponse->getId())->setCurrency('EUR')->setInterval('1 week,monday')->setName('Nova sub')->setPeriodOfValidity('2 YEAR')->setStartAt(time());
     $subscriptionResponse = $paymillRequest->create($subscription);
     // Save in database
     $paymentModel = new PaymentModel();
     $paymentModel->user_id = Auth::user()->id;
     $paymentModel->paymill_payment_id = $paymentResponse->getId();
     $paymentModel->save();
     // Save subscription
     $subscriptionModel = new SubscriptionModel();
     $subscriptionModel->user_id = Auth::user()->id;
     $subscriptionModel->paymill_subscription_id = $subscriptionResponse->getId();
     $subscriptionModel->save();
 }
示例#14
0
 private function canAdd(\App\User $user, $request)
 {
     if (\App\Subscription::isSubscribed($user)) {
         return true;
     } else {
         $deck = \App\Deck::find($request->id);
         if ($deck->users->count() >= DeckAddUser::USER_LIMIT) {
             return false;
         } else {
             return true;
         }
     }
 }
 /**
  * Assert that emails are sent using the command send:email
  *
  * @return void
  */
 public function testItSendsEmailToInterestedSubscribers()
 {
     $totalSubscribers = Subscription::count();
     $subscriber = factory(Subscription::class)->create(['confirmed' => true, 'active' => true]);
     $this->assertTrue($totalSubscribers < Subscription::count());
     $subscriber->topics()->detach();
     foreach (Tag::all() as $tag) {
         $subscriber->topics()->save($tag);
     }
     $this->assertTrue($subscriber->topics()->get()->count() == Tag::count());
     // $this->expectsJobs(SendNewsletter::class);
     Artisan::call("emails:send", ['timestamp' => 1]);
     $logFile = file_get_contents(storage_path() . '/logs/laravel.log');
     $this->assertTrue(strpos($logFile, $subscriber->email) !== false);
 }
示例#16
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();
 }
 public function confirmEmail($token)
 {
     Subscription::whereToken($token)->firstOrFail()->confirmEmail();
     flash('You are now confirmed!');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     try {
         $subscription = Subscription::findOrFail($id);
         $subscription->delete();
     } catch (ModelNotFoundException $ex) {
         Flash::error('No subscription plan found' . $ex);
         return redirect()->route('subscriptions.index');
     }
     Flash::success('Subscription plan deleted successfully');
     return back();
 }
示例#19
0
 /**
  * Subscribe user with POST request.
  *
  * @param Request $request
  * @return mixed
  */
 public function postSubscription(Request $request)
 {
     $validator = Validator::make($request->all(), array('sub_email' => 'required|email|unique:subscriptions'), array('sub_email.required' => 'Please enter an e-mail address!', 'sub_email.email' => 'Please enter an correct e-mail address!', 'sub_email.unique' => 'Your already subscribed, please enter a different e-mail address!'));
     if ($validator->fails()) {
         return Redirect::route('home')->with('msg-error', 'Bad Email!')->withErrors($validator);
     } else {
         $s_email = new Subscription();
         $s_email->sub_email = $request['sub_email'];
         $s_email->user_ip = $request->getClientIp();
         if ($s_email->save()) {
             return Redirect::route('home')->with('msg-success', 'Your successfully subscribed with: <strong>' . $request['sub_email'] . '</strong>');
         }
     }
     return Redirect::route('home')->with('global', 'There was an error with sign in. Please try again later!');
 }
示例#20
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');
 }
 public function index()
 {
     $id = \Auth::user()->id;
     $subscripts = Subscription::with('Soortcursus')->find(['id' => $id])->all();
     return view('subscriptions.index', compact('subscripts'));
 }
示例#22
0
 public function createSubscription(Request $request)
 {
     \App\Subscription::create($request->stripeToken, Auth::user());
     return view('pro')->with(['user' => $request->user, 'congrats' => true]);
 }
示例#23
0
 public function notifyAllSubs($id)
 {
     $subs = Subscription::where('subscriber_id', $id)->get()->subscribed_id;
     return $subs;
 }
 /**
  * Test subscription can be deactivated
  *
  * @depends testSubscriptionBecomesActiveWhenConfirmedByEmailAndKeyParams
  * @return void
  */
 public function testSubscriptionCanBeDeactivated()
 {
     $id = 1;
     $this->assertNotNull(Subscription::find($id));
     $this->visit("/subscription/{$id}/remove");
     $this->assertFalse((bool) Subscription::find($id)->active);
 }
 /**
  * Handle the event.
  *
  * @param  SubscriptionSucceeded  $event
  * @return void
  */
 public function handle(SubscriptionSucceeded $event)
 {
     Subscription::where('paymill_subscription_id', $event->subscription['id'])->update(['status' => 'active']);
 }
示例#26
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');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $subscription = Subscription::findOrFail($id);
     $subscription->delete();
     return redirect()->route('subscriptions.index');
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create()
 {
     $user_data = User::lists('name', 'id');
     $subscription_data = Subscription::lists('subscription_name', 'id');
     return view('notifications.create', compact('user_data', 'subscription_data'));
 }
示例#29
0
 /**
  * @param $recipient
  */
 private function saveSubscription($recipient)
 {
     $result = $this->subscription->subscribe($recipient);
     $subscription = new SubscriptionModel();
     $subscription->number = $recipient;
     $subscription->status = $result->status;
     $subscription->description = $result->description;
     $subscription->save();
     Log::debug($recipient . ' is subscribed');
 }
 public function payment()
 {
     if ('type' == 'free') {
     }
     $subscription = new Subscription();
     $subscription->createPayment();
 }