public function download($gateway_id)
 {
     $header = app('request')->header();
     if (!$this->check($header)) {
         return response('Unauthorized', 401);
     }
     $gateway = Gateway::find($gateway_id);
     $gateway->content = File::get($gateway->path);
     return $gateway;
 }
 /** API methods **/
 public function authGateway(Request $request)
 {
     $data = $request->only(['key']);
     $validator = Validator::make($data, ['key' => 'required']);
     if ($validator->fails()) {
         return validatorError($validator->errors());
     }
     $gateway = Gateway::where('access_key', $data['key'])->first();
     if ($gateway == null) {
         return errorResponse('gateway_not_found', 404);
     }
     return successResponse($gateway->authResponse());
 }
 public function search(Request $request, $race_id)
 {
     $race = Race::find($race_id);
     $gateways = Gateway::where('enabled', true)->get();
     $gateway_list = $gateways->lists('name', 'id');
     $runners = [];
     $codes = [];
     $transactions = [];
     if (!($criteria = $request->get('criteria'))) {
         $criteria = '';
     }
     if (!($type = $request->get('type'))) {
         $type = '';
     }
     if (!($runner_status = $request->get('runner_status'))) {
         $runner_status = '';
     }
     if (!($payment_id = $request->get('payment_id'))) {
         $payment_id = '';
     }
     if (!($code_status = $request->get('code_status'))) {
         $code_status = '';
     }
     if (!($transaction_status = $request->get('transaction_status'))) {
         $transaction_status = '';
     }
     if (!($gateway_id = $request->get('gateway_id'))) {
         $gateway_id = '';
     }
     if (!($date = $request->get('date'))) {
         $date = '';
     }
     if ($request->has('criteria')) {
         switch ($type) {
             case 'runner_name':
                 $runners_query = Runner::where([['last_name_01', 'like', '%' . $criteria . '%'], ['race_id', $race->id]]);
                 break;
             case 'runner_doc':
                 $runners_query = Runner::where([['doc_num', $criteria], ['race_id', $race->id]]);
                 break;
             case 'runner_bib':
                 $runners_query = Runner::where([['bib', $criteria], ['race_id', $race->id]]);
                 break;
             case 'code':
                 $codes = Code::where([['code', 'like', '%' . $criteria . '%'], ['race_id', $race->id]]);
                 if ($code_status < 2) {
                     $codes = $codes->where('status', $code_status);
                 }
                 $codes = $codes->get();
                 break;
             case 'transaction':
                 $transactions = Transaction::where('id', $criteria);
                 if ($transaction_status > 3) {
                     $transactions = $transactions->where('status', $transaction_status);
                 }
                 if ($gateway_id > 0) {
                     $transactions = $transactions->where('gateway_id', $gateway_id);
                 }
                 $transactions = $transactions->get();
                 break;
             default:
                 $runners_query = Runner::where('last_name_01', 'like', '%' . $criteria . '%')->get();
                 break;
         }
         if (!empty($runners_query)) {
             if ($runner_status < 2) {
                 $runners_query = $runners_query->where('status', $runner_status);
             }
             if ($payment_id > 0) {
                 $runners_query = $runners_query->where('payment_id', $payment_id);
             }
             $runners = $runners_query->get();
         }
     }
     return view('admin.search')->with(['race' => $race, 'runners' => $runners, 'codes' => $codes, 'transactions' => $transactions, 'gateway_list' => $gateway_list, 'criteria' => $criteria, 'type' => $type, 'date' => $date, 'runner_status' => $runner_status, 'code_status' => $code_status, 'transaction_status' => $transaction_status, 'payment_id' => $payment_id, 'gateway_id' => $gateway_id]);
 }
 public function runner(Request $request, $prefix)
 {
     if ($race_id = foundInRequest($request, 'race_id')) {
         $race = Race::find($race_id);
     } else {
         return redirect($prefix . '/error');
     }
     $doc_type = foundInRequest($request, 'doc_type');
     $doc_num = foundInRequest($request, 'doc_num');
     $gender = foundInRequest($request, 'gender');
     $dob = Carbon::parse(foundInRequest($request, 'dob'));
     $event = Event::find(foundInRequest($request, 'event_id'));
     $payment = Payment::find(foundInRequest($request, 'payment_id'));
     $ticket = foundInRequest($request, 'ticket');
     if (!($gateway = Gateway::find(foundInRequest($request, 'gateway_id')))) {
         $gateway = Gateway::makeDummy();
     }
     if ($payment->id == 1) {
         $transaction = Transaction::find(foundInRequest($request, 'ticket'));
         $code = Code::makeDummy();
     } else {
         $code = Code::where('code', foundInRequest($request, 'ticket'))->first();
         $transaction = Transaction::makeDummy();
     }
     if ($gender == 'M') {
         $gender_verbose = 'Masculino';
         $sizes = $event->maleSizes($race->size_threshold)->lists('name_long', 'id')->all();
     } else {
         $gender_verbose = 'Femenino';
         $sizes = $event->femaleSizes($race->size_threshold)->lists('name_long', 'id')->all();
     }
     $type = $request->session()->get('type');
     return view('enroll.runner')->with(['doc_type' => $doc_type, 'doc_num' => $doc_num, 'gender' => $gender, 'dob' => $dob, 'race' => $race, 'event' => $event, 'payment' => $payment, 'ticket' => $ticket, 'gateway' => $gateway, 'transaction' => $transaction, 'code' => $code, 'gender_verbose' => $gender_verbose, 'sizes' => $sizes, 'type' => $type]);
 }