From eea4ca73c4718f1a242e0fc984da25274035337d Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 24 Dec 2021 11:59:50 +0100 Subject: [PATCH] wait #4994 @0.5 --- .idea/deployment.xml | 5 +- .../controllers/PaymentController.php | 192 +++++++++--------- 2 files changed, 104 insertions(+), 93 deletions(-) diff --git a/.idea/deployment.xml b/.idea/deployment.xml index 60dbce0..9992c45 100644 --- a/.idea/deployment.xml +++ b/.idea/deployment.xml @@ -1,6 +1,6 @@ - + @@ -194,7 +194,7 @@ - + @@ -353,5 +353,6 @@ + \ No newline at end of file diff --git a/framework/application/controllers/PaymentController.php b/framework/application/controllers/PaymentController.php index b104b7d..ebf0b4c 100644 --- a/framework/application/controllers/PaymentController.php +++ b/framework/application/controllers/PaymentController.php @@ -1,95 +1,105 @@ _sendFakeResponse(true); - $this->redirect($this->getNavigation()->findOneByName('commander/confirmation')->getHref()); - } - - protected function _getPaymentManager() { - $o = $this->_getPaymentOptions(); - if ($o['system'] == 'cmcic') { - return new CubeIT_Payment_CMCIC(); - } else if ($o['system'] == 'postfinance') { - return new CubeIT_Payment_Postfinance(); - } - } - - protected function _getPaymentOptions() { - $p = $this->getOption('payment'); - $res = $this->getOption($p); - $res['system'] = $p; - return $res; - } - - protected function _sendFakeResponse($ok) { - $o = $this->_getPaymentOptions(); - if (!$o['test']) { - return; - } - $session = $this->getSession(); - $datas = array('reference' => $session->commande, 'summary' => 'test response'); - if ($ok) { - $this->accepted($datas); - } else { - $this->refused($datas); - } - } - - public function nokAction() { - $this->_sendFakeResponse(true); - $this->redirect($this->getNavigation()->findOneByName('commander/confirmation')->getHref()); - } - - public function autoAction() { - $this->disableLayout(); - $this->getResponse()->setHeader('Content-type', 'text/plain'); - - $manager = $this->_getPaymentManager(); - echo $manager->receipt(array($this, 'accepted'), array($this, 'refused')); - } - - public function accepted($datas) { - // Get next facture number - $db = $this->getDb(); - $f = $db->select()->from('commande', array('facture' => 'MAX(facture)+1'))->query()->fetch(); - - $commande = $this->_updateCommande($datas, array('status' => 1, 'facture' => $f->facture)); - - for ($i = 1; $i <= $commande->getQuantite(); $i++) { - // Création du médaillon - $medaillon = new Adangelis_Model_Medaillon(); - $medaillon->setCommande($commande->getId()); - $medaillon->save(); - - // Création du mémorial - $memorial = new Adangelis_Model_Memorial(); - $memorial->setMedaillon($medaillon->getId()); - $memorial->save(); - } - $mailing = new Adangelis_Mailing($this->view); - $mailing->confirmationCommande($commande->getId()); - } - - public function refused($datas) { - $this->_updateCommande($datas, array('status' => 3)); - } - - /** - * - * @param array $datas - * @param array $bind - * @return Adangelis_Model_Commande - */ - protected function _updateCommande($datas, $bind) { - $bind = array_merge($bind, array('infospaiement' => $datas['summary'], 'date_paiement' => Zend_Date::now())); - $commande = new Adangelis_Model_Commande(); - $commande->selectById($datas['reference']); - $commande->inject($bind); - $commande->save(); - - return $commande; - } +class PaymentController extends CubeIT_Controller_PageController +{ + + public function okAction() + { + //$this->_sendFakeResponse(true); + $this->redirect($this->getNavigation()->findOneByName('commander/confirmation')->getHref()); + } + + protected function _getPaymentManager() + { + $o = $this->_getPaymentOptions(); + if ($o['system'] == 'cmcic') { + return new CubeIT_Payment_CMCIC(); + } else if ($o['system'] == 'postfinance') { + return new CubeIT_Payment_Postfinance(); + } + } + + protected function _getPaymentOptions() + { + $p = $this->getOption('payment'); + $res = $this->getOption($p); + $res['system'] = $p; + return $res; + } + + protected function _sendFakeResponse($ok) + { + $o = $this->_getPaymentOptions(); + if (!$o['test']) { + return; + } + $session = $this->getSession(); + $datas = array('reference' => $session->commande, 'summary' => 'test response'); + if ($ok) { + $this->accepted($datas); + } else { + $this->refused($datas); + } + } + + public function nokAction() + { + $this->_sendFakeResponse(true); + $this->redirect($this->getNavigation()->findOneByName('commander/confirmation')->getHref()); + } + + public function autoAction() + { + $this->disableLayout(); + $this->getResponse()->setHeader('Content-type', 'text/plain'); + + $manager = $this->_getPaymentManager(); + echo $manager->receipt(array($this, 'accepted'), array($this, 'refused')); + } + + public function accepted($datas) + { + // Get next facture number + $db = $this->getDb(); + $f = $db->select()->from('commande', [new Zend_Db_Expr('MAX(facture)+1 AS facture')])->query()->fetch(); + + $commande = $this->_updateCommande($datas, array('status' => 1, 'facture' => $f->facture)); + + for ($i = 1; $i <= $commande->getQuantite(); $i++) { + // Création du médaillon + $medaillon = new Adangelis_Model_Medaillon(); + $medaillon->setCommande($commande->getId()); + $medaillon->save(); + + // Création du mémorial + $memorial = new Adangelis_Model_Memorial(); + $memorial->setMedaillon($medaillon->getId()); + $memorial->save(); + } + $mailing = new Adangelis_Mailing($this->view); + $mailing->confirmationCommande($commande->getId()); + } + + public function refused($datas) + { + $this->_updateCommande($datas, array('status' => 3)); + } + + /** + * + * @param array $datas + * @param array $bind + * @return Adangelis_Model_Commande + */ + protected function _updateCommande($datas, $bind) + { + $bind = array_merge($bind, array('infospaiement' => $datas['summary'], 'date_paiement' => Zend_Date::now())); + $commande = new Adangelis_Model_Commande(); + $commande->selectById($datas['reference']); + $commande->inject($bind); + $commande->save(); + + return $commande; + } } -- 2.39.5