/** * Creates a new User model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (!\Yii::$app->user->isGuest) { return $this->goHome(); } $model = new User(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $email = new Email(); $email->to_name = $model->name; $email->to_email = $model->email; $email->subject = "Your Tixty Purchase"; $message = <<<EOT Hi {$model->name}!! You just registered as a user. Use {$model->email} to login with the password you chose and start buying tickets at <a href="https://tixty.co.uk/">tixty.co.uk</a> Thanks, Tixty EOT; $email->body = nl2br($message); $email->save(); $email->send(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Displays a single Organisation model. * @param string $id * @return mixed */ public function actionConnect($code, $state) { $sql = "SELECT * FROM organisation WHERE SHA1(CONCAT(`id`, :salt, `name`)) = :state"; $organisation = Organisation::findBySql($sql, [':salt' => 'jiejieugs9837', ':state' => $state])->one(); if (\Yii::$app->user->isGuest) { return $this->redirect('/site/denied/'); } $user = \Yii::$app->user->identity; if (!$user->admin && count($user->organisations) == 0) { return $this->redirect('/site/denied/'); } else { if (!$user->admin) { $organisations = $user->organisations; foreach ($organisations as $org) { if ($organisation->id == $org->id) { break 2; } } return $this->redirect('/site/denied'); } } if (!empty($code)) { $token_request_body = array('grant_type' => 'authorization_code', 'client_id' => Yii::$app->params['stripeClientID'], 'code' => $code, 'client_secret' => Yii::$app->params['stripeSecretKey']); $req = curl_init('https://connect.stripe.com/oauth/token'); curl_setopt($req, CURLOPT_RETURNTRANSFER, true); curl_setopt($req, CURLOPT_POST, true); curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($token_request_body)); curl_setopt($req, CURLOPT_SSL_VERIFYPEER, true); //curl_setopt($req, CURLOPT_CAINFO, '/home/web/tickets/cacert.pem'); $respCode = curl_getinfo($req, CURLINFO_HTTP_CODE); $resp = json_decode(curl_exec($req), true); curl_close($req); $organisation = $this->findModel($organisation->id); $organisation->stripe_access_token = $resp['access_token']; $organisation->stripe_public_key = $resp['stripe_publishable_key']; $organisation->stripe_user_id = $resp['stripe_user_id']; $organisation->stripe_refresh_token = $resp['refresh_token']; $organisation->save(); $organisation_test = Organisation::findOne($organisation->id); $result = $organisation_test->stripe_user_id ? "successful" : "unsuccessful"; $founder = User::findOne(OrganisationMembers::findOne(['organisation_id' => $organisation->id, 'founder' => 1])->user_id); $email = new Email(); $email->to_name = $founder->name; $email->to_email = $founder->email; $email->subject = "Authorisation Attempt"; $email->body = <<<EOT You tried to connect {$organisation->name} to Tixty. That was {$result}. Tixty EOT; $email->save(); $email->send(); $response = print_r($resp, true); $email = new Email(); $email->to_name = $email->sender_name; $email->to_email = $email->sender_email; $email->subject = "Authorisation Attempt for {$organisation->name} {$result}"; $email->body = <<<EOT <pre>{$response}</pre> EOT; $email->save(); $email->send(); } return $this->redirect('/organisation/view', ['id' => $organisation->id]); }
public function actionSave() { $session = new Session(); $user = Yii::$app->user->identity; $cart = Cart::getCurrentCart(); $cart->processCart(); if ($cart->total > 0) { return $this->actionCharge(); } $cart->status = Cart::CART_SOLD; $cart->save(); $session->addSuccess(Yii::t('app', 'Congratulations, you\'ve completed your order!')); $cart_lines = []; foreach ($cart->items as $item) { $cart_lines[] = $item->ticket->group->event->name . ': ' . $item->ticket->name . ' x' . $item->quantity . ' @ ' . $item->ticket->ticket_price . ' each'; } $cart_details = implode("\n", $cart_lines); $email = new Email(); $email->to_name = $user->name; $email->to_email = $user->email; $email->subject = "Your Tixty Purchase"; $message = <<<EOT Hi {$user->name}!! You just bought {$cart->quantity} tickets for a total of {$cart->total} - details below. Thanks, Tixty --- {$cart_details} EOT; $email->body = nl2br($message); $email->save(); $email->send(); $email = new Email(); $email->to_name = "Tixty"; $email->to_email = \Yii::$app->params['adminEmail']; $email->subject = "Tixty Purchase #{$cart->id}"; $message = <<<EOT {$user->name} just bought {$cart->quantity} tickets for a total of {$cart->total} - details below. Tixty --- {$cart_details} EOT; $email->body = nl2br($message); $email->save(); $email->send(); return $this->redirect('index'); }