Module Maintenance + création du module Recette
This commit is contained in:
72
local/modules/PayPlugModule/Controller/Admin/ConfigurationController.php
Executable file
72
local/modules/PayPlugModule/Controller/Admin/ConfigurationController.php
Executable file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace PayPlugModule\Controller\Admin;
|
||||
|
||||
use PayPlugModule\Form\ConfigurationForm;
|
||||
use PayPlugModule\Model\PayPlugConfigValue;
|
||||
use PayPlugModule\Model\PayPlugModuleDeliveryTypeQuery;
|
||||
use PayPlugModule\PayPlugModule;
|
||||
use PayPlugModule\Service\OrderStatusService;
|
||||
use Thelia\Controller\Admin\BaseAdminController;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
class ConfigurationController extends BaseAdminController
|
||||
{
|
||||
public function viewAction()
|
||||
{
|
||||
// Create default order statuses
|
||||
/** @var OrderStatusService $orderStatusesService */
|
||||
$orderStatusesService = $this->container->get('payplugmodule_order_status_service');
|
||||
$orderStatusesService->initAllStatuses();
|
||||
$deliveryModuleFormFields = ConfigurationForm::getDeliveryModuleFormFields();
|
||||
|
||||
return $this->render(
|
||||
"PayPlugModule/configuration",
|
||||
compact('deliveryModuleFormFields')
|
||||
);
|
||||
}
|
||||
|
||||
public function saveAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(array(AdminResources::MODULE), 'PayPlugModule', AccessManager::UPDATE)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$form = $this->createForm('payplugmodule_configuration_form');
|
||||
|
||||
try {
|
||||
$data = $this->validateForm($form)->getData();
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if (in_array($key, PayPlugConfigValue::getConfigKeys())) {
|
||||
PayPlugModule::setConfigValue($key, $value);
|
||||
}
|
||||
|
||||
$explodedKey = explode(':', $key);
|
||||
if ($explodedKey[0] === ConfigurationForm::DELIVERY_MODULE_TYPE_KEY_PREFIX) {
|
||||
$moduleId = $explodedKey[1];
|
||||
$payPlugModuleDeliveryType = PayPlugModuleDeliveryTypeQuery::create()->filterByModuleId($moduleId)->findOneOrCreate();
|
||||
$payPlugModuleDeliveryType->setDeliveryType($value)
|
||||
->save();
|
||||
}
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->setupFormErrorContext(
|
||||
Translator::getInstance()->trans(
|
||||
"Error",
|
||||
[],
|
||||
PayPlugModule::DOMAIN_NAME
|
||||
),
|
||||
$e->getMessage(),
|
||||
$form
|
||||
);
|
||||
return $this->viewAction();
|
||||
}
|
||||
|
||||
return $this->generateSuccessRedirect($form);
|
||||
}
|
||||
|
||||
}
|
||||
84
local/modules/PayPlugModule/Controller/Admin/OrderController.php
Executable file
84
local/modules/PayPlugModule/Controller/Admin/OrderController.php
Executable file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace PayPlugModule\Controller\Admin;
|
||||
|
||||
use PayPlugModule\PayPlugModule;
|
||||
use PayPlugModule\Service\PaymentService;
|
||||
use Thelia\Controller\Admin\BaseAdminController;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Core\Security\Resource\AdminResources;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\OrderQuery;
|
||||
|
||||
class OrderController extends BaseAdminController
|
||||
{
|
||||
public function refundAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(array(AdminResources::MODULE), 'PayPlugModule', AccessManager::UPDATE)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$form = $this->createForm('payplugmodule_order_action_form_refund');
|
||||
|
||||
try {
|
||||
$data = $this->validateForm($form)->getData();
|
||||
$order = OrderQuery::create()
|
||||
->findOneById($data['order_id']);
|
||||
|
||||
$amountToRefund = (int)($data['refund_amount'] * 100);
|
||||
|
||||
/** @var PaymentService $paymentService */
|
||||
$paymentService = $this->container->get('payplugmodule_payment_service');
|
||||
$paymentService->doOrderRefund($order, $amountToRefund);
|
||||
} catch (\Exception $e) {
|
||||
$this->setupFormErrorContext(
|
||||
Translator::getInstance()->trans(
|
||||
"Error",
|
||||
[],
|
||||
PayPlugModule::DOMAIN_NAME
|
||||
),
|
||||
$e->getMessage(),
|
||||
$form
|
||||
);
|
||||
}
|
||||
|
||||
// Sleep to let time for PayPlug to send validation
|
||||
sleep(2);
|
||||
$url = $this->retrieveSuccessUrl($form);
|
||||
return $this->generateRedirect($url.'#orderPayPlug');
|
||||
}
|
||||
|
||||
public function captureAction()
|
||||
{
|
||||
if (null !== $response = $this->checkAuth(array(AdminResources::MODULE), 'PayPlugModule', AccessManager::UPDATE)) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$form = $this->createForm('payplugmodule_order_action_form');
|
||||
|
||||
try {
|
||||
$data = $this->validateForm($form)->getData();
|
||||
$order = OrderQuery::create()
|
||||
->findOneById($data['order_id']);
|
||||
|
||||
/** @var PaymentService $paymentService */
|
||||
$paymentService = $this->container->get('payplugmodule_payment_service');
|
||||
$paymentService->doOrderCapture($order);
|
||||
} catch (\Exception $e) {
|
||||
$this->setupFormErrorContext(
|
||||
Translator::getInstance()->trans(
|
||||
"Error",
|
||||
[],
|
||||
PayPlugModule::DOMAIN_NAME
|
||||
),
|
||||
$e->getMessage(),
|
||||
$form
|
||||
);
|
||||
}
|
||||
|
||||
// Sleep to let time for PayPlug to send validation
|
||||
sleep(2);
|
||||
$url = $this->retrieveSuccessUrl($form);
|
||||
return $this->generateRedirect($url.'#orderPayPlug');
|
||||
}
|
||||
}
|
||||
22
local/modules/PayPlugModule/Controller/CardController.php
Executable file
22
local/modules/PayPlugModule/Controller/CardController.php
Executable file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace PayPlugModule\Controller;
|
||||
|
||||
use PayPlugModule\Model\PayPlugCardQuery;
|
||||
use Thelia\Controller\Front\BaseFrontController;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
|
||||
class CardController extends BaseFrontController
|
||||
{
|
||||
public function deleteCurrentCustomerCard(Request $request)
|
||||
{
|
||||
$customerId = $request->getSession()->getCustomerUser()->getId();
|
||||
|
||||
if (null !== $card = PayPlugCardQuery::create()->findOneByCustomerId($customerId)) {
|
||||
$card->delete();
|
||||
}
|
||||
|
||||
return $this->generateRedirect($this->getSession()->getReturnToUrl());
|
||||
}
|
||||
|
||||
}
|
||||
28
local/modules/PayPlugModule/Controller/NotificationController.php
Executable file
28
local/modules/PayPlugModule/Controller/NotificationController.php
Executable file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace PayPlugModule\Controller;
|
||||
|
||||
use PayPlugModule\Event\Notification\UnknownNotificationEvent;
|
||||
use PayPlugModule\Service\PaymentService;
|
||||
use Thelia\Controller\Front\BaseFrontController;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Response;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
class NotificationController extends BaseFrontController
|
||||
{
|
||||
public function entryPoint(Request $request)
|
||||
{
|
||||
/** @var PaymentService $paymentService */
|
||||
$paymentService = $this->container->get('payplugmodule_payment_service');
|
||||
Tlog::getInstance()->addAlert('Notification received');
|
||||
Tlog::getInstance()->addAlert($request->getContent());
|
||||
|
||||
$notificationResource = $paymentService->getNotificationResource($request);
|
||||
|
||||
$notificationEvent = new UnknownNotificationEvent($notificationResource);
|
||||
$this->dispatch(UnknownNotificationEvent::UNKNOWN_NOTIFICATION_EVENT, $notificationEvent);
|
||||
|
||||
return new Response();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user