Exemplo n.º 1
0
 public function store($ques, $resp)
 {
     $data = $ques->getParsedBody();
     $data['birthday'] = $data['year'] . '-' . $data['month'] . '-' . $data['day'];
     $runner = new Runner();
     $runner->error = 'Please fill in all the required fields.';
     if ($runner->validate($data)) {
         if ($runner->create($data)) {
             $data['name'] = $data['first_name'] . ' ' . $data['last_name'];
             // Envoi d'un mail de confirmation
             $body = $this->view->fetch('mail/register.twig', ['runner' => $data]);
             $message = \Swift_Message::newInstance('You were registered!')->setFrom(['*****@*****.**' => 'Postrail'])->setTo([$data['email'] => $data['name']])->setBody($body, 'text/html');
             $this->mailer->send($message);
             // Retour à la liste des coureurs avec message
             $this->flash->addMessage('success', 'Welcome and keep running!');
             return $resp->withRedirect('/runner');
         }
         $runner->error = 'We were unable to store your datas.';
     }
     $this->flash->addMessage('error', $runner->error);
     return $resp->withRedirect('/runner/create');
 }
Exemplo n.º 2
0
 public function persist(Requests\RunnerInputRequest $request)
 {
     $runner = Runner::create($request->all());
     $race = $runner->race;
     $event = $runner->event;
     $payment = $runner->payment;
     $type = $request->get('type');
     if ($error = checkRunnerDoc($race, $runner->doc_num)) {
         $runner->comment .= Carbon::now() . ' Duplicated document number.';
         $runner->save();
         return redirect($race->prefix . '/error')->with('doc', $error);
     }
     if ($payment->id == 2) {
         $code = Code::where('code', $runner->ticket)->first();
         if ($error = checkCode($race, $runner->event, $code, $runner->ticket)) {
             $runner->comment .= Carbon::now() . ' Redeemed code.';
             return redirect($race->prefix . '/error')->with('code', $error);
         } else {
             return redirect($race->prefix . '/subscribe')->with(['runner_id' => $runner->id, 'type' => $type]);
         }
     } else {
         $gateway = $runner->gateway;
         $transaction = Transaction::find($runner->ticket);
         if ($transaction->coupon != '') {
             $coupon = Coupon::where('coupon', $transaction->coupon)->first();
             if ($error = checkCoupon($coupon, $transaction->coupon)) {
                 $runner->comment .= Carbon::now() . ' Redeemed coupon.';
                 return redirect($race->prefix . '/error')->with('coupon', $error);
             }
         }
         switch ($gateway->mode) {
             case 'production':
                 $request_url = $gateway->url_production;
                 break;
             case 'development':
                 $request_url = $gateway->url_development;
                 break;
             case 'emulation':
                 $request_url = $gateway->url_emulator;
                 break;
             default:
                 $request_url = $gateway->url_production;
                 break;
         }
         return view('enroll.pay_request')->with(['runner' => $runner, 'race' => $race, 'event' => $event, 'gateway' => $gateway, 'transaction' => $transaction, 'request_url' => $request_url]);
     }
 }