Skip to content

Commit 26a5fc0

Browse files
committed
Changes for Thelia 2.5 compatibility
1 parent 27a952e commit 26a5fc0

16 files changed

Lines changed: 80 additions & 101 deletions

Command/TreatOrderMultiPaymentCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
4040
->setPaymentMethod($todayPlannedOrderPayment->getPaymentMethod())
4141
->setInitiator("MERCHANT");
4242

43-
$dispatcher->dispatch(PayPlugPaymentEvent::CREATE_PAYMENT_EVENT, $paymentEvent);
43+
$dispatcher->dispatch($paymentEvent, PayPlugPaymentEvent::CREATE_PAYMENT_EVENT);
4444

4545
$todayPlannedOrderPayment->setPaymentId($paymentEvent->getPaymentId())
4646
->save();

Config/config.xml

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,7 @@
2121
</commands>
2222

2323
<services>
24-
<service id="payplugmodule_payment_service" class="PayPlugModule\Service\PaymentService">
25-
<argument type="service" id="event_dispatcher"/>
26-
</service>
27-
<service id="payplugmodule_order_status_service" class="PayPlugModule\Service\OrderStatusService">
28-
<argument type="service" id="event_dispatcher"/>
29-
</service>
30-
<service id="payplugmodule_notification_listener" class="PayPlugModule\EventListener\NotificationListener">
31-
<argument type="service" id="event_dispatcher"/>
32-
<argument type="service" id="payplugmodule_order_status_service"/>
33-
<tag name="kernel.event_subscriber"/>
34-
</service>
35-
<service id="payplugmodule_payment_listener" class="PayPlugModule\EventListener\PaymentListener">
36-
<argument type="service" id="event_dispatcher"/>
37-
<argument type="service" id="payplugmodule_order_status_service"/>
38-
<tag name="kernel.event_subscriber"/>
39-
</service>
40-
<service id="payplugmodule_order_listener" class="PayPlugModule\EventListener\OrderListener">
41-
<argument type="service" id="payplugmodule_payment_service"/>
42-
<tag name="kernel.event_subscriber"/>
43-
</service>
44-
<service id="payplugmodule_form_extend_order_listener" class="PayPlugModule\EventListener\FormExtend\OrderFormListener">
45-
<argument type="service" id="request_stack"/>
46-
<tag name="kernel.event_subscriber"/>
47-
</service>
48-
<service id="payplugmodule_conformation_emil_listener" class="PayPlugModule\EventListener\ConfirmationEmailListener">
49-
<argument type="service" id="mailer"/>
50-
<tag name="kernel.event_subscriber"/>
24+
<service id="payplugmodule_payment_service" alias="PayPlugModule\Service\PaymentService" public="true">
5125
</service>
5226
</services>
5327

@@ -57,7 +31,7 @@
5731
<tag name="hook.event_listener" event="order.edit-js " type="back" templates="js:PayPlugModule/order_pay_plug.js"/>
5832
</hook>
5933
<hook id="payplugmodule_front_hook" class="PayPlugModule\Hook\FrontHookManager">
60-
<argument type="service" id="thelia.taxengine"/>
34+
<argument type="service" id="thelia.taxEngine"/>
6135
<tag name="hook.event_listener" event="order-invoice.after-javascript-include" type="front" method="onOrderInvoiceAfterJsInclude"/>
6236
<tag name="hook.event_listener" event="order-invoice.payment-extra" type="front" method="onOrderInvoicePaymentExtra"/>
6337
</hook>

Config/module.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
<language>en_US</language>
1818
<language>fr_FR</language>
1919
</languages>
20-
<version>1.0.7</version>
20+
<version>2.0.0</version>
2121
<authors>
2222
<author>
2323
<name>Vincent Lopes-Vicente</name>
2424
<email>vlopes@openstudio.fr</email>
2525
</author>
2626
</authors>
2727
<type>payment</type>
28-
<thelia>2.4.0</thelia>
28+
<thelia>2.5.0</thelia>
2929
<stability>other</stability>
3030
<mandatory>0</mandatory>
3131
<hidden>0</hidden>

Config/schema.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<database defaultIdMethod="native" name="thelia"
2+
<database defaultIdMethod="native" name="TheliaMain"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
55

Controller/Admin/ConfigurationController.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@
1414

1515
class ConfigurationController extends BaseAdminController
1616
{
17-
public function viewAction()
17+
public function viewAction(OrderStatusService $orderStatusesService)
1818
{
19-
// Create default order statuses
20-
/** @var OrderStatusService $orderStatusesService */
21-
$orderStatusesService = $this->container->get('payplugmodule_order_status_service');
2219
$orderStatusesService->initAllStatuses();
2320
$deliveryModuleFormFields = ConfigurationForm::getDeliveryModuleFormFields();
2421

@@ -34,7 +31,7 @@ public function saveAction()
3431
return $response;
3532
}
3633

37-
$form = $this->createForm('payplugmodule_configuration_form');
34+
$form = $this->createForm(ConfigurationForm::getName());
3835

3936
try {
4037
$data = $this->validateForm($form)->getData();

Controller/Admin/OrderController.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace PayPlugModule\Controller\Admin;
44

5+
use PayPlugModule\Form\OrderActionForm;
6+
use PayPlugModule\Form\OrderRefundForm;
57
use PayPlugModule\PayPlugModule;
68
use PayPlugModule\Service\PaymentService;
79
use Thelia\Controller\Admin\BaseAdminController;
@@ -12,13 +14,13 @@
1214

1315
class OrderController extends BaseAdminController
1416
{
15-
public function refundAction()
17+
public function refundAction(PaymentService $paymentService)
1618
{
1719
if (null !== $response = $this->checkAuth(array(AdminResources::MODULE), 'PayPlugModule', AccessManager::UPDATE)) {
1820
return $response;
1921
}
2022

21-
$form = $this->createForm('payplugmodule_order_action_form_refund');
23+
$form = $this->createForm(OrderRefundForm::getName());
2224

2325
try {
2426
$data = $this->validateForm($form)->getData();
@@ -27,8 +29,6 @@ public function refundAction()
2729

2830
$amountToRefund = (int)($data['refund_amount'] * 100);
2931

30-
/** @var PaymentService $paymentService */
31-
$paymentService = $this->container->get('payplugmodule_payment_service');
3232
$paymentService->doOrderRefund($order, $amountToRefund);
3333
} catch (\Exception $e) {
3434
$this->setupFormErrorContext(
@@ -48,21 +48,19 @@ public function refundAction()
4848
return $this->generateRedirect($url.'#orderPayPlug');
4949
}
5050

51-
public function captureAction()
51+
public function captureAction(PaymentService $paymentService)
5252
{
5353
if (null !== $response = $this->checkAuth(array(AdminResources::MODULE), 'PayPlugModule', AccessManager::UPDATE)) {
5454
return $response;
5555
}
5656

57-
$form = $this->createForm('payplugmodule_order_action_form');
57+
$form = $this->createForm(OrderActionForm::getName());
5858

5959
try {
6060
$data = $this->validateForm($form)->getData();
6161
$order = OrderQuery::create()
6262
->findOneById($data['order_id']);
6363

64-
/** @var PaymentService $paymentService */
65-
$paymentService = $this->container->get('payplugmodule_payment_service');
6664
$paymentService->doOrderCapture($order);
6765
} catch (\Exception $e) {
6866
$this->setupFormErrorContext(

Controller/NotificationController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44

55
use PayPlugModule\Event\Notification\UnknownNotificationEvent;
66
use PayPlugModule\Service\PaymentService;
7+
use Symfony\Component\EventDispatcher\EventDispatcher;
8+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
79
use Thelia\Controller\Front\BaseFrontController;
810
use Thelia\Core\HttpFoundation\Request;
911
use Thelia\Core\HttpFoundation\Response;
1012
use Thelia\Log\Tlog;
1113

1214
class NotificationController extends BaseFrontController
1315
{
14-
public function entryPoint(Request $request)
16+
public function entryPoint(Request $request, EventDispatcherInterface $eventDispatcher, PaymentService $paymentService)
1517
{
16-
/** @var PaymentService $paymentService */
17-
$paymentService = $this->container->get('payplugmodule_payment_service');
1818
Tlog::getInstance()->addAlert('Notification received');
1919
Tlog::getInstance()->addAlert($request->getContent());
2020

2121
$notificationResource = $paymentService->getNotificationResource($request);
2222

2323
$notificationEvent = new UnknownNotificationEvent($notificationResource);
24-
$this->dispatch(UnknownNotificationEvent::UNKNOWN_NOTIFICATION_EVENT, $notificationEvent);
24+
$eventDispatcher->dispatch($notificationEvent, UnknownNotificationEvent::UNKNOWN_NOTIFICATION_EVENT);
2525

2626
return new Response();
2727
}

EventListener/ConfirmationEmailListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function updateStatus(OrderEvent $event, $eventName, EventDispatcherInter
6969
if ($order->isPaid() && $order->getPaymentModuleId() == PayPlugModule::getModuleId()) {
7070
// Send confirmation email if required.
7171
if (PayPlugModule::getConfigValue('send_confirmation_message_only_if_paid')) {
72-
$dispatcher->dispatch(TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL, $event);
72+
$dispatcher->dispatch($event, TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL);
7373
}
7474

7575
Tlog::getInstance()->debug("Confirmation email sent to customer " . $order->getCustomer()->getEmail());

EventListener/NotificationListener.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ public function handleUnknownNotification(UnknownNotificationEvent $event)
4545
switch(true) {
4646
case $resource instanceof Payment:
4747
$paymentNotificationEvent = new PaymentNotificationEvent($resource);
48-
$this->dispatcher->dispatch(PaymentNotificationEvent::PAYMENT_NOTIFICATION_EVENT, $paymentNotificationEvent);
48+
$this->dispatcher->dispatch($paymentNotificationEvent, PaymentNotificationEvent::PAYMENT_NOTIFICATION_EVENT);
4949
break;
5050
case $resource instanceof Refund:
5151
$refundNotificationEvent = new RefundNotificationEvent($resource);
52-
$this->dispatcher->dispatch(RefundNotificationEvent::REFUND_NOTIFICATION_EVENT, $refundNotificationEvent);
52+
$this->dispatcher->dispatch($refundNotificationEvent, RefundNotificationEvent::REFUND_NOTIFICATION_EVENT);
5353
break;
5454
}
5555
}
@@ -110,7 +110,7 @@ public function handlePaymentNotification(PaymentNotificationEvent $event)
110110
if (null !== $orderStatusId) {
111111
$event = (new OrderEvent($order))
112112
->setStatus($orderStatusId);
113-
$this->dispatcher->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
113+
$this->dispatcher->dispatch($event, TheliaEvents::ORDER_UPDATE_STATUS);
114114
}
115115

116116
if (null !== $paymentResource->card->id) {
@@ -151,7 +151,7 @@ protected function handleMultiPaymentNotification($paymentResource, Order $order
151151
if ($orderMultiPayment->getIsFirstPayment()) {
152152
$event = (new OrderEvent($order))
153153
->setStatus($orderStatusId);
154-
$this->dispatcher->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
154+
$this->dispatcher->dispatch($event, TheliaEvents::ORDER_UPDATE_STATUS);
155155
}
156156
}
157157

@@ -192,7 +192,7 @@ public function handleRefundNotification(RefundNotificationEvent $event)
192192

193193
$event = (new OrderEvent($order))
194194
->setStatus(OrderStatusQuery::getRefundedStatus()->getId());
195-
$this->dispatcher->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
195+
$this->dispatcher->dispatch($event, TheliaEvents::ORDER_UPDATE_STATUS);
196196
}
197197

198198
/**

EventListener/PaymentListener.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function createCapture(PayPlugPaymentEvent $paymentEvent)
9191
*/
9292
public function orderPayment(PayPlugPaymentEvent $paymentEvent)
9393
{
94-
$this->dispatcher->dispatch(PayPlugPaymentEvent::CREATE_PAYMENT_EVENT, $paymentEvent);
94+
$this->dispatcher->dispatch($paymentEvent, PayPlugPaymentEvent::CREATE_PAYMENT_EVENT);
9595

9696
$order = $paymentEvent->getOrder();
9797

@@ -106,7 +106,7 @@ public function orderPayment(PayPlugPaymentEvent $paymentEvent)
106106

107107
$orderEvent = new OrderEvent($paymentEvent->getOrder());
108108
$orderEvent->setTransactionRef($paymentEvent->getPaymentId());
109-
$this->dispatcher->dispatch(TheliaEvents::ORDER_UPDATE_TRANSACTION_REF, $orderEvent);
109+
$this->dispatcher->dispatch($orderEvent, TheliaEvents::ORDER_UPDATE_TRANSACTION_REF);
110110
}
111111

112112
/**
@@ -146,13 +146,13 @@ public function orderRefund(PayPlugPaymentEvent $paymentEvent)
146146
$refundPaymentEvent = clone $paymentEvent;
147147
$refundPaymentEvent->setPaymentId($multiPayment->getPaymentId())
148148
->setAmount($currentPaymentAmountToRefund);
149-
$this->dispatcher->dispatch(PayPlugPaymentEvent::CREATE_REFUND_EVENT, $refundPaymentEvent);
149+
$this->dispatcher->dispatch($refundPaymentEvent, PayPlugPaymentEvent::CREATE_REFUND_EVENT);
150150
$amountToRefund = $amountToRefund - $currentPaymentAmountToRefund;
151151
}
152152
return;
153153
}
154154

155-
$this->dispatcher->dispatch(PayPlugPaymentEvent::CREATE_REFUND_EVENT, $paymentEvent);
155+
$this->dispatcher->dispatch($paymentEvent, PayPlugPaymentEvent::CREATE_REFUND_EVENT);
156156
}
157157

158158
/**
@@ -164,7 +164,7 @@ public function orderRefund(PayPlugPaymentEvent $paymentEvent)
164164
*/
165165
public function orderCapture(PayPlugPaymentEvent $paymentEvent)
166166
{
167-
$this->dispatcher->dispatch(PayPlugPaymentEvent::CREATE_CAPTURE_EVENT, $paymentEvent);
167+
$this->dispatcher->dispatch($paymentEvent, PayPlugPaymentEvent::CREATE_CAPTURE_EVENT);
168168
}
169169

170170
protected function formatErrorMessage(PayplugException $exception)

0 commit comments

Comments
 (0)