Initial commit

This commit is contained in:
2021-03-23 13:54:38 +01:00
commit 82b142ff95
16941 changed files with 2617212 additions and 0 deletions

View File

@@ -0,0 +1,151 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace CmCIC\Controller;
use CmCIC\CmCIC;
use CmCIC\Model\Config;
use Thelia\Controller\Front\BaseFrontController;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Log\Tlog;
use Thelia\Model\OrderQuery;
use Thelia\Model\OrderStatus;
use Thelia\Model\OrderStatusQuery;
/**
* Class CmcicPayResponse
* @package CmCIC\Controller
* author Thelia <info@thelia.net>
*/
class CmcicPayResponse extends BaseFrontController
{
public function payfail($order_id)
{
$url = $this->getRouteFromRouter(
'router.front',
'order.failed',
[
'order_id' => $order_id,
'message' => $this->getTranslator()->trans("Your payment was rejected", [], CmCIC::DOMAIN_NAME)
]
);
return $this->generateRedirect($url);
}
/**
* @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_LOG_DIR . "log-cmcic.txt");
$log->info("Reception confirmation paiement CB : ". json_encode($request->request->all()));
$order = OrderQuery::create()->findPk($order_id);
/*
* Retrieve HMac for CGI2
*/
$config = Config::read(CmCIC::JSON_CONFIG_PATH);
$vars = $request->request->all();
unset($vars['MAC']);
$hashable = CmCIC::getHashable($vars);
$computed_mac = CmCIC::computeHmac(
$hashable,
CmCIC::getUsableKey($config["CMCIC_KEY"])
);
$response=CmCIC::CMCIC_CGI2_MACNOTOK.$hashable;
$request_mac = strtolower($request->get('MAC'));
if ($computed_mac == $request_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 $code");
throw new \Exception(
$this->getTranslator()->trans("An error occured, no valid code-retour $code", [], CmCIC::DOMAIN_NAME)
);
}
if (!empty($msg)) {
$log->info($msg);
}
$response= CmCIC::CMCIC_CGI2_MACOK;
} else {
$log->error("MAC could not be validated. Received : $request_mac, computed : $computed_mac");
}
/*
* 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"
)
);
}
}

View File

@@ -0,0 +1,142 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace CmCIC\Controller;
use CmCIC\CmCIC;
use CmCIC\Form\ConfigureCmCIC;
use CmCIC\Model\Config;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\HttpFoundation\Response;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Tools\URL;
class CmcicSaveConfig extends BaseAdminController
{
const CIC_SERVER = "https://ssl.paiement.cic-banques.fr/";
const CM_SERVER = "https://paiement.creditmutuel.fr/";
const OBC_SERVER = "https://ssl.paiement.banque-obc.fr/";
const MONETICO_SERVER = "https://p.monetico-services.com/";
const CMCIC_VERSION = "3.0";
const CMCIC_URLOK = "/order/placed/";
const CMCIC_URLKO = "/module/cmcic/payfail/";
const CMCIC_URLRECEIVE = "/module/cmcic/receive/";
public function downloadLog()
{
if (null !== $response = $this->checkAuth(AdminResources::MODULE, 'CmCIC', AccessManager::UPDATE)) {
return $response;
}
$data = @file_get_contents(THELIA_LOG_DIR . "log-cmcic.txt");
if (empty($data)) {
$data = $this->getTranslator()->trans("The CmCIC server log is currently empty.", [], CmCIC::DOMAIN_NAME);
}
return Response::create(
$data,
200,
array(
'Content-type' => "text/plain",
'Content-Disposition' => sprintf('Attachment;filename=log-cmcic.txt')
)
);
}
public function save()
{
if (null !== $response = $this->checkAuth(AdminResources::MODULE, '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());
CmCIC::setConfigValue('allowed_ips', $vform->get('allowed_ips')->getData());
CmCIC::setConfigValue('send_confirmation_message_only_if_paid', $vform->get('send_confirmation_message_only_if_paid')->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|mon$#", $vform->get('server')->getData())
) {
$serv = $vform->get('server')->getData();
switch($serv) {
case 'mon':
$serv = self::MONETICO_SERVER;
break;
case 'cic':
$serv = self::CIC_SERVER;
break;
case 'cm':
$serv = self::CM_SERVER;
break;
case 'obc':
$serv = self::OBC_SERVER;
break;
default:
throw new \InvalidArgumentException("Unknown server type '$serv'");
}
if ($vform->get('debug')->getData() === true) {
$serv .= '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($this->getTranslator()->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
);
}
return $this->generateRedirect(URL::getInstance()->absoluteUrl("/admin/module/CmCIC"));
}
}