public function vaultUpdate($id)
 {
     $user = Auth::user();
     $follow = Follower::where("user_id", "=", $user->id)->FirstOrFail();
     $club = Club::find($follow->club_id);
     $validator = Validator::make(Input::all(), Payment::$rules);
     if ($validator->passes()) {
         //validation done prior ajax
         $param = array('customer_vault_id' => $id, 'club' => $club->id, 'ccnumber' => Input::get('card'), 'ccexp' => sprintf('%02s', Input::get('month')) . Input::get('year'), 'cvv' => Input::get('cvv'), 'address1' => Input::get('address'), 'city' => Input::get('city'), 'state' => Input::get('state'), 'zip' => Input::get('zip'));
         $payment = new Payment();
         $transaction = $payment->update_customer($param, $user);
         if ($transaction->response == 3 || $transaction->response == 2) {
             $data = array('success' => false, 'error' => $transaction);
             return $data;
         } else {
             //update user customer #
             $user->profile->customer_vault = $transaction->customer_vault_id;
             $user->profile->save();
             //retrived data save from API - See API documentation
             $data = array('success' => true, 'customer' => $transaction->customer_vault_id, 'card' => substr($param['ccnumber'], -4), 'ccexp' => $param['ccexp'], 'zip' => $param['zip']);
             return Redirect::action('AccountController@settings')->with('notice', 'Payment information updated successfully');
         }
     }
     return Redirect::back()->withErrors($validator)->withInput();
     return Redirect::action('AccountController@settings');
 }
 /**
  * Show the form for creating a new resource.
  * GET /player/create
  *
  * @return Response
  */
 public function create()
 {
     $user = Auth::user();
     $follow = Follower::where("user_id", "=", $user->id)->FirstOrFail();
     $club = Club::find($follow->club_id);
     $title = 'League Together - Player';
     return View::make('app.account.player.create')->with('page_title', $title)->with('club', $club)->withUser($user);
 }
 /**
 * Store a newly created resource in storage.
 * POST /administratorclub
 *
 * @return Response
 */
 public function store()
 {
     $uuid = Uuid::generate();
     $validator = Validator::make(Input::all(), AdministratorClub::$rules);
     if ($validator->passes()) {
         $repo = App::make('UserRepository');
         $user = $repo->signup(Input::all());
         $role = Role::find(2);
         $user->attachRole($role);
         if ($user->id) {
             $profile = new Profile();
             $profile->user_id = $user->id;
             $profile->firstname = Input::get('firstname');
             $profile->lastname = Input::get('lastname');
             $profile->mobile = Input::get('mobile');
             $profile->avatar = '/img/coach-avatar.jpg';
             $profile->save();
             $club = new Club();
             $club->id = $uuid;
             $club->name = Input::get('name');
             $club->sport = 'lacrosse';
             $club->phone = Input::get('contactphone');
             $club->website = Input::get('website');
             $club->email = Input::get('contactemail');
             $club->add1 = Input::get('add1');
             $club->city = Input::get('city');
             $club->state = Input::get('state');
             $club->zip = Input::get('zip');
             $club->logo = Input::get('logo');
             $club->waiver = Input::get('waiver');
             $club->processor_user = Crypt::encrypt(Input::get('processor_user'));
             $club->processor_pass = Crypt::encrypt(Input::get('processor_pass'));
             $club->save();
             $clubs = Club::find($uuid);
             $clubs->users()->save($user);
             if (Config::get('confide::signup_email')) {
                 Mail::queueOn(Config::get('confide::email_queue'), Config::get('confide::email_account_confirmation'), compact('user'), function ($message) use($user) {
                     $message->to($user->email, $user->username)->subject(Lang::get('confide::confide.email.account_confirmation.subject'));
                 });
             }
             return Redirect::action('UsersController@login')->with('notice', Lang::get('confide::confide.alerts.account_created'));
         } else {
             $error = $user->errors()->all(':message');
             return Redirect::back()->withInput(Input::except('password'))->withErrors($error);
         }
     }
     return Redirect::back()->withErrors($validator)->withInput();
 }
 /**
  * Show the form for creating a new resource.
  * GET /calendar/create
  *
  * @return Response
  */
 public function create($id)
 {
     $event = Evento::find($id);
     $club = Club::find($event->club_id);
     return View::make('icalendar.create')->with('event', $event)->with('club', $club);
 }
 public function doPaymentSelect($id)
 {
     $user = Auth::user();
     $member = Member::find($id);
     $title = 'League Together - ' . $member->team->club->name . ' Teams';
     $type = Input::get('type');
     $club = Club::find($member->team->club->id);
     switch ($type) {
         case 'full':
             $price = $member->getOriginal('due');
             $today = Carbon::Now();
             $early = new Carbon($member->early_due_deadline);
             if ($member->early_due_deadline) {
                 if ($today->startOfDay() <= $early->startOfDay()) {
                     $price = $member->getOriginal('early_due');
                 }
             }
             $item = array('id' => $member->team->id, 'name' => "Membership Team " . $member->team->name, 'price' => $price, 'quantity' => 1, 'organization' => $member->team->club->name, 'organization_id' => $member->team->club->id, 'member_id' => $member->id, 'player_id' => $member->player->id, 'user_id' => $user->id, 'type' => $type, 'autopay' => false);
             Cart::insert($item);
             foreach (Cart::contents() as $item) {
                 $item->name = "Membership Team " . $member->team->name;
                 $item->quantity = 1;
             }
             return Redirect::action('MemberController@paymentCreate', array($member->id));
         case 'plan':
             $price = $member->plan->getOriginal('initial');
             $item = array('id' => $member->team->id, 'name' => "Membership Team " . $member->team->name, 'price' => $price, 'quantity' => 1, 'organization' => $member->team->club->name, 'organization_id' => $member->team->club->id, 'member_id' => $member->id, 'player_id' => $member->player->id, 'user_id' => $user->id, 'type' => $type, 'autopay' => false);
             Cart::insert($item);
             foreach (Cart::contents() as $item) {
                 $item->name = "Membership Team " . $member->team->name;
                 $item->quantity = 1;
             }
             return Redirect::action('MemberController@paymentCreate', array($member->id));
         default:
             return Redirect::action('MemberController@paymentSelect', array($member->id))->with('error', 'Opps we are having some trouble processing your request, please try later. Error# 345');
     }
 }
Example #6
0
 public function testClubHasUsers()
 {
     $club = Club::find(1);
     $this->assertEquals(10, $club->users->length);
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $startDate = Carbon::now();
     $from = Carbon::now()->hour(0)->minute(0)->second(0);
     $to = Carbon::now()->hour(23)->minute(59)->second(59);
     $schedules = SchedulePayment::where('status', 0)->whereBetween('date', array($from, $to))->with('member.user.profile')->get();
     //$schedules = SchedulePayment::where('status', 0)->with('member.user.profile')->get();
     $errors = array();
     $totalAmount = array();
     $errorAmount = array();
     //save daylog
     $dayLog = new ScheduleDailyLog();
     $dayLog->started_on = Carbon::now()->toDateTimeString();
     $dayLog->payments_count = count($schedules);
     $dayLog->save();
     Cart::destroy();
     foreach ($schedules as $schedule) {
         try {
             $vault = $schedule->member->user->profile->customer_vault;
             $user = User::find($schedule->member->user->id);
             $player = Player::find($schedule->member->player->id);
             $club = Club::find($schedule->club_id);
             $team = Team::find($schedule->member->team_id);
             $uuid = Uuid::generate();
             $member = Member::find($schedule->member->id);
             $history = SchedulePayment::find($schedule->id);
             //manually login user out before login new user
             Auth::logout();
             //manually login user
             Auth::login($user);
             //clear cart content
             Cart::destroy();
             //set cart item
             $itemCart = array('id' => $team->id, 'name' => "Scheduled payment for " . $team->name, 'price' => $schedule->subtotal, 'quantity' => 1, 'organization' => $club->name, 'organization_id' => $club->id, 'player_id' => $player->id, 'user_id' => $user->id, 'type' => 'full', 'autopay' => true);
             Cart::insert($itemCart);
             //check if vault exist
             if ($vault) {
                 $param = array('customer_vault_id' => $vault, 'discount' => null, 'club' => $club->id);
                 $payment = new Payment();
                 $transaction = $payment->sale($param);
                 //temp json_decode(json_encode($array), FALSE);
                 //$transaction = json_decode(json_encode(array('response' => 1, 'total'=>$schedule->total, 'fee'=>$schedule->fee)), FALSE);
                 if ($transaction->response == 3 || $transaction->response == 2) {
                     $errors[] = array('payment_schedule_id' => $schedule->id, 'error_description' => $transaction->transactionid . ' : ' . $transaction->responsetext, 'error_amount' => $schedule->total, 'daily_log_id' => $dayLog->id);
                     array_push($errorAmount, number_format($schedule->total, 2));
                     //Email error
                     $emailerrorstatus = $payment->error($transaction, $club->id, $player->id);
                 } else {
                     array_push($totalAmount, number_format($transaction->total, 2));
                     $payment->id = $uuid;
                     $payment->customer = $vault;
                     $payment->transaction = $transaction->transactionid;
                     $payment->subtotal = $transaction->subtotal;
                     $payment->service_fee = $transaction->fee;
                     $payment->total = $transaction->total;
                     $payment->promo = $transaction->promo;
                     $payment->tax = $transaction->tax;
                     $payment->discount = $transaction->discount;
                     $payment->club_id = $club->id;
                     $payment->user_id = $user->id;
                     $payment->player_id = $player->id;
                     $payment->event_type = null;
                     $payment->type = $transaction->type;
                     $payment->save();
                     //Email receipt
                     $payment->receipt($transaction, $club->id, $player->id);
                     $sale = new Item();
                     $sale->description = $itemCart['name'];
                     $sale->quantity = $itemCart['quantity'];
                     $sale->price = $itemCart['price'];
                     $sale->fee = $transaction->fee;
                     $sale->member_id = $member->id;
                     $sale->team_id = $team->id;
                     $sale->payment_id = $uuid;
                     $sale->save();
                     //update schedule
                     $history->status = 2;
                     $history->save();
                 }
             } else {
                 //save error that vault didnt exist
                 $errors[] = array('payment_schedule_id' => $schedule->id, 'error_description' => 'Customer Vault not found', 'error_amount' => number_format($schedule->total, 2), 'daily_log_id' => $dayLog->id);
                 array_push($errorAmount, number_format($schedule->total, 2));
             }
         } catch (Exception $e) {
             //save internal error
             $errors[] = array('payment_schedule_id' => $schedule->id, 'error_description' => $e, 'error_amount' => number_format($schedule->total, 2), 'daily_log_id' => $dayLog->id);
             array_push($errorAmount, number_format($schedule->total, 2));
         }
     }
     //end of foreach schedule
     //save log for everything done
     $dayLogEnd = ScheduleDailyLog::find($dayLog->id);
     $dayLogEnd->ended_on = Carbon::now()->toDateTimeString();
     $dayLogEnd->successful_count = Count($totalAmount);
     $dayLogEnd->error_count = Count($errors);
     $dayLogEnd->total_amount = array_sum($totalAmount);
     $dayLogEnd->total_amount_error = array_sum($errorAmount);
     $dayLogEnd->save();
     //save log for errors
     if (Count($errors) > 0) {
         foreach ($errors as $errorItem) {
             $scheduleError = new ScheduleDailyError();
             $scheduleError->error_description = $errorItem['error_description'];
             $scheduleError->error_amount = $errorItem['error_amount'];
             $scheduleError->payment_schedule_id = $errorItem['payment_schedule_id'];
             $scheduleError->daily_log_id = $dayLogEnd->id;
             $scheduleError->save();
         }
     }
     return Log::info($errors);
 }
Example #8
0
function link_users_to_clubs()
{
    foreach (User::find('all') as $user) {
        foreach (Club::find('all') as $club) {
            ClubUser::create(array('user_id' => $user->id, 'club_id' => $club->id));
        }
    }
}
 /**
  * Show the form for editing the specified resource.
  * GET /contact/{id}/edit
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $user = Auth::user();
     $follow = Follower::where("user_id", "=", $user->id)->FirstOrFail();
     $club = Club::find($follow->club_id);
     $players = $user->players;
     $contact = Contact::find($id);
     $title = 'League Together - Player';
     return View::make('app.account.contact.edit')->with('page_title', $title)->with('players', $players->lists('firstname', 'id'))->with('club', $club)->with('contact', $contact)->withUser($user);
 }
 public function PaymentRemoveCartItemTeam($club, $id)
 {
     $club = Club::find($club);
     $team = Team::find($id);
     Cart::destroy();
     return Redirect::action('ClubPublicController@paymentSelectTeam', array($club->id, $team->id));
 }
 /**
  * Update the specified resource in storage.
  * PUT /club/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $user = Auth::user();
     $validator = Validator::make(Input::all(), Club::$rules_update);
     if ($validator->passes()) {
         $club = Club::find($id);
         $club->name = Input::get('name');
         $club->phone = Input::get('contactphone');
         $club->website = Input::get('website');
         $club->email = Input::get('contactemail');
         $club->add1 = Input::get('add1');
         $club->city = Input::get('city');
         $club->state = Input::get('state');
         $club->zip = Input::get('zip');
         $club->logo = Input::get('logo');
         $club->waiver = Input::get('waiver');
         $club->save();
         $status = $club->save();
         if ($status) {
             return Redirect::back()->with('notice', 'Club updated successfully');
         }
     }
     $error = $validator->errors()->all(':message');
     return Redirect::back()->withErrors($validator)->withInput();
 }