Il manquait quelques fichiers dans Git

This commit is contained in:
2024-01-18 12:02:32 +01:00
parent 485580e0b2
commit 15053f58f2
194 changed files with 63120 additions and 9403 deletions

View File

@@ -0,0 +1,80 @@
<?php
namespace Axepta\Controller;
use Axepta\Axepta;
use Thelia\Controller\Admin\BaseAdminController;
use Thelia\Core\Security\AccessManager;
use Thelia\Core\Security\Resource\AdminResources;
use Thelia\Form\Exception\FormValidationException;
use Thelia\Tools\URL;
class ConfigurationController extends BaseAdminController
{
public function configure()
{
if (null !== $response = $this->checkAuth(AdminResources::MODULE, 'Axepta', AccessManager::UPDATE)) {
return $response;
}
// Create the Form from the request
$configurationForm = $this->createForm('axepta_configuration');
try {
// Check the form against constraints violations
$form = $this->validateForm($configurationForm, "POST");
// Get the form field values
$data = $form->getData();
foreach ($data as $name => $value) {
if (is_array($value)) {
$value = implode(';', $value);
}
Axepta::setConfigValue($name, $value);
}
// Log configuration modification
$this->adminLogAppend(
"axepta.configuration.message",
AccessManager::UPDATE,
"Axepta configuration updated"
);
// Redirect to the success URL,
if ($this->getRequest()->get('save_mode') === 'stay') {
// If we have to stay on the same page, redisplay the configuration page/
$route = '/admin/module/Axepta';
} else {
// If we have to close the page, go back to the module back-office page.
$route = '/admin/modules';
}
return $this->generateRedirect(URL::getInstance()->absoluteUrl($route));
// An exit is performed after redirect.+
} catch (FormValidationException $ex) {
// Form cannot be validated. Create the error message using
// the BaseAdminController helper method.
$error_msg = $this->createStandardFormValidationErrorMessage($ex);
} catch (\Exception $ex) {
// Any other error
$error_msg = $ex->getMessage();
}
// At this point, the form has errors, and should be redisplayed. We do not redirect,
// just redisplay the same template.
// Set up the Form error context, to make error information available in the template.
$this->setupFormErrorContext(
$this->getTranslator()->trans("Axepta configuration", [], Axepta::DOMAIN_NAME),
$error_msg,
$configurationForm,
$ex
);
// Do not redirect at this point, or the error context will be lost.
// Just redisplay the current template.
return $this->render('module-configure', array('module_code' => 'Payline'));
}
}

View File

@@ -0,0 +1,68 @@
<?php
namespace Axepta\Controller;
use Axepta\Axepta;
use Axepta\Util\Axepta as AxeptaPayment;
use Thelia\Core\Event\Order\OrderEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Translation\Translator;
use Thelia\Exception\TheliaProcessException;
use Thelia\Model\Base\OrderQuery;
use Thelia\Model\OrderStatusQuery;
use Thelia\Module\BasePaymentModuleController;
class NotificationController extends BasePaymentModuleController
{
protected function getModuleCode()
{
return 'Axepta';
}
/**
* @throws \Propel\Runtime\Exception\PropelException
*/
public function notificationAction()
{
$this->getLog()->addInfo("Processing Axcepta notification");
$paymentResponse = new AxeptaPayment(Axepta::getConfigValue(Axepta::HMAC));
$paymentResponse->setCryptKey(Axepta::getConfigValue(Axepta::CRYPT_KEY));
$paymentResponse->setResponse($this->getRequest()->query->all());
$this->getLog()->addError("Notification parameters: ".print_r($paymentResponse->parameters, 1));
$transId = $paymentResponse->getTransID();
if (null === $order = OrderQuery::create()->filterByTransactionRef($transId)->findOne()) {
$this->getLog()->addInfo("Failed to fin order for transaction ID $transId. Aborting.");
throw new TheliaProcessException(
Translator::getInstance()->trans("Failed to find order for transaction ID %id", ['id' => $transId ], Axepta::DOMAIN_NAME)
);
}
$this->getLog()->addInfo("Processing payment of order " . $order->getRef());
$event = new OrderEvent($order);
if ($paymentResponse->isValid() && $paymentResponse->isSuccessful()) {
$this->getLog()->addInfo("Payment of order ".$order->getRef()." is successful.");
if (!$order->isPaid()) {
$this->getLog()->addInfo("Setting order status to 'paid'.");
$event->setStatus(OrderStatusQuery::getPaidStatus()->getId());
$this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
}
$this->redirectToSuccessPage($order->getId());
}
$this->getLog()->addInfo("Payment failed, cancelling order " . $order->getRef());
$event->setStatus(OrderStatusQuery::getCancelledStatus()->getId());
$this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
$this->getLog()->addInfo("Failure cause:".$paymentResponse->getDescription() . ' ('.$paymentResponse->getCode());
$this->redirectToFailurePage($order->getId(), $paymentResponse->getDescription() . ' ('.$paymentResponse->getCode().')');
}
}