Ejemplo n.º 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'));
 }
Ejemplo n.º 2
0
 protected function buildForm()
 {
     $values = null;
     $path = __DIR__ . "/../" . CmCIC::JSON_CONFIG_PATH;
     if (is_readable($path)) {
         $values = json_decode(file_get_contents($path), true);
     }
     $this->formBuilder->add('com_key', 'text', array('label' => Translator::getInstance()->trans('Merchant key', [], CmCIC::DOMAIN_NAME), 'label_attr' => array('for' => 'com_key'), 'data' => null === $values ? '' : $values["CMCIC_KEY"], 'constraints' => array(new NotBlank())))->add('TPE', 'text', array('label' => Translator::getInstance()->trans('TPE', [], CmCIC::DOMAIN_NAME), 'label_attr' => array('for' => 'TPE'), 'data' => null === $values ? '' : $values["CMCIC_TPE"], 'constraints' => array(new NotBlank())))->add('com_soc', 'text', array('label' => Translator::getInstance()->trans('Society code', [], CmCIC::DOMAIN_NAME), 'label_attr' => array('for' => 'com_soc'), 'data' => null === $values ? '' : $values["CMCIC_CODESOCIETE"], 'constraints' => array(new NotBlank())))->add('server', 'choice', array('label' => Translator::getInstance()->trans('server', [], CmCIC::DOMAIN_NAME), 'choices' => array("cic" => "CIC", "cm" => "Crédit Mutuel", "obc" => "OBC"), 'required' => 'true', 'expanded' => true, 'multiple' => false, 'data' => null === $values ? '' : (preg_match("#cic-banques#i", $values["CMCIC_SERVER"]) ? "cic" : (preg_match("#creditmutuel#i", $values["CMCIC_SERVER"]) ? "cm" : (preg_match("#banque-obc#i", $values["CMCIC_SERVER"]) ? "obc" : "")))))->add('page', 'text', array('label' => Translator::getInstance()->trans('page', [], CmCIC::DOMAIN_NAME), 'label_attr' => array('for' => 'page'), 'data' => null === $values ? '' : $values["CMCIC_PAGE"], 'constraints' => array(new NotBlank())))->add('debug', 'checkbox', array('label' => "Debug", 'label_attr' => array('for' => 'debug'), 'value' => null !== $values && preg_match("#test#i", $values["CMCIC_SERVER"]) ? "true" : ""))->add('allowed_ips', 'textarea', array('required' => false, 'label' => Translator::getInstance()->trans('Allowed IPs in test mode', [], CmCIC::DOMAIN_NAME), 'data' => CmCIC::getConfigValue('allowed_ips', ''), 'label_attr' => array('for' => 'allowed_ips', 'help' => Translator::getInstance()->trans('List of IP addresses allowed to use this payment on the front-office when in test mode (your current IP is %ip). One address per line', array('%ip' => $this->getRequest()->getClientIp()), CmCIC::DOMAIN_NAME), 'rows' => 3)));
 }
Ejemplo n.º 3
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"));
 }