Skip to content

Commit

Permalink
Use the state machine to apply the create transition before authorizi…
Browse files Browse the repository at this point in the history
…ng payment.
  • Loading branch information
alexsegura committed Apr 16, 2018
1 parent d192144 commit f558b06
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
4 changes: 4 additions & 0 deletions app/config/state_machine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ winzou_state_machine:
do: ["@sylius.order_number_assigner", "assignNumber"]
args: ["object"]
after:
after_create_create_payment:
on: ["create"]
do: ["@sm.callback.cascade_transition", "apply"]
args: ["object.getLastPayment('cart')", "event", "'create'", "'sylius_payment'"]
after_create_authorize_payment:
on: "create"
do: ["@coopcycle.order_manager", "authorizePayment"]
Expand Down
13 changes: 2 additions & 11 deletions src/AppBundle/Service/OrderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,8 @@ public function pay(OrderInterface $order, $stripeToken)

public function create(OrderInterface $order)
{
$orderStateMachine = $this->stateMachineFactory->get($order, OrderTransitions::GRAPH);
$stripePayment = $order->getLastPayment(PaymentInterface::STATE_CART);
$paymentStateMachine = $this->stateMachineFactory->get($stripePayment, PaymentTransitions::GRAPH);
$paymentStateMachine->apply(PaymentTransitions::TRANSITION_CREATE);

// apply the order transition after because we need the payment in state new in the create order hook
$orderStateMachine->apply(OrderTransitions::TRANSITION_CREATE);

$stripePayment = $order->getLastPayment(PaymentInterface::STATE_CART);
$paymentStateMachine = $this->stateMachineFactory->get($stripePayment, PaymentTransitions::GRAPH);
$paymentStateMachine->apply(PaymentTransitions::TRANSITION_CREATE);
$stateMachine = $this->stateMachineFactory->get($order, OrderTransitions::GRAPH);
$stateMachine->apply(OrderTransitions::TRANSITION_CREATE);
}

public function accept(OrderInterface $order)
Expand Down

0 comments on commit f558b06

Please sign in to comment.