Exemple #1
0
 public function save()
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('CmCIC'), AccessManager::UPDATE))) {
         return $response;
     }
     $error_message = "";
     $conf = new Config();
     $form = new ConfigureCmCIC($this->getRequest());
     try {
         $vform = $this->validateForm($form);
         CmCIC::setConfigValue('debug', $vform->get('debug')->getData() === true ? 1 : 0);
         CmCIC::setConfigValue('allowed_ips', $vform->get('allowed_ips')->getData());
         // After post checks (PREG_MATCH) & create json file
         if (preg_match("#^\\d{7}\$#", $vform->get('TPE')->getData()) && preg_match("#^[a-z\\d]{40}\$#i", $vform->get('com_key')->getData()) && preg_match("#^[a-z\\d]+\$#i", $vform->get('com_soc')->getData()) && preg_match("#^cic|cm|obc\$#", $vform->get('server')->getData())) {
             $serv = $vform->get('server')->getData();
             $serv = ($serv === "cic" ? self::CIC_SERVER : ($serv === "cm" ? self::CM_SERVER : ($serv === "obc" ? self::OBC_SERVER : ""))) . ($vform->get('debug')->getData() === true ? "test/" : "");
             $conf->setCMCICKEY($vform->get('com_key')->getData())->setCMCICVERSION(self::CMCIC_VERSION)->setCMCICCODESOCIETE($vform->get('com_soc')->getData())->setCMCICPAGE($vform->get('page')->getData())->setCMCICTPE($vform->get('TPE')->getData())->setCMCICSERVER($serv)->write(CmCIC::JSON_CONFIG_PATH);
         } else {
             throw new \Exception(Translator::getInstance()->trans("Error in form syntax, please check that your values are correct."));
         }
     } catch (\Exception $e) {
         $error_message = $e->getMessage();
     }
     $this->setupFormErrorContext('erreur sauvegarde configuration', $error_message, $form);
     $this->redirectToRoute("admin.module.configure", array(), array('module_code' => "CmCIC", '_controller' => 'Thelia\\Controller\\Admin\\ModuleController::configureAction'));
 }
Exemple #2
0
 /**
  * @throws \Exception
  */
 public function receiveResponse()
 {
     $request = $this->getRequest();
     $order_id = $request->get('reference');
     if (is_numeric($order_id)) {
         $order_id = (int) $order_id;
     }
     /*
      * Configure log output
      */
     $log = Tlog::getInstance();
     $log->setDestinations("\\Thelia\\Log\\Destination\\TlogDestinationFile");
     $log->setConfig("\\Thelia\\Log\\Destination\\TlogDestinationFile", 0, THELIA_ROOT . "log" . DS . "log-cmcic.txt");
     $log->info("accessed");
     $order = OrderQuery::create()->findPk($order_id);
     /*
      * Retrieve HMac for CGI2
      */
     $config = Config::read(CmCIC::JSON_CONFIG_PATH);
     $hashable = sprintf(CmCIC::CMCIC_CGI2_FIELDS, $config['CMCIC_TPE'], $request->get('date'), $request->get('montant'), $request->get('reference'), $request->get('texte-libre'), $config['CMCIC_VERSION'], $request->get('code-retour'), $request->get('cvx'), $request->get('vld'), $request->get('brand'), $request->get('status3ds'), $request->get('numauto'), $request->get('motifrefus'), $request->get('originecb'), $request->get('bincb'), $request->get('hpancb'), $request->get('ipclient'), $request->get('originetr'), $request->get('veres'), $request->get('pares'));
     $mac = CmCIC::computeHmac($hashable, CmCIC::getUsableKey($config["CMCIC_KEY"]));
     $response = CmCIC::CMCIC_CGI2_MACNOTOK . $hashable;
     if ($mac === strtolower($request->get('MAC'))) {
         $code = $request->get("code-retour");
         $msg = null;
         $status = OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_PAID);
         $event = new OrderEvent($order);
         $event->setStatus($status->getId());
         switch ($code) {
             case "payetest":
                 $msg = "The test payment of the order " . $order->getRef() . " has been successfully released. ";
                 $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
                 break;
             case "paiement":
                 $msg = "The payment of the order " . $order->getRef() . " has been successfully released. ";
                 $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
                 break;
             case "Annulation":
                 $msg = "Error during the paiement: " . $this->getRequest()->get("motifrefus");
                 break;
             default:
                 $log->error("Error while receiving response from CMCIC: code-retour not valid");
                 throw new \Exception(Translator::getInstance()->trans("An error occured, no valid code-retour"));
         }
         if (!empty($msg)) {
             $log->info($msg);
         }
         $response = CmCIC::CMCIC_CGI2_MACOK;
     }
     /*
      * Get log back to previous state
      */
     $log->setDestinations("\\Thelia\\Log\\Destination\\TlogDestinationRotatingFile");
     return Response::create(sprintf(CmCIC::CMCIC_CGI2_RECEIPT, $response), 200, array("Content-type" => "text/plain", "Pragma" => "nocache"));
 }
Exemple #3
0
 /**
  * @return mixed
  */
 public function pay(Order $order)
 {
     $c = Config::read(CmCIC::JSON_CONFIG_PATH);
     $currency = $order->getCurrency()->getCode();
     $opts = "";
     $cmCicRouter = $this->container->get('router.cmcic');
     $mainRouter = $this->container->get('router.front');
     $vars = array("url_bank" => sprintf(self::CMCIC_URLPAIEMENT, $c["CMCIC_SERVER"], $c["CMCIC_PAGE"]), "version" => $c["CMCIC_VERSION"], "TPE" => $c["CMCIC_TPE"], "date" => date("d/m/Y:H:i:s"), "montant" => (string) round($order->getTotalAmount(), 2) . $currency, "reference" => self::harmonise($order->getId(), 'numeric', 12), "url_retour" => URL::getInstance()->absoluteUrl($cmCicRouter->generate("cmcic.receive", array(), Router::ABSOLUTE_URL)) . "/" . (string) $order->getId(), "url_retour_ok" => URL::getInstance()->absoluteUrl($mainRouter->generate("order.placed", array("order_id" => (string) $order->getId()), Router::ABSOLUTE_URL)), "url_retour_err" => URL::getInstance()->absoluteUrl($cmCicRouter->generate("cmcic.payfail", array("order_id" => (string) $order->getId()), Router::ABSOLUTE_URL)), "lgue" => strtoupper($this->getRequest()->getSession()->getLang()->getCode()), "societe" => $c["CMCIC_CODESOCIETE"], "texte-libre" => "0", "mail" => $this->getRequest()->getSession()->getCustomerUser()->getEmail(), "nbrech" => "", "dateech1" => "", "montantech1" => "", "dateech2" => "", "montantech2" => "", "dateech3" => "", "montantech3" => "", "dateech4" => "", "montantech4" => "");
     $hashable = sprintf(self::CMCIC_CGI1_FIELDS, $vars["TPE"], $vars["date"], $vars["montant"], $vars["reference"], $vars["texte-libre"], $vars["version"], $vars["lgue"], $vars["societe"], $vars["mail"], $vars["nbrech"], $vars["dateech1"], $vars["montantech1"], $vars["dateech2"], $vars["montantech2"], $vars["dateech3"], $vars["montantech3"], $vars["dateech4"], $vars["montantech4"], $opts);
     $mac = self::computeHmac($hashable, self::getUsableKey($c["CMCIC_KEY"]));
     $vars["MAC"] = $mac;
     $parser = $this->container->get("thelia.parser");
     $parser->setTemplateDefinition(new TemplateDefinition('module_cmcic', TemplateDefinition::FRONT_OFFICE));
     $render = $parser->render("gotobankservice.html", $vars);
     return Response::create($render);
 }