Skip to content

Commit

Permalink
dummy payment automaticaly makes order paid and shipped
Browse files Browse the repository at this point in the history
  • Loading branch information
Dukecz committed Jun 5, 2015
1 parent 6dc34c9 commit 09e24fd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/Sylius/Bundle/PayumBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@

<!-- Dummy -->
<service id="sylius.payum.dummy.action.capture_payment" class="%sylius.payum.dummy.action.capture_payment.class%" public="false" />
<service id="sylius.payum.dummy.action.payment_status" class="%sylius.payum.dummy.action.payment_status.class%" public="false" />
<service id="sylius.payum.dummy.action.payment_status" class="%sylius.payum.dummy.action.payment_status.class%" public="false">
<argument type="service" id="service_container"/>
</service>
</services>

</container>

0 comments on commit 09e24fd

Please sign in to comment.