/** * @param $eventId EventID * @return \Illuminate\Http\RedirectResponse * Unsubscribe a user */ public function unsubscribe($eventId) { $userId = Auth::user()->id; $event = $this->eventRepository->findById($eventId); $subscription = $this->subscriptionRepository->findByEvent($userId, $eventId); if (!$event) { return Redirect::action('EventsController@show', $eventId)->with('warning', trans('word.system_error')); } // If event is Expired if ($this->eventRepository->eventExpired($event->date_start)) { return Redirect::action('EventsController@show', $eventId)->with('warning', trans('word.event_expired')); } // if event is currently going on // if ( $this->eventRepository->ongoingEvent($event->date_start, $event->date_end) ) { // // return Redirect::action('EventsController@show', $eventId)->with('warning', trans('general.event_ongoing')); // } if ($subscription) { $subscriber = new Subscriber($subscription); $subscriber = $subscriber->unsubscribe(); if ($subscriber->messages->has('errors')) { // redirect with first error as an array return Redirect::action('EventsController@index')->with('errors', [$subscriber->messages->first('errors')]); } else { // If no errors occured while subscription process return Redirect::action('EventsController@index')->with('success', trans('general.unsubscribed')); } } return Redirect::action('EventsController@index')->with('success', trans('general.subscription.unsubscribed_fail')); }
/** * Stream the online event using Electa service * @param $id * @return \Illuminate\Http\RedirectResponse */ public function streamEvent($id) { $user = Auth::user(); $event = $this->eventRepository->findById($id); // check if this event has online streaming if (!$this->isOnlineEvent($event)) { return Redirect::action('EventsController@index')->with('error', trans('general.event_no_stream')); } // if event is currently going on if (!$this->eventRepository->ongoingEvent($event->date_start, $event->date_end)) { return Redirect::action('EventsController@show', $id)->with('warning', trans('general.wrong_event_stream_time')); } // check whether this user subscribed for this and confirmed $subscription = $event->subscriptions()->where('user_id', $user->id)->first(); // find if this user has a subscriptoin if (!$subscription) { return Redirect::action('EventsController@index')->with('error', trans('general.not_subscribed')); } // find whether the user is in the confirmed list $subscription = $event->subscriptions()->where('user_id', $user->id)->where('status', 'CONFIRMED')->first(); // If user has a subscription and subscription is not confirmed if (!$subscription) { return Redirect::action('EventsController@index')->with('error', trans('general.subscription_not_confirmed')); } // check whether the user has subscribed as online if ($subscription->registration_type != 'ONLINE') { return Redirect::action('EventsController@index')->with('error', trans('general.subscription_not_online')); } // stream the event if (!$this->getStreamSettings()) { return Redirect::action('EventsController@show', $id)->with('info', trans('word.system_error')); } list($token, $cid, $launchUrl) = $this->getStreamSettings(); if (is_null($token)) { return Redirect::action('EventsController@show', $id)->with('error', trans('word.system-error')); } // Find the user id $userTypeId = $event->isAuthor($user->id) ? 1000 : 0; // user date to pass to streaming server $data = ['token' => urlencode($token), 'cid' => $cid, 'roomid' => $event->setting->online_room_id, 'usertypeid' => $userTypeId, 'gender' => $user->gender ? $user->gender[0] : 'M', 'firstname' => $user->username, 'lastname' => $user->name, 'email' => $user->email, 'externalname' => $user->username]; // launch the live stream $this->launchStream($data, $launchUrl); }
public function postPayment() { $payableId = Input::get('event_id'); $token = Input::get('token'); // payment token $paymentRepo = $this->paymentRepository->findByToken($token); $paymentRepo->method = 'paypal'; $event = $this->eventRepository->findById($payableId); $country = $this->processCountry($event); $user = Auth::user(); $subscription = $this->subscriptionRepository->findByEvent($user->id, $event->id); $eventPrice = $event->getPriceByCountryAndType($country->id, $subscription->registration_type)->first(); $convertedPrice = $this->converter->convert($this->defaultCurrency, $eventPrice->price); if ($convertedPrice <= 0) { return Redirect::back('/')->with('error', trans('word.system_error')); } $paymentRepo->amount = $convertedPrice; $paymentRepo->currency = $this->defaultCurrency; $description = 'Total: ' . $convertedPrice . ' ' . $this->defaultCurrency . '. '; $description .= Str::limit(strip_tags($event->description), 50, '..'); $baseUrl = App::make('url')->action('PaymentsController@getFinal') . '?t=' . $token; $item = ['title' => $event->title, 'amount' => $paymentRepo->amount, 'description' => $event->description]; try { // Instantiate Paypal Class $payer = $this->paypal; // Make Payment $payment = $payer->makePayment($paymentRepo->amount, 'USD', $description, "{$baseUrl}&success=true", "{$baseUrl}&success=false", $item); $paymentRepo->status = 'CREATED'; $paymentRepo->transaction_id = $payment->getId(); $paymentRepo->save(); // Redirect With Payment Params header("Location: " . $this->getLink($payment->getLinks(), 'approval_url')); exit; } catch (Exception $e) { // Set Status To Error $paymentRepo->status = 'ERROR'; $paymentRepo->save(); return Redirect::back()->with('info', trans('word.system_error')); } }