From 09e24fd612f89e503f48f7122935f0445c58b8ec Mon Sep 17 00:00:00 2001 From: Michal Kruzik Date: Fri, 5 Jun 2015 16:05:10 +0200 Subject: [PATCH] dummy payment automaticaly makes order paid and shipped --- .../Dummy/Action/PaymentStatusAction.php | 32 ++++++++++++++++++- .../PayumBundle/Resources/config/services.xml | 4 ++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Sylius/Bundle/PayumBundle/Payum/Dummy/Action/PaymentStatusAction.php b/src/Sylius/Bundle/PayumBundle/Payum/Dummy/Action/PaymentStatusAction.php index cca412002b5..2002bf602ed 100644 --- a/src/Sylius/Bundle/PayumBundle/Payum/Dummy/Action/PaymentStatusAction.php +++ b/src/Sylius/Bundle/PayumBundle/Payum/Dummy/Action/PaymentStatusAction.php @@ -14,10 +14,27 @@ use Payum\Core\Action\PaymentAwareAction; use Payum\Core\Exception\RequestNotSupportedException; use Payum\Core\Request\GetStatusInterface; -use Sylius\Component\Payment\Model\PaymentInterface; +use Sylius\Component\Core\Model\PaymentInterface; +use Sylius\Component\Order\Model\OrderInterface; +use Sylius\Component\Order\OrderTransitions; +use Sylius\Component\Shipping\Model\ShipmentInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; class PaymentStatusAction extends PaymentAwareAction { + /** + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + private $container; + + /** + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container + */ + public function __construct(ContainerInterface $container) + { + $this->container = $container; + } + /** * {@inheritDoc} * @@ -40,6 +57,19 @@ public function execute($request) } if (isset($paymentDetails['captured'])) { + $factory = $this->container->get('sm.factory'); + /** @var $order \Funlife\Bundle\EshopBundle\Entity\Order */ + $order = $payment->getOrder(); + $orderSM = $factory->get($order, OrderTransitions::GRAPH); + if($orderSM->can(OrderTransitions::SYLIUS_CONFIRM)) { + $orderSM->apply(OrderTransitions::SYLIUS_CONFIRM); + if($orderSM->can(OrderTransitions::SYLIUS_SHIP)) { + $orderSM->apply(OrderTransitions::SYLIUS_SHIP); + } + } else { // if state machine won't work the information about sold tickets will not be updated but at least the client will not be affected + $order->getLastShipment()->setState(ShipmentInterface::STATE_SHIPPED); + $order->setState(OrderInterface::STATE_SHIPPED); + } $request->markCaptured(); return; diff --git a/src/Sylius/Bundle/PayumBundle/Resources/config/services.xml b/src/Sylius/Bundle/PayumBundle/Resources/config/services.xml index bb2130d3b72..3b6ac90d2d4 100644 --- a/src/Sylius/Bundle/PayumBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/PayumBundle/Resources/config/services.xml @@ -94,7 +94,9 @@ - + + +