allow possibility for payment module to return a response
This commit is contained in:
@@ -176,7 +176,11 @@ class Module extends BaseAction implements EventSubscriberInterface
|
|||||||
|
|
||||||
$paymentModuleInstance = $this->container->get(sprintf('module.%s', $paymentModule->getCode()));
|
$paymentModuleInstance = $this->container->get(sprintf('module.%s', $paymentModule->getCode()));
|
||||||
|
|
||||||
$paymentModuleInstance->pay($order);
|
$response = $paymentModuleInstance->pay($order);
|
||||||
|
|
||||||
|
if (null !== $response && $response instanceof \Thelia\Core\HttpFoundation\Response) {
|
||||||
|
$event->setResponse($response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -340,12 +340,6 @@ class Order extends BaseAction implements EventSubscriberInterface
|
|||||||
$event->getDispatcher()->dispatch(TheliaEvents::ORDER_BEFORE_PAYMENT, new OrderEvent($placedOrder));
|
$event->getDispatcher()->dispatch(TheliaEvents::ORDER_BEFORE_PAYMENT, new OrderEvent($placedOrder));
|
||||||
|
|
||||||
|
|
||||||
/* clear session */
|
|
||||||
$session
|
|
||||||
->setProcessedOrder($placedOrder)
|
|
||||||
->setOrder(new \Thelia\Model\Order())
|
|
||||||
;
|
|
||||||
|
|
||||||
/* but memorize placed order */
|
/* but memorize placed order */
|
||||||
$event->setOrder(new \Thelia\Model\Order());
|
$event->setOrder(new \Thelia\Model\Order());
|
||||||
$event->setPlacedOrder($placedOrder);
|
$event->setPlacedOrder($placedOrder);
|
||||||
@@ -353,14 +347,14 @@ class Order extends BaseAction implements EventSubscriberInterface
|
|||||||
/* empty cart */
|
/* empty cart */
|
||||||
$dispatcher = $event->getDispatcher();
|
$dispatcher = $event->getDispatcher();
|
||||||
|
|
||||||
$dispatcher->dispatch(
|
|
||||||
TheliaEvents::CART_CLEAR, new CartEvent($this->getCart($dispatcher, $this->request)));
|
|
||||||
|
|
||||||
|
|
||||||
/* call pay method */
|
/* call pay method */
|
||||||
$payEvent = new OrderPaymentEvent($placedOrder);
|
$payEvent = new OrderPaymentEvent($placedOrder);
|
||||||
|
|
||||||
$dispatcher->dispatch(TheliaEvents::MODULE_PAY, $payEvent);
|
$dispatcher->dispatch(TheliaEvents::MODULE_PAY, $payEvent);
|
||||||
|
|
||||||
|
if ($payEvent->hasResponse()) {
|
||||||
|
$event->setResponse($payEvent->getResponse());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -135,7 +135,12 @@ trait CartTrait
|
|||||||
$id = null;
|
$id = null;
|
||||||
if (ConfigQuery::read("cart.session_only", 0) == 0) {
|
if (ConfigQuery::read("cart.session_only", 0) == 0) {
|
||||||
$id = uniqid('', true);
|
$id = uniqid('', true);
|
||||||
setcookie("thelia_cart", $id, time()+ConfigQuery::read("cart.cookie_lifetime", 60*60*24*365));
|
setcookie(
|
||||||
|
"thelia_cart",
|
||||||
|
$id,
|
||||||
|
time()+ConfigQuery::read("cart.cookie_lifetime", 60*60*24*365),
|
||||||
|
'/'
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
namespace Thelia\Core\Event\Order;
|
namespace Thelia\Core\Event\Order;
|
||||||
|
|
||||||
use Thelia\Core\Event\ActionEvent;
|
use Thelia\Core\Event\ActionEvent;
|
||||||
|
use Thelia\Core\HttpFoundation\Response;
|
||||||
use Thelia\Model\Order;
|
use Thelia\Model\Order;
|
||||||
|
|
||||||
class OrderEvent extends ActionEvent
|
class OrderEvent extends ActionEvent
|
||||||
@@ -39,6 +40,11 @@ class OrderEvent extends ActionEvent
|
|||||||
protected $status = null;
|
protected $status = null;
|
||||||
protected $deliveryRef = null;
|
protected $deliveryRef = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Response
|
||||||
|
*/
|
||||||
|
protected $response;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Order $order
|
* @param Order $order
|
||||||
*/
|
*/
|
||||||
@@ -206,4 +212,28 @@ class OrderEvent extends ActionEvent
|
|||||||
{
|
{
|
||||||
return $this->deliveryRef;
|
return $this->deliveryRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Response $response
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setResponse(Response $response)
|
||||||
|
{
|
||||||
|
$this->response = $response;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function getResponse()
|
||||||
|
{
|
||||||
|
return $this->response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasResponse()
|
||||||
|
{
|
||||||
|
return null !== $this->response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
namespace Thelia\Core\Event\Order;
|
namespace Thelia\Core\Event\Order;
|
||||||
|
|
||||||
use Thelia\Core\Event\ActionEvent;
|
use Thelia\Core\Event\ActionEvent;
|
||||||
|
use Thelia\Core\HttpFoundation\Response;
|
||||||
use Thelia\Model\Order;
|
use Thelia\Model\Order;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,6 +39,11 @@ class OrderPaymentEvent extends ActionEvent
|
|||||||
*/
|
*/
|
||||||
protected $order;
|
protected $order;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Thelia\Core\HttpFoundation\Response
|
||||||
|
*/
|
||||||
|
protected $response;
|
||||||
|
|
||||||
public function __construct(Order $order) {
|
public function __construct(Order $order) {
|
||||||
$this->order = $order;
|
$this->order = $order;
|
||||||
}
|
}
|
||||||
@@ -49,4 +55,29 @@ class OrderPaymentEvent extends ActionEvent
|
|||||||
{
|
{
|
||||||
return $this->order;
|
return $this->order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Thelia\Core\HttpFoundation\Response $response
|
||||||
|
*/
|
||||||
|
public function setResponse(Response $response)
|
||||||
|
{
|
||||||
|
$this->response = $response;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Thelia\Core\HttpFoundation\Response
|
||||||
|
*/
|
||||||
|
public function getResponse()
|
||||||
|
{
|
||||||
|
return $this->response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasResponse()
|
||||||
|
{
|
||||||
|
return null !== $this->response;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -253,26 +253,6 @@ class Session extends BaseSession
|
|||||||
return $this->get("thelia.order");
|
return $this->get("thelia.order");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Order $order
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setProcessedOrder(Order $order)
|
|
||||||
{
|
|
||||||
$this->set('thelia.order.processed', $order);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return an order already processed, usefull for payment modules
|
|
||||||
* @return Order
|
|
||||||
*/
|
|
||||||
public function getProcessedOrder()
|
|
||||||
{
|
|
||||||
return $this->get('thelia.order.processed');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set consumed coupons by the Customer
|
* Set consumed coupons by the Customer
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
namespace Front\Controller;
|
namespace Front\Controller;
|
||||||
|
|
||||||
use Propel\Runtime\Exception\PropelException;
|
use Propel\Runtime\Exception\PropelException;
|
||||||
|
use Thelia\Cart\CartTrait;
|
||||||
use Thelia\Controller\Front\BaseFrontController;
|
use Thelia\Controller\Front\BaseFrontController;
|
||||||
use Thelia\Core\Event\PdfEvent;
|
use Thelia\Core\Event\PdfEvent;
|
||||||
use Thelia\Core\HttpFoundation\Response;
|
use Thelia\Core\HttpFoundation\Response;
|
||||||
@@ -51,6 +52,7 @@ use Thelia\Tools\URL;
|
|||||||
*/
|
*/
|
||||||
class OrderController extends BaseFrontController
|
class OrderController extends BaseFrontController
|
||||||
{
|
{
|
||||||
|
use CartTrait;
|
||||||
/**
|
/**
|
||||||
* set delivery address
|
* set delivery address
|
||||||
* set delivery module
|
* set delivery module
|
||||||
@@ -199,7 +201,11 @@ class OrderController extends BaseFrontController
|
|||||||
|
|
||||||
if (null !== $placedOrder && null !== $placedOrder->getId()) {
|
if (null !== $placedOrder && null !== $placedOrder->getId()) {
|
||||||
/* order has been placed */
|
/* order has been placed */
|
||||||
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute('order.placed', array('order_id' => $orderEvent->getPlacedOrder()->getId()))));
|
if($orderEvent->hasResponse()) {
|
||||||
|
return $orderEvent->getResponse();
|
||||||
|
} else {
|
||||||
|
$this->redirect(URL::getInstance()->absoluteUrl($this->getRoute('order.placed', array('order_id' => $orderEvent->getPlacedOrder()->getId()))));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* order has not been placed */
|
/* order has not been placed */
|
||||||
$this->redirectToRoute('cart.view');
|
$this->redirectToRoute('cart.view');
|
||||||
@@ -222,6 +228,10 @@ class OrderController extends BaseFrontController
|
|||||||
if (null === $customer || $placedOrder->getCustomerId() !== $customer->getId()) {
|
if (null === $customer || $placedOrder->getCustomerId() !== $customer->getId()) {
|
||||||
throw new TheliaProcessException("Received placed order id does not belong to the current customer", TheliaProcessException::PLACED_ORDER_ID_BAD_CURRENT_CUSTOMER, $placedOrder);
|
throw new TheliaProcessException("Received placed order id does not belong to the current customer", TheliaProcessException::PLACED_ORDER_ID_BAD_CURRENT_CUSTOMER, $placedOrder);
|
||||||
}
|
}
|
||||||
|
$session = $this->getRequest()->getSession();
|
||||||
|
$this->createCart($this->getRequest()->getSession());
|
||||||
|
|
||||||
|
$session->setOrder(new Order());
|
||||||
|
|
||||||
$this->getParserContext()->set("placed_order_id", $placedOrder->getId());
|
$this->getParserContext()->set("placed_order_id", $placedOrder->getId());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user