public function edit($id = null)
 {
     $tweet = $this->load_tweet($id);
     if ($tweet->message_id) {
         Site::Flash('error', 'This tweet has already been posted to Twitter. It cannot be edited');
         RedirectBack('admin/twitter');
     }
     if ($this->post) {
         $tweet->twitter_account_id = $this->PostData('twitter_account_id');
         $tweet->message = $this->PostData('message');
         $tweet->set_publish_at($this->PostData('publish_at'));
         if ($tweet->save()) {
             Site::Flash('notice', 'The tweet has been edited');
             Redirect('admin/twitter/tweets');
         }
     }
     $accounts = array();
     $allAccounts = TwitterAccount::find_all();
     foreach ($allAccounts as $account) {
         $accounts[$account->id] = $account->name;
     }
     $this->assign('accounts', $accounts);
     $this->assign('tweet', $tweet);
     $this->title = 'Edit Tweet';
     $this->render('tweet/edit.tpl');
 }
 public function healthcheck()
 {
     // Check we have data from Mandrill
     $data = json_decode($this->PostData('mandrill_events'));
     if (!$data) {
         echo 'OK - No Data';
         die;
     }
     // We need to check if we've sent an alert in the past
     // 8 hours, if not, send another one.
     $content = "Exchange Alert: Delivery Delay";
     $cutoff = time() - 3600 * 8;
     $lastTweet = Tweet::find("tweets.message = '{$content}'", "publish_at DESC");
     if ($lastTweet && $lastTweet->publish_at > $cutoff) {
         echo 'OK - Alert Already Sent';
         die;
     }
     $account = TwitterAccount::find_by_code('site');
     $account->add_tweet($content);
     echo 'OK - Alert Sent';
     die;
 }
Example #3
0
 /**
  * Processes an IPN request.
  * 
  * @param type $postData HTTP POST data from the request
  * @return string Any output for the notification page
  */
 public static function processPayment($gateway, $postData)
 {
     $responseData = array_merge(array('cmd' => '_notify-validate'), $postData);
     $qs = http_build_query($responseData);
     $curl = curl_init($gateway->getSetting('endpoint'));
     global $config;
     if ($config['dev'] or true) {
         // Paypal sandbox certificate is apparently invalid
         curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     }
     curl_setopt($curl, CURLOPT_POST, true);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $qs);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     $response = curl_exec($curl);
     curl_close($curl);
     if (!isset($postData['transaction_subject'])) {
         // No transaction subject
     }
     $ref = explode("-", $postData['custom']);
     if (count($ref) < 2) {
         return;
     }
     $type = $ref[0];
     $id = $ref[1];
     if ($type != 'cart') {
         // Not a cart, nothing to do here
         return;
     }
     $id = mysql_real_escape_string($id);
     $cart = Cart::find_by_id($id);
     $payment = new PaymentTransaction();
     $payment->processResponse = $postData;
     $payment->paymentgateway_id = $gateway->id;
     $payment->amount = $postData['mc_gross'];
     $payment->externalid = $postData['txn_id'];
     $payment->status = 'ptsFailed';
     $payment->sender = $postData['payer_email'];
     $payment->method = "PayPal ({$postData['payer_email']})";
     if (!$cart) {
         // Cart not found
         $payment->failurereason = "Transaction specified a cart, but the cart was not found";
         $payment->save();
         Email::send_payment_alert($postData, $payment->failurereason, $response);
         return;
     }
     $cart->check_discounts();
     // Make Payment Object
     $payment->cart_id = $cart->id;
     if ($response != 'VERIFIED') {
         // IPN response is not verified
         $payment->failurereason = "The transaction was not verified";
         $payment->save();
         Email::send_payment_alert($postData, $payment->failurereason, $response, $cart);
         return;
     }
     if ($postData['payment_status'] != "Completed") {
         // Payment status is not completed
         $payment->failurereason = "Payment status is not completed";
         $payment->save();
         Email::send_payment_alert($postData, $payment->failurereason, $response, $cart);
         return;
     }
     if ($postData['receiver_email'] != $gateway->getSetting('email')) {
         // Sent to the wrong email
         $payment->failurereason = "Payment was sent to a different email address";
         $payment->save();
         Email::send_payment_alert($postData, $payment->failurereason, $response, $cart);
         return;
     }
     $total = $cart->cost() + $cart->card_fee();
     if ($postData['mc_gross'] * 100 < $total) {
         // Cart is not enough
         $payment->failurereason = "Payment was not enough for the cart";
         $payment->save();
         Email::send_payment_alert($postData, $payment->failurereason, $response, $cart);
         return;
     }
     if ($cart->paid) {
         // Cart is already marked paid
         $payment->failurereason = "The cart has already been paid for";
         $payment->save();
         Email::send_payment_alert($postData, $payment->failurereason, $response, $cart);
         return;
     }
     // Payment is valid and for the right amount for our cart!
     $payment->status = 'ptsTaken';
     $payment->save();
     Email::send_user_paymentconfirmation($payment);
     // Mark cart as paid, this will trigger the event signup
     // email to the user.
     $cart->mark_paid($payment, "Paypal");
     // Email staff about payment
     Email::send_payment_complete($postData, $response, $cart);
     // And alert on Twitter
     $account = TwitterAccount::find_by_code('site');
     if ($account) {
         $signups = $cart->get_signups();
         $eventsignups = array();
         foreach ($signups as $signup) {
             $amount = sprintf("%.2f", $signup->event_ticket->cost / 100);
             $paidsignups = count($signup->event->participants("paid"));
             $message = "{$signup->user->nickname} has paid for {$signup->event->name} {$signup->event_ticket->name} [£{$amount}] ({$paidsignups}/{$signup->event->capacity}) [{$signup->id}]";
             $account->add_tweet($message);
         }
     }
 }
 protected static function get_fields()
 {
     return self::select_fields() . ", " . TwitterAccount::select_fields();
 }
 function createAccounts($argv)
 {
     echo "Creating Accounts<br>";
     // Tally up total account user wants to create
     $total = 0;
     foreach ($argv as $argIndex => $arg) {
         if (stripos($argIndex, "_number") !== false) {
             $total += $arg;
         }
     }
     $userCredits = $this->getUserCredits();
     if ($total > $userCredits) {
         echo "You are attempting to create " . $total . " accounts but you only have " . $userCredits . " credits.<br>Add More Credits To Your Account.";
     } else {
         $accounts = $this->getUserAccounts();
         if (isset($argv['twitter_number'])) {
             while ($argv['twitter_number'] > 0) {
                 $proxy = $this->Proxy->getRandomProxy();
                 $obj = new TwitterAccount($proxy['proxy'], $proxy['port']);
                 $range = 15 - strlen($this->username);
                 $range = $range < 15 ? $range : 15;
                 $max = pow(10, $range);
                 $tUsername = $this->username . rand(0, $max);
                 $success = $obj->create($this->username, $tUsername, 'mypassword', $tUsername . '@chrisqueen.com');
                 if ($success) {
                     echo "Twitter Account Created. Username:  "******"<br>";
                     $argv['twitter_number']--;
                     $userCredits--;
                     $this->addToAccounts($accounts, $obj, 'twitter');
                     $this->getDBConnection()->queryDB("Update members set credits=" . $userCredits . " where username='******'");
                 } else {
                     echo "Twitter Account Was NOT Created";
                 }
             }
         }
         $this->updateUserAccounts($accounts);
     }
 }
 protected function load_account($id = null)
 {
     if (!$id) {
         $id = $this->GetData('id');
     }
     $object = TwitterAccount::find_by_id($id);
     if ($object) {
         return $object;
     } else {
         throw new Error404('Unable to find Twitter Account');
     }
 }
Example #7
0
 public static function _processPayment($gateway, $postData)
 {
     // Process according to SagePay
     $paymentTransaction = null;
     if (isset($_POST['VendorTxCode'])) {
         $paymentTransaction = PaymentTransaction::find_by_id($postData['VendorTxCode']);
     }
     if (!$paymentTransaction) {
         throw new PGI_SagePay_ProcessException('Unable to find a payment matching ' . $postData['VendorTxCode']);
     }
     if ($paymentTransaction->status == 'ptsTaken') {
         $params = array('Status' => 'OK', 'StatusDetail' => "Payment for {$paymentTransaction->cart}", 'RedirectURL' => "{$paymentTransaction->baseuri}/payments/{$paymentTransaction->cart->id}/complete");
         $output = '';
         foreach ($params as $key => $value) {
             $output .= "{$key}={$value}\r\n";
         }
         return $output;
     }
     if ($paymentTransaction->status != 'ptsSubmitted') {
         throw new PGI_SagePay_ProcessException("{$paymentTransaction} is in state {$paymentTransaction->status}", $paymentTransaction, $notify);
     }
     // Validate response
     if (!isset($postData['VPSTxId'])) {
         throw new PGI_SagePay_ProcessException('No transaction ID from SagePay');
     }
     if ($paymentTransaction->externalid != $postData['VPSTxId']) {
         throw new PGI_SagePay_ProcessException("{$postData['VPSTxId']} does not match the transaction ID in " . $paymentTransaction, $paymentTransaction);
     }
     $fields = array('VPSTxId', 'VendorTxCode', 'Status', 'TxAuthNo', 'VendorName', 'AVSCV2', 'SecurityKey', 'AddressResult', 'PostCodeResult', 'CV2Result', 'GiftAid', '3DSecureStatus', 'CAVV', 'AddressStatus', 'PayerStatus', 'CardType', 'Last4Digits', 'DeclineCode', 'ExpiryDate', 'FraudResponse', 'BankAuthCode');
     $sig = '';
     foreach ($fields as $name) {
         switch ($name) {
             case 'SecurityKey':
                 $sig .= $paymentTransaction->initialResponse->SecurityKey;
                 break;
             case 'VendorName':
                 $sig .= $gateway->getSetting('vendor');
                 break;
             default:
                 $sig .= $postData[$name];
                 break;
         }
     }
     $sig = strtoupper(md5($sig));
     if ($sig != $postData['VPSSignature']) {
         throw new PGI_SagePay_ProcessException("Signatures do not match, found {$sig}, expecting {$postData['VPSSignature']}", $paymentTransaction);
     }
     $url = "{$paymentTransaction->baseuri}/payments/{$paymentTransaction->id}/failed";
     $paymentTransaction->processResponse = $postData;
     // Determine our correct response
     switch ($postData['Status']) {
         case 'OK':
             $url = "{$paymentTransaction->baseuri}/payments/{$paymentTransaction->cart->id}/complete";
             $cart = Cart::find_by_id($paymentTransaction->cart->id);
             $paymentTransaction->status = 'ptsTaken';
             if ($postData['CardType'] == 'PAYPAL') {
                 $paymentTransaction->method = 'PayPal';
             } else {
                 $cardName = 'Credit Card';
                 $lookup = array('VISA' => 'Visa', 'DELTA' => 'Visa Debit', 'UKE' => 'Visa Electron', 'MC' => 'Mastercard', 'SWITCH' => 'UK Maestro', 'MAESTRO' => 'Maestro', 'AMEX' => 'American Express', 'DINERS' => 'Diners Club', 'JCB' => 'JCB', 'LASER' => 'LASER', 'PAYPAL' => 'PayPal');
                 if (isset($lookup[$postData['CardType']])) {
                     $cardName = $lookup[$postData['CardType']];
                 }
                 $paymentTransaction->method = "{$cardName} (Ending in {$postData['Last4Digits']})";
             }
             $paymentTransaction->save();
             Email::send_user_paymentconfirmation($paymentTransaction);
             // Mark cart as paid, this will trigger the event signup
             // email to the user.
             $cart->mark_paid(null, "SagePay");
             // Email staff about payment
             Email::send_payment_complete($postData, $postData['Status'], $cart);
             // And alert on Twitter
             $account = TwitterAccount::find_by_code('site');
             if ($account) {
                 $signups = $cart->get_signups();
                 $eventsignups = array();
                 foreach ($signups as $signup) {
                     $amount = sprintf("%.2f", $signup->event_ticket->cost / 100);
                     $paidsignups = count($signup->event->participants("paid"));
                     $message = "{$signup->user->nickname} has paid for {$signup->event->name} {$signup->event_ticket->name} [£{$amount}] ({$paidsignups}/{$signup->event->capacity}) [{$signup->id}]";
                     $account->add_tweet($message);
                 }
             }
             break;
         case 'ABORT':
             $paymentTransaction->status = 'ptsCancelled';
             $paymentTransaction->failurereason = $postData['StatusDetail'];
             break;
         default:
             $paymentTransaction->status = 'ptsFailed';
             $paymentTransaction->failurereason = $postData['StatusDetail'];
             break;
     }
     $paymentTransaction->save();
     $params = array('Status' => 'OK', 'StatusDetail' => "Payment for {$paymentTransaction->cart}", 'RedirectURL' => $url);
     $output = '';
     foreach ($params as $key => $value) {
         $output .= "{$key}={$value}\r\n";
     }
     return $output;
 }
 public function show($permalink = null)
 {
     if (isset($_GET['permalink'])) {
         $permalink = $_GET['permalink'];
     }
     $survey = Survey::find_by_permalink($permalink);
     if (!$survey or !$survey->active && Site::CurrentUser()->isAdmin() == 0) {
         Error404();
     }
     if ($survey->event->id) {
         $event_id = mysql_real_escape_string($survey->event_id);
         $user_id = mysql_real_escape_string(Site::CurrentUser()->id);
         $result = EventSignup::find("events.id = '{$event_id}' AND users.id = '{$user_id}' AND event_signups.paid");
         if (!$result) {
             Site::Flash("error", "You must have attended {$survey->event->name} to take this survey");
             RedirectBack();
         }
     }
     $user_id = mysql_real_escape_string(Site::CurrentUser()->id);
     $survey_id = mysql_real_escape_string($survey->id);
     $response = SurveyResponse::find("surveys.id = '{$survey_id}' AND users.id = '{$user_id}'");
     if ($response) {
         Site::Flash("error", "You have already completed this survey");
         Redirect("surveys");
     }
     $response = new SurveyResponse();
     $response->survey = $survey;
     $response->survey_id = $survey->id;
     $response->user = Site::CurrentUser();
     $response->user_id = Site::CurrentUser()->id;
     $answers = array();
     $choices = array();
     $valid = true;
     $errors = array();
     if ($this->post) {
         foreach ($survey->questions() as $question) {
             $answer = new SurveyAnswer();
             $answer->survey_question_id = $question->id;
             if (in_array($question->type, array("sqtTextbox", "sqtTextArea"))) {
                 // Free-text input
                 if (isset($_POST['question'][$question->id])) {
                     $answer->value = $_POST['question'][$question->id];
                 } elseif (!$question->required) {
                     continue;
                 }
             } else {
                 if (isset($_POST['question'][$question->id])) {
                     $chosen = array();
                     if ($question->type == "sqtCheckbox") {
                         // Checkboxes
                         $chosen = $_POST['question'][$question->id];
                     } else {
                         // Radio/Select
                         $chosen = array($_POST['question'][$question->id]);
                     }
                     foreach ($chosen as $id) {
                         $option = SurveyQuestionOption::find_by_id($id);
                         if (!$option or $option->question->id != $question->id) {
                             if (!$question->required) {
                                 continue;
                             }
                             $valid = false;
                             $answer->add_error("Answer for question {$question->position} is invalid");
                             $errors[] = $question->id;
                             break;
                         }
                         $choice = new SurveyAnswerChoice();
                         $choice->survey_question_option_id = $option->id;
                         $choices[$question->id][$option->id] = $choice;
                     }
                 } elseif ($question->required) {
                     $valid = false;
                     $answer->add_error("You must enter an answer for question {$question->position}");
                     $errors[] = $question->id;
                 } else {
                     continue;
                 }
             }
             $result = $answer->validate();
             if (!$result) {
                 $valid = false;
             }
             $answers[$question->id] = $answer;
         }
         if ($valid) {
             // This is valid, let's save everything!
             if ($response->save()) {
                 foreach ($answers as $answer) {
                     $answer->survey_response_id = $response->id;
                     $answer->save();
                     $answers[$answer->survey_question_id] = $answer;
                 }
                 foreach ($choices as $question_id => $answer_choices) {
                     foreach ($answer_choices as $choice) {
                         $choice->survey_answer_id = $answers[$question_id]->id;
                         $choice->save();
                     }
                 }
                 $account = TwitterAccount::find_by_code('site');
                 if ($account) {
                     $message = "{$response->user->nickname} has completed the {$survey->name} Survey";
                     $account->add_tweet($message);
                 }
                 Redirect("surveys/{$survey->permalink}/complete");
             }
             $valid = false;
         }
     }
     $this->assign("answers", $answers);
     $this->assign("choices", $choices);
     $this->assign("valid", $valid);
     $this->assign("survey", $survey);
     $this->assign("response", $response);
     $this->assign("errors", $errors);
     $this->title = $survey->name;
     $this->render("survey/show.tpl");
 }