public function testExceptions()
 {
     // Ohne Mail
     $exception = new Kwf_Exception();
     $view = $this->_processException($exception);
     $this->assertEquals($view->message, $exception->getMessage());
     $this->assertTrue($view->debug);
     $this->assertEquals($view->template, 'error.tpl');
     // Mit Mail
     Kwf_Exception_Abstract::$logErrors = true;
     $exception = new Kwf_Exception();
     $view = $this->_processException($exception);
     $this->assertEquals($view->message, $exception->getMessage());
     $this->assertFalse($view->debug);
     $this->assertEquals($view->template, 'error.tpl');
     // Nicht-Kwf_Exception mit Mail
     Kwf_Exception_Abstract::$logErrors = true;
     $e = new Zend_Exception();
     $exception = new Kwf_Exception_Other($e);
     $view = $this->_processException($exception);
     $this->assertEquals($view->message, $e->getMessage());
     $this->assertFalse($view->debug);
     $this->assertEquals($view->template, 'error.tpl');
     Kwf_Exception_Abstract::$logErrors = null;
     // Kwf_Exception_NoLog mit Debug
     Kwf_Exception_Abstract::$logErrors = true;
     $exception = new Kwf_Exception_NoLog();
     $view = $this->_processException($exception);
     $this->assertEquals($view->message, $exception->getMessage());
     $this->assertFalse($view->debug);
     Kwf_Exception_Abstract::$logErrors = null;
     $this->assertEquals($view->template, 'error.tpl');
     // Kwf_Exception_NoLog ohne Debug
     $exception = new Kwf_Exception_NoLog();
     $view = $this->_processException($exception);
     $this->assertEquals($view->message, $exception->getMessage());
     $this->assertTrue($view->debug);
     $this->assertEquals($view->template, 'error.tpl');
     // Kwf_Exception_NotFound
     $exception = new Kwf_Exception_NotFound();
     $view = $this->_processException($exception);
     $this->assertEquals($view->message, $exception->getMessage());
     $this->assertEquals($view->template, 'error404.tpl');
     // Nicht-Kwf_Exception
     $exception = new Exception();
     $view = $this->_processException($exception);
     $this->assertEquals($view->message, $exception->getMessage());
     $this->assertEquals($view->template, 'error.tpl');
     // ClientException
     $exception = new Kwf_ClientException();
     $view = $this->_processException($exception);
     $this->assertEquals($view->message, $exception->getMessage());
     $this->assertEquals($view->template, 'error-client.tpl');
 }
 public function preDispatch()
 {
     Kwf_Exception_Abstract::$logErrors = false;
     //don't call parent, no acl required
     if (!file_exists('build/assets')) {
         throw new Kwf_Exception_Client("Installation incomplete: 'build' folder does not exist. You can generate it by calling 'php bootstrap.php build' on commandline. On production servers you should upload locally generated build.");
     }
     if (file_exists('downloader.php')) {
         throw new Kwf_Exception_Client("downloader.php still exists, please delete before starting setup");
     }
     if (file_exists('update')) {
         //for pre 3.3 webs, update file got replaced by kwf_update table
         throw new Kwf_Exception_Client("Application seems to be set up already. (update file exists)");
     }
     if (file_exists('config.local.ini') && filesize('config.local.ini') > 0 && Kwf_Registry::get('config')->setupFinished) {
         if (strpos(file_get_contents('config.local.ini'), "\nsetupFinished = false\n") !== false) {
             throw new Kwf_Exception_Client("Application seems to be set up already. (config.local.ini file exists)");
         }
     }
     $db = null;
     try {
         $db = Kwf_Registry::get('db');
     } catch (Exception $e) {
     }
     if ($db) {
         try {
             $tables = Kwf_Registry::get('db')->fetchCol("SHOW TABLES");
         } catch (Exception $e) {
             throw new Kwf_Exception_Client("Fetching Tables failed: " . $e->getMessage());
         }
         if (in_array('kwf_update', $tables)) {
             throw new Kwf_Exception_Client("Application seems to be set up already. (kwf_update table exists)");
         }
         if ($tables) {
             throw new Kwf_Exception_Client("Database not empty, kwf installation or other application already exists in this database.");
         }
     }
 }
 public static function process($logModel = 'Kwf_Util_Wirecard_LogModel', $secret = null)
 {
     Kwf_Exception_Abstract::$logErrors = true;
     //activate log always, because request comes from wirecard
     ignore_user_abort(true);
     if (!$secret) {
         $secret = Kwf_Registry::get('config')->wirecard->secret;
     }
     $paymentState = isset($_POST["paymentState"]) ? $_POST["paymentState"] : "";
     if (strcmp($paymentState, "CANCEL") == 0) {
         /// the transaction was cancelled.
         $message = "Transaktion wurde abgebrochen.";
     } else {
         if (strcmp($paymentState, "FAILURE") == 0) {
             // there was something wrong with the initiation or an fatal error during the transaction processing occured
             $message = $_POST["message"];
             $e = new Kwf_Exception('Wirecard Transaction Failed: ' . $message);
             $e->log();
             $message = "Fehler bei der Initiierung: " . $message;
         } else {
             if (strcmp($paymentState, "SUCCESS") == 0) {
                 $responseFingerprintOrder = $_POST["responseFingerprintOrder"];
                 $responseFingerprint = $_POST["responseFingerprint"];
                 $str4responseFingerprint = "";
                 $mandatoryFingerPrintFields = 0;
                 $secretUsed = 0;
                 $order = explode(",", $responseFingerprintOrder);
                 for ($i = 0; $i < count($order); $i++) {
                     $key = $order[$i];
                     // check if there are enough fields in den responsefingerprint
                     if (strcmp($key, "paymentState") == 0 && strlen($_POST[$order[$i]]) > 0) {
                         $mandatoryFingerPrintFields++;
                     }
                     if (strcmp($key, "orderNumber") == 0 && strlen($_POST[$order[$i]]) > 0) {
                         $mandatoryFingerPrintFields++;
                     }
                     if (strcmp($key, "paymentType") == 0 && strlen($_POST[$order[$i]]) > 0) {
                         $mandatoryFingerPrintFields++;
                     }
                     if (strcmp($key, "secret") == 0) {
                         $str4responseFingerprint .= $secret;
                         $secretUsed = 1;
                     } else {
                         $str4responseFingerprint .= $_POST[$order[$i]];
                     }
                 }
                 // recalc the fingerprint
                 $responseFingerprintCalc = md5($str4responseFingerprint);
                 if (strcmp($responseFingerprintCalc, $responseFingerprint) == 0 && $mandatoryFingerPrintFields == 3 && $secretUsed == 1) {
                     // everything is ok. store the successfull payment somewhere
                     // please store at least the paymentType and the orderNumber additional to the orderinformation,
                     // otherwise you will never find the transaction again.
                     $m = Kwf_Model_Abstract::getInstance($logModel);
                     $row = $m->createRow();
                     foreach ($order as $i) {
                         if ($i != 'secret') {
                             $row->{$i} = $_POST[$i];
                         }
                     }
                     $row->custom = $_POST['custom'];
                     $row->save();
                     // e.g.  something like
                     // checkBasketIntegrety($amount, $currency, $basketId);
                     // storeAndCloseBasket($paymentType, $orderNumber, $basketId);
                     $message = "Vielen Dank für Ihre Bestellung.";
                 } else {
                     // there is something strange. maybe an unauthorized call of this page or a wrong secret
                     $e = new Kwf_Exception('Wirecard Transaction Failed: Can\'t verify');
                     $e->log();
                 }
             } else {
                 // unauthorized call of this page
                 $e = new Kwf_Exception('Wirecard Transaction Failed: Invalid Payment Status: ' . $paymentState);
                 $e->log();
             }
         }
     }
     echo 'Pfeift';
     exit;
 }