<?php
-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', 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;
+ }
}