/**
  * If current logged in member is not an admin and not trying to log in to the admin
  * or run a /dev/build then display an {@link ErrorPage}.
  * 
  * @see UnderConstruction_Decorator::requireDefaultRecords()
  * @return Void
  */
 public function onBeforeInit()
 {
     $siteConfig = SiteConfig::current_site_config();
     $siteUnderConstruction = $siteConfig->UnderConstruction;
     if ($siteUnderConstruction) {
         //Check to see if running /dev/build
         $runningDevBuild = $this->owner && $this->owner->data() instanceof ErrorPage;
         if (!Permission::check('ADMIN') && strpos($_SERVER['REQUEST_URI'], '/admin') === false && strpos($_SERVER['REQUEST_URI'], '/Security') === false && !Director::isDev() && !$runningDevBuild) {
             Debug::friendlyError(503);
             exit;
         }
     }
 }
예제 #2
0
 /**
  * Send this HTTPReponse to the browser
  */
 function output()
 {
     // Attach appropriate X-Include-JavaScript and X-Include-CSS headers
     if (Director::is_ajax()) {
         Requirements::include_in_response($this);
     }
     if (in_array($this->statusCode, self::$redirect_codes) && headers_sent($file, $line)) {
         $url = $this->headers['Location'];
         echo "<p>Redirecting to <a href=\"{$url}\" title=\"Please click this link if your browser does not redirect you\">{$url}... (output started on {$file}, line {$line})</a></p>\n\t\t\t<meta http-equiv=\"refresh\" content=\"1; url={$url}\" />\n\t\t\t<script type=\"text/javascript\">setTimeout('window.location.href = \"{$url}\"', 50);</script>";
     } else {
         if (!headers_sent()) {
             header($_SERVER['SERVER_PROTOCOL'] . " {$this->statusCode} " . $this->getStatusDescription());
             foreach ($this->headers as $header => $value) {
                 header("{$header}: {$value}");
             }
         }
         if (Director::isLive() && $this->isError()) {
             Debug::friendlyError($this->statusCode, $this->getStatusDescription());
         } else {
             echo $this->body;
         }
     }
 }
예제 #3
0
 static function fatalHandler($errno, $errstr, $errfile, $errline, $errcontext)
 {
     if (self::$send_errors_to) {
         self::emailError(self::$send_errors_to, $errno, $errstr, $errfile, $errline, $errcontext, "Error");
     }
     if (Director::isDev()) {
         Debug::showError($errno, $errstr, $errfile, $errline, $errcontext);
     } else {
         Debug::friendlyError($errno, $errstr, $errfile, $errline, $errcontext);
     }
     die;
 }
 /**
  * Process the order by sending form information to Payment class.
  * 
  * TODO send emails from this function after payment is processed
  * 
  * @see Payment::processPayment()
  * @param Array $data Submitted form data via POST
  * @param Form $form Form data was submitted from
  */
 function ProcessOrder($data, $form)
 {
     //Check payment type
     $paymentClass = !empty($data['PaymentMethod']) ? $data['PaymentMethod'] : null;
     $payment = class_exists($paymentClass) ? new $paymentClass() : null;
     if (!($payment && $payment instanceof Payment)) {
         Debug::friendlyError(403, _t('CheckoutPage.NOT_VALID_METHOD', "Sorry, that is not a valid payment method."), _t('CheckoutPage.TRY_AGAIN', "Please go back and try again."));
         return;
     }
     //Save or create a new customer/member
     //Need to save billing address info to Member for Payment class to work
     $memberData = array('FirstName' => $data['Billing']['FirstName'], 'Surname' => $data['Billing']['Surname'], 'Address' => $data['Billing']['Address'], 'AddressLine2' => $data['Billing']['AddressLine2'], 'City' => $data['Billing']['City'], 'State' => $data['Billing']['State'], 'Country' => $data['Billing']['Country'], 'PostalCode' => $data['Billing']['PostalCode']);
     if (!($member = DataObject::get_one('Member', "\"Email\" = '" . $data['Email'] . "'"))) {
         $member = new Customer();
         $form->saveInto($member);
         $member->FirstName = $data['Billing']['FirstName'];
         $member->Surname = $data['Billing']['Surname'];
         $member->Address = $data['Billing']['Address'];
         $member->AddressLine2 = $data['Billing']['AddressLine2'];
         $member->City = $data['Billing']['City'];
         $member->State = $data['Billing']['State'];
         $member->Country = $data['Billing']['Country'];
         $member->PostalCode = $data['Billing']['PostalCode'];
         $member->Email = $data['Email'];
         $member->write();
         $member->addToGroupByCode('customers');
         $member->logIn();
     } else {
         if (Customer::currentUser() && Customer::currentUser()->Email == $data['Email']) {
             $member->update($data);
             $member->write();
         } else {
             $form->sessionMessage(_t('CheckoutPage.MEMBER_ALREADY_EXISTS', 'Sorry, a member already exists with that email address. If this is your email address, please log in first before placing your order.'), 'bad');
             Director::redirectBack();
             return false;
         }
     }
     //Save the order
     $order = CartControllerExtension::get_current_order();
     $items = $order->Items();
     $form->saveInto($order);
     $order->MemberID = $member->ID;
     $order->Status = Order::STATUS_PENDING;
     $order->OrderedOn = SS_Datetime::now()->getValue();
     $order->write();
     //Save the order items (not sure why can't do this with writeComponents() perhaps because Items() are cached?!)
     foreach ($items as $item) {
         $item->OrderID = $order->ID;
         $item->write();
     }
     //Add addresses to order
     $order->addAddressesAtCheckout($data);
     //Add modifiers to order
     $order->addModifiersAtCheckout($data);
     Session::clear('Cart.OrderID');
     //Save payment data from form and process payment
     $form->saveInto($payment);
     $payment->OrderID = $order->ID;
     $payment->PaidByID = $member->ID;
     $payment->PaidForID = $order->ID;
     $payment->PaidForClass = $order->class;
     $payment->OrderID = $order->ID;
     $payment->Amount->setAmount($order->Total->getAmount());
     $payment->Amount->setCurrency($order->Total->getCurrency());
     $payment->write();
     //Process payment, get the result back
     $result = $payment->processPayment($data, $form);
     //If instant payment success
     if ($result->isSuccess()) {
         $order->sendReceipt();
         $order->sendNotification();
     }
     //If payment is being processed
     //e.g long payment process redirected to another website (PayPal, DPS)
     if ($result->isProcessing()) {
         //Defer sending receipt until payment process has completed
         //@see AccountPage_Controller::order()
         return $result->getValue();
     }
     //If payment failed
     if (!$result->isSuccess() && !$result->isProcessing()) {
         $order->sendReceipt();
         $order->sendNotification();
     }
     //Fallback
     Director::redirect($order->Link());
     return true;
 }
    /**
     * Send this HTTPReponse to the browser
     */
    public function output()
    {
        // Attach appropriate X-Include-JavaScript and X-Include-CSS headers
        if (Director::is_ajax()) {
            Requirements::include_in_response($this);
        }
        if (in_array($this->statusCode, self::$redirect_codes) && headers_sent($file, $line)) {
            $url = Director::absoluteURL($this->headers['Location'], true);
            $urlATT = Convert::raw2htmlatt($url);
            $urlJS = Convert::raw2js($url);
            $title = Director::isDev() ? "{$urlATT}... (output started on {$file}, line {$line})" : "{$urlATT}...";
            echo <<<EOT
<p>Redirecting to <a href="{$urlATT}" title="Click this link if your browser does not redirect you">{$title}</a></p>
<meta http-equiv="refresh" content="1; url={$urlATT}" />
<script type="text/javascript">setTimeout(function(){
\twindow.location.href = "{$urlJS}";
}, 50);</script>";
EOT;
        } else {
            $line = $file = null;
            if (!headers_sent($file, $line)) {
                header($_SERVER['SERVER_PROTOCOL'] . " {$this->statusCode} " . $this->getStatusDescription());
                foreach ($this->headers as $header => $value) {
                    header("{$header}: {$value}", true, $this->statusCode);
                }
            } else {
                // It's critical that these status codes are sent; we need to report a failure if not.
                if ($this->statusCode >= 300) {
                    user_error("Couldn't set response type to {$this->statusCode} because " . "of output on line {$line} of {$file}", E_USER_WARNING);
                }
            }
            // Only show error pages or generic "friendly" errors if the status code signifies
            // an error, and the response doesn't have any body yet that might contain
            // a more specific error description.
            if (Director::isLive() && $this->isError() && !$this->body) {
                Debug::friendlyError($this->statusCode, $this->getStatusDescription());
            } else {
                echo $this->body;
            }
        }
    }
예제 #6
0
 /**
  * Send this HTTPReponse to the browser
  */
 public function output()
 {
     // Attach appropriate X-Include-JavaScript and X-Include-CSS headers
     if (Director::is_ajax()) {
         Requirements::include_in_response($this);
     }
     if (in_array($this->statusCode, self::$redirect_codes) && headers_sent($file, $line)) {
         $url = $this->headers['Location'];
         echo "<p>Redirecting to <a href=\"{$url}\" title=\"Click this link if your browser does not redirect you\">" . "{$url}... (output started on {$file}, line {$line})</a></p>\n\t\t\t<meta http-equiv=\"refresh\" content=\"1; url={$url}\" />\n\t\t\t<script type=\"text/javascript\">setTimeout('window.location.href = \"{$url}\"', 50);</script>";
     } else {
         if (!headers_sent()) {
             header($_SERVER['SERVER_PROTOCOL'] . " {$this->statusCode} " . $this->getStatusDescription());
             foreach ($this->headers as $header => $value) {
                 header("{$header}: {$value}", true, $this->statusCode);
             }
         }
         // Only show error pages or generic "friendly" errors if the status code signifies
         // an error, and the response doesn't have any body yet that might contain
         // a more specific error description.
         if (Director::isLive() && $this->isError() && !$this->body) {
             Debug::friendlyError($this->statusCode, $this->getStatusDescription());
         } else {
             echo $this->body;
         }
     }
 }
예제 #7
0
파일: RepayForm.php 프로젝트: vinstah/body
 public function process($data, $form)
 {
     //Check payment type
     try {
         $paymentMethod = $data['PaymentMethod'];
         $paymentProcessor = PaymentFactory::factory($paymentMethod);
     } catch (Exception $e) {
         Debug::friendlyError(403, _t('CheckoutPage.NOT_VALID_METHOD', "Sorry, that is not a valid payment method."), _t('CheckoutPage.TRY_AGAIN', "Please go back and try again."));
         return;
     }
     $member = Customer::currentUser();
     $orderID = Session::get('Repay.OrderID');
     if ($orderID) {
         $order = DataObject::get_by_id('Order', $orderID);
     }
     Session::clear('Repay.OrderID');
     $order->onBeforePayment();
     try {
         $paymentData = array('Amount' => number_format($order->TotalOutstanding()->getAmount(), 2, '.', ''), 'Currency' => $order->TotalOutstanding()->getCurrency(), 'Reference' => $order->ID);
         $paymentProcessor->payment->OrderID = $order->ID;
         $paymentProcessor->payment->PaidByID = $member->ID;
         $paymentProcessor->setRedirectURL($order->Link());
         $paymentProcessor->capture($paymentData);
     } catch (Exception $e) {
         //This is where we catch gateway validation or gateway unreachable errors
         $result = $paymentProcessor->gateway->getValidationResult();
         $payment = $paymentProcessor->payment;
         //TODO: Need to get errors and save for display on order page
         SS_Log::log(new Exception(print_r($result->message(), true)), SS_Log::NOTICE);
         SS_Log::log(new Exception(print_r($e->getMessage(), true)), SS_Log::NOTICE);
         $this->controller->redirect($order->Link());
     }
 }
예제 #8
0
파일: CartForm.php 프로젝트: vinstah/body
 /**
  * Update the current cart quantities and redirect to checkout.
  * 
  * @param Array $data Data submitted from the form via POST
  * @param Form $form Form that data was submitted from
  */
 public function goToCheckout(array $data, Form $form)
 {
     $this->saveCart($data, $form);
     if ($checkoutPage = DataObject::get_one('CheckoutPage')) {
         $this->controller->redirect($checkoutPage->AbsoluteLink());
     } else {
         Debug::friendlyError(500);
     }
 }
예제 #9
0
 /**
  * Handle a fatal error, depending on the mode of the site (ie: Dev, Test, or Live).
  * 
  * Runtime execution dies immediately once the error is generated.
  *
  * @param unknown_type $errno
  * @param unknown_type $errstr
  * @param unknown_type $errfile
  * @param unknown_type $errline
  * @param unknown_type $errcontext
  */
 static function fatalHandler($errno, $errstr, $errfile, $errline, $errcontext)
 {
     if (self::$send_errors_to) {
         self::emailError(self::$send_errors_to, $errno, $errstr, $errfile, $errline, $errcontext, "Error");
     }
     self::log_error_if_necessary($errno, $errstr, $errfile, $errline, $errcontext, "Error");
     if (Director::isDev() || Director::is_cli()) {
         Debug::showError($errno, $errstr, $errfile, $errline, $errcontext, "Error");
     } else {
         Debug::friendlyError();
     }
     exit(1);
 }
예제 #10
0
파일: OrderForm.php 프로젝트: vinstah/body
 public function process($data, $form)
 {
     $this->extend('onBeforeProcess', $data);
     //Check payment type
     try {
         $paymentMethod = Convert::raw2sql($data['PaymentMethod']);
         $paymentProcessor = PaymentFactory::factory($paymentMethod);
     } catch (Exception $e) {
         Debug::friendlyError(403, _t('CheckoutPage.NOT_VALID_METHOD', "Sorry, that is not a valid payment method."), _t('CheckoutPage.TRY_AGAIN', "Please go back and try again."));
         return;
     }
     //Save or create a new customer/member
     $member = Customer::currentUser() ? Customer::currentUser() : singleton('Customer');
     if (!$member->exists()) {
         $existingCustomer = Customer::get()->filter('Email', $data['Email']);
         if ($existingCustomer && $existingCustomer->exists()) {
             $form->sessionMessage(_t('CheckoutPage.MEMBER_ALREADY_EXISTS', 'Sorry, a member already exists with that email address. If this is your email address, please log in first before placing your order.'), 'bad');
             $this->controller->redirectBack();
             return false;
         }
         $member = Customer::create();
         $form->saveInto($member);
         $member->write();
         $member->addToGroupByCode('customers');
         $member->logIn();
     }
     //Save the order
     $order = Cart::get_current_order();
     $items = $order->Items();
     $form->saveInto($order);
     $order->MemberID = $member->ID;
     $order->Status = Order::STATUS_PENDING;
     $order->OrderedOn = SS_Datetime::now()->getValue();
     $order->write();
     //Saving an update on the order
     if ($notes = $data['Notes']) {
         $update = new Order_Update();
         $update->Note = $notes;
         $update->Visible = true;
         $update->OrderID = $order->ID;
         $update->MemberID = $member->ID;
         $update->write();
     }
     //Add modifiers to order
     $order->updateModifications($data)->write();
     Session::clear('Cart.OrderID');
     $order->onBeforePayment();
     try {
         $shopConfig = ShopConfig::current_shop_config();
         $precision = $shopConfig->BaseCurrencyPrecision;
         $paymentData = array('Amount' => number_format($order->Total()->getAmount(), $precision, '.', ''), 'Currency' => $order->Total()->getCurrency(), 'Reference' => $order->ID);
         $paymentProcessor->payment->OrderID = $order->ID;
         $paymentProcessor->payment->PaidByID = $member->ID;
         $paymentProcessor->setRedirectURL($order->Link());
         $paymentProcessor->capture($paymentData);
     } catch (Exception $e) {
         //This is where we catch gateway validation or gateway unreachable errors
         $result = $paymentProcessor->gateway->getValidationResult();
         $payment = $paymentProcessor->payment;
         //TODO: Need to get errors and save for display on order page
         SS_Log::log(new Exception(print_r($result->message(), true)), SS_Log::NOTICE);
         SS_Log::log(new Exception(print_r($e->getMessage(), true)), SS_Log::NOTICE);
         $this->controller->redirect($order->Link());
     }
 }