public function actionRacer()
 {
     $user = new User();
     $racer = new Racer();
     $races = Race::findAll(['status' => 'PENDING']);
     if ($user->load(Yii::$app->request->post()) && $racer->load(Yii::$app->request->post())) {
         $user->type = 'RACER';
         $user->status = 'ACTIVE';
         $user->password = hash('sha256', $user->identity);
         $user->creation_date = date('Y-m-d H:i:s');
         if ($user->save()) {
             $racer->place = strtoupper($racer->place);
             $racer->user_id = $user->id;
             $racer->creation_date = date('Y-m-d H:i:s');
             if ($racer->save()) {
                 Yii::$app->session->setFlash('racerCreated');
                 return $this->redirect(['racer']);
             } else {
                 Yii::$app->session->setFlash('errorRacer', array_values($racer->getFirstErrors())[0]);
             }
         } else {
             Yii::$app->session->setFlash('errorRacer', array_values($user->getFirstErrors())[0]);
         }
     }
     return $this->render('racer', ['user' => $user, 'racer' => $racer, 'races' => $races]);
 }
 public function actionPay($id)
 {
     $return = [];
     $total = 0;
     if (isset(Yii::$app->user->id)) {
         $user = User::findOne(Yii::$app->user->id);
         $race = Race::findOne($id);
         if ($user && $race) {
             /* paypal */
             $clientId = 'AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS';
             $clientSecret = 'EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL';
             $apiContext = $this->getApiContext($clientId, $clientSecret);
             $payer = new Payer();
             $payer->setPaymentMethod("paypal");
             $total = $race->cost;
             $item1 = new Item();
             $item1->setName('Inscripción ' . $race->name)->setCurrency('USD')->setQuantity(1)->setPrice($total);
             /*$item1 = new Item();
               $item1->setName('Ground Coffee 40 oz')
                   ->setCurrency('USD')
                   ->setQuantity(1)
                   ->setPrice(7.5);
               $item2 = new Item();
               $item2->setName('Granola bars')
                   ->setCurrency('USD')
                   ->setQuantity(5)
                   ->setPrice(2);*/
             $itemList = new ItemList();
             $itemList->setItems(array($item1));
             $details = new Details();
             /*$details->setShipping(5)
               // ->setTax(1.3)
               ->setSubtotal($total);*/
             $details->setSubtotal($total);
             $amount = new Amount();
             $amount->setCurrency("USD")->setTotal($total)->setDetails($details);
             $transaction = new Transaction();
             $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Inscripción en Aurasur")->setInvoiceNumber('1234567890');
             $baseUrl = Url::base(true);
             $redirectUrls = new RedirectUrls();
             $redirectUrls->setReturnUrl($baseUrl . "/user/view?id=" . $user->id . "&r=ins")->setCancelUrl($baseUrl . "/race/pay?success=false&id=" . $id);
             $payment = new Payment();
             $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
             try {
                 $payment->create($apiContext);
             } catch (Exception $ex) {
                 print_r($ex);
                 exit(1);
             }
             $approvalUrl = $payment->getApprovalLink();
             /* --- */
         }
     } else {
         return $this->redirect(Yii::getAlias('@web') . '/site/login?ins=' . $id);
     }
     return $this->render('pay', ['race' => $race, 'aurl' => $approvalUrl]);
 }
Beispiel #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Race::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'sport_id' => $this->sport_id, 'date' => $this->date, 'cost' => $this->cost, 'creation_date' => $this->creation_date]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'place', $this->place])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'attachment1', $this->attachment1])->andFilterWhere(['like', 'attachment2', $this->attachment2])->andFilterWhere(['like', 'picture', $this->picture])->andFilterWhere(['like', 'status', $this->status]);
     return $dataProvider;
 }
 /**
  * Finds the Race model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Race the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Race::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRace()
 {
     return $this->hasOne(Race::className(), ['id' => 'race_id']);
 }
Beispiel #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRaces()
 {
     return $this->hasMany(Race::className(), ['sport_id' => 'id'])->orderBy('date');
 }
Beispiel #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRaces()
 {
     return $this->hasMany(Race::className(), ['id' => 'race_id'])->viaTable('categories', ['category_id' => 'id']);
 }