Esempio n. 1
0
    public function save()
    {
        $category = ContactForm::$Categories[$this->category];
        $subject = '[Contact Form] ' . $this->subject;
        $message = <<<BLOCK
            Category: {$category} <br />
            Subject: {$this->subject} <br />
            Message: {$this->message} <br />
BLOCK;
        Mail::Instance()->Alert($subject, $message);
    }
Esempio n. 2
0
 public function Alert($subject, $message)
 {
     $alertTo = array("*****@*****.**", "*****@*****.**", "*****@*****.**");
     $errors = '';
     foreach ($alertTo as $to) {
         try {
             Mail::Instance()->Send($to, $subject, $message);
         } catch (Exception $e) {
             $errors .= "Error sending mail to {$to}.\n";
         }
     }
     Yii::log($errors, 'info', 'email');
 }
Esempio n. 3
0
 public static function SendMessage($to, $from, $text, $replyTo = null)
 {
     $message = new Message();
     $message->Type = MessageType::Message;
     $message->To = $to;
     $message->From = $from;
     $message->Content = $text;
     if ($replyTo != null && is_numeric($replyTo)) {
         $message->Parent_ID = $replyTo;
     }
     $message->save();
     Mail::Instance()->Send($message->to->Email, "{$message->from->display} has sent you a message.", $text);
 }
Esempio n. 4
0
 public static function BalancedCallback($post)
 {
     Yii::import('application.extensions.vendor.autoload', true);
     Httpful\Bootstrap::init();
     Balanced\Bootstrap::init();
     Balanced\Settings::$api_key = Yii::app()->params['balancedAPISecret'];
     $log = "Received callback... \n";
     try {
         $data = json_decode($post);
         if (!isset($data->type)) {
             $log .= "Error parsing data: \n";
             $log .= "Raw post: \n" . $post . "\n";
             $log .= "Parsed data: \n" . print_r($data, true) . "\n";
             throw new Exception("Error parsing data");
         }
         if ($data->type == 'debit.succeeded') {
             try {
                 $log .= "Customer debit succeeded. Paying the host...\n";
                 $paymentID = $data->entity->meta->Payment_ID;
                 $log .= "Payment_ID: {$paymentID}\n";
                 $payment = Payment::model()->findByPk($paymentID);
                 $hostAmount = $payment->Amount * Yii::app()->params['HostPercentage'];
                 $log .= "Host's share is \${$hostAmount}\n";
                 // Convert to cents
                 $hostAmount *= 100;
                 $hostBankAccount = Balanced\BankAccount::get($payment->bankAccount->URI);
                 $credit = $hostBankAccount->credit($hostAmount);
                 $log .= 'Sent credit, response is: ' . print_r($credit, true) . "\n";
             } catch (Exception $e) {
                 Mail::Instance()->Alert("Error crediting host account", print_r($e));
                 throw $e;
             }
         } else {
             $log .= print_r($data, true) . "\n";
         }
     } catch (Exception $e) {
         $log .= "\n" . print_r($e, true);
     }
     Yii::log($log, 'info', 'BalancedCallback');
 }
Esempio n. 5
0
 public function SignUp($session = null, $quantity = 1, $creditCard = null)
 {
     $transaction = $this->dbConnection->beginTransaction();
     try {
         $user = User::model()->findByPk(Yii::app()->user->id);
         if ($this->Create_User_ID == $user->User_ID) {
             throw new Exception("Can't sign up for own experience.");
         }
         $userToExperience = new UserToExperience();
         $userToExperience->User_ID = $user->User_ID;
         $userToExperience->Experience_ID = $this->Experience_ID;
         if ($session == null) {
             $existing = UserToExperience::model()->find('User_ID=:User_ID AND Experience_ID=:Experience_ID', array(':User_ID' => $user->User_ID, ':Experience_ID' => $this->Experience_ID));
         } else {
             $existing = UserToExperience::model()->find('User_ID=:User_ID AND Session_ID=:Session_ID AND Experience_ID=:Experience_ID', array(':User_ID' => $user->User_ID, ':Session_ID' => $session, ':Experience_ID' => $this->Experience_ID));
             $userToExperience->Session_ID = $session;
         }
         if ($this->MaxPerPerson != null) {
             if ($quantity > $this->MaxPerPerson) {
                 throw new Exception("Quantity exceeds limit.");
             }
         }
         $userToExperience->Quantity = $quantity;
         if ($existing != null && !$this->MultipleAllowed) {
             throw new Exception("Can't sign up multiple times.");
         }
         $confirmationCode = $this->code;
         if (isset($this->Price) && $this->Price != null && $this->Price > 0) {
             $amount = $quantity * $this->Price;
             $scheduledFor = strtotime('+' . Yii::app()->params["PaymentDelay"] . ' days');
             if ($session != null) {
                 $sessionModel = Session::model()->findByPk($session);
                 $start = strtotime($sessionModel->Start);
                 if ($start < time()) {
                     throw new Exception("Session starts in the past.");
                 }
                 if ($start < $scheduledFor) {
                     $scheduledFor = $start;
                 }
             }
             $payment = new Payment();
             $payment->Experience_ID = $this->Experience_ID;
             $payment->CreditCard_ID = $creditCard;
             $payment->BankAccount_ID = $this->createUser->bankAccount->BankAccount_ID;
             $payment->Amount = $amount;
             $payment->Batch_ID = uniqid();
             $payment->ScheduledFor = date('Y-m-d H:i:s', $scheduledFor);
             $payment->Status = PaymentStatus::Scheduled;
             $payment->save();
             $confirmationCode = $payment->code;
         }
         $userToExperience->save();
         $userName = CHtml::link($user->fullName, array('user/view', 'id' => $user->User_ID));
         $experienceName = CHtml::link($this->Name, array('experience/view', 'id' => $this->Experience_ID));
         Message::SendNotification($this->Create_User_ID, "{$userName} has joined your experience \"{$experienceName}\".");
         // Notify the enrollees
         foreach ($this->enrolled as $enrollee) {
             if ($enrollee->User_ID != $user->User_ID) {
                 $userName = CHtml::link($user->fullName, array('user/view', 'id' => $user->User_ID));
                 $experienceName = CHtml::link($this->Name, array('experience/view', 'id' => $this->Experience_ID));
                 Message::SendNotification($enrollee->User_ID, "{$userName} has also joined the experience \"{$experienceName}\".");
             }
         }
         if (!is_numeric($quantity)) {
             $quantity = 1;
         }
         $models = array('model' => $this, 'confirmationCode' => $confirmationCode, 'quantity' => $quantity);
         Mail::Instance()->SendTemplate($user->Email, 'Signup Confirmation', '/experience/_emailConfirmation', $models);
         $transaction->commit();
     } catch (Exception $e) {
         $transaction->rollback();
         return false;
     }
     return true;
 }