예제 #1
0
 public function updateOrderOnPayment(PaymentInterface $payment)
 {
     /** @var $order OrderInterface */
     $order = $payment->getOrder();
     if (null === $order) {
         throw new \RuntimeException(sprintf('Cannot retrieve Order from Payment with id %s', $payment->getId()));
     }
     $total = 0;
     if (PaymentInterface::STATE_COMPLETED === $payment->getState()) {
         $payments = $order->getPayments()->filter(function (PaymentInterface $payment) {
             return PaymentInterface::STATE_COMPLETED === $payment->getState();
         });
         if ($payments->count() === $order->getPayments()->count()) {
             $order->setPaymentState(PaymentInterface::STATE_COMPLETED);
         }
         $total += $payment->getAmount();
     } else {
         $order->setPaymentState($payment->getState());
     }
     if ($total >= $order->getTotal()) {
         $this->factory->get($order, OrderTransitions::GRAPH)->apply(OrderTransitions::SYLIUS_CONFIRM, true);
     }
 }
예제 #2
0
 function it_sets_not_started_payments_as_cancelled_while_creating_payment($paymentManager, $paymentFactory, OrderInterface $order, PaymentInterface $existingPayment, PaymentInterface $payment)
 {
     $existingPayment->getState()->willReturn('new');
     $order->getPayments()->willReturn(array($existingPayment))->shouldBeCalled();
     $existingPayment->setState('cancelled')->shouldBeCalled();
     $paymentManager->flush()->shouldBeCalled();
     $order->getCurrency()->willReturn('EUR')->shouldBeCalled();
     $order->getTotal()->willReturn(100)->shouldBeCalled();
     $paymentFactory->createNew()->willReturn($payment)->shouldBeCalled();
     $payment->setCurrency('EUR')->shouldBeCalled();
     $payment->setAmount(100)->shouldBeCalled();
     $order->addPayment($payment)->shouldBeCalled();
     $this->createPayment($order)->shouldReturn($payment);
 }
예제 #3
0
 function it_dispatches_event_on_payment_update($factory, PaymentInterface $payment, OrderInterface $order, StateMachineInterface $sm, Collection $payments, Collection $filteredPayments)
 {
     $payment->getOrder()->willReturn($order);
     $payment->getState()->willReturn(PaymentInterface::STATE_COMPLETED);
     $payment->getAmount()->willReturn(1000);
     $order->getPayments()->willReturn($payments);
     $order->getTotal()->willReturn(1000);
     $order->setPaymentState(PaymentInterface::STATE_COMPLETED)->shouldBeCalled();
     $payments->filter(Argument::any())->willReturn($filteredPayments);
     $payments->count()->willReturn(1);
     $filteredPayments->count()->willReturn(1);
     $factory->get($order, OrderTransitions::GRAPH)->willReturn($sm);
     $sm->apply(OrderTransitions::SYLIUS_CONFIRM, true)->shouldBeCalled();
     $this->updateOrderOnPayment($payment);
 }
 function it_marks_order_as_partially_paid_if_one_of_the_payment_is_processing(FactoryInterface $stateMachineFactory, StateMachineInterface $stateMachine, OrderInterface $order, PaymentInterface $payment1, PaymentInterface $payment2)
 {
     $payment1->getAmount()->willReturn(6000);
     $payment1->getState()->willReturn(PaymentInterface::STATE_PROCESSING);
     $payment2->getAmount()->willReturn(4000);
     $payment2->getState()->willReturn(PaymentInterface::STATE_COMPLETED);
     $payments = new ArrayCollection([$payment1->getWrappedObject(), $payment2->getWrappedObject()]);
     $order->hasPayments()->willReturn(true);
     $order->getPayments()->willReturn($payments);
     $order->getPaymentState()->willReturn(OrderPaymentStates::STATE_AWAITING_PAYMENT);
     $order->getTotal()->willReturn(10000);
     $stateMachineFactory->get($order, OrderPaymentTransitions::GRAPH)->willReturn($stateMachine);
     $stateMachine->can(OrderPaymentTransitions::TRANSITION_PARTIALLY_PAY)->willReturn(true);
     $stateMachine->apply(OrderPaymentTransitions::TRANSITION_PARTIALLY_PAY)->shouldBeCalled();
     $this->resolve($order);
 }
예제 #5
0
 public function updateOrderOnPayment(PaymentInterface $payment)
 {
     $order = $payment->getOrder();
     if (null === $order) {
         throw new \RuntimeException(sprintf('Cannot retrieve Order from Payment with id %s', $payment->getId()));
     }
     $total = 0;
     foreach ($order->getPayments() as $payment) {
         if ($payment->getState() === PaymentInterface::STATE_COMPLETED) {
             $total += $payment->getAmount();
         }
     }
     if ($total === $order->getTotal()) {
         $this->factory->get($order, OrderTransitions::GRAPH)->apply(OrderTransitions::SYLIUS_CONFIRM, true);
     }
 }
예제 #6
0
 function it_returns_last_new_payment_from_payments_in_various_states(PaymentInterface $payment1, PaymentInterface $payment2, PaymentInterface $payment3, PaymentInterface $payment4)
 {
     $payment1->getState()->willReturn(PaymentInterface::STATE_NEW);
     $payment1->setOrder($this)->shouldBeCalled();
     $payment2->getState()->willReturn(PaymentInterface::STATE_CANCELLED);
     $payment2->setOrder($this)->shouldBeCalled();
     $payment3->getState()->willReturn(PaymentInterface::STATE_CART);
     $payment3->setOrder($this)->shouldBeCalled();
     $payment4->getState()->willReturn(PaymentInterface::STATE_FAILED);
     $payment4->setOrder($this)->shouldBeCalled();
     $this->addPayment($payment1);
     $this->addPayment($payment2);
     $this->addPayment($payment3);
     $this->addPayment($payment4);
     $this->getLastNewPayment()->shouldReturn($payment1);
 }
 function it_sets_orders_total_on_payment_amount_when_payment_is_new(OrderInterface $order, PaymentInterface $payment)
 {
     $order->getState()->willReturn(OrderInterface::STATE_NEW);
     $order->getTotal()->willReturn(123);
     $order->getCurrencyCode()->willReturn('EUR');
     $payment->getState()->willReturn(PaymentInterface::STATE_NEW);
     $order->getLastPayment(PaymentInterface::STATE_NEW)->willReturn($payment);
     $payment->setAmount(123)->shouldBeCalled();
     $payment->setCurrencyCode('EUR')->shouldBeCalled();
     $this->process($order);
 }
예제 #8
0
파일: OrderSpec.php 프로젝트: Hsidhu/Sylius
 function it_returns_last_payment(PaymentInterface $payment1, PaymentInterface $payment2)
 {
     $payment1->getState()->willReturn(PaymentInterface::STATE_NEW);
     $payment1->setOrder($this)->shouldBeCalled();
     $payment2->getState()->willReturn(PaymentInterface::STATE_NEW);
     $payment2->setOrder($this)->shouldBeCalled();
     $this->addPayment($payment1);
     $this->addPayment($payment2);
     $this->getLastPayment()->shouldReturn($payment2);
 }
예제 #9
0
 /**
  * @param PaymentInterface $payment
  */
 private function cancelPaymentStateIfNotStarted(PaymentInterface $payment)
 {
     if (PaymentInterface::STATE_NEW === $payment->getState()) {
         $payment->setState(PaymentInterface::STATE_CANCELLED);
     }
 }
예제 #10
0
 /**
  * @param PaymentInterface $payment
  * @param string $targetState
  */
 private function applyRequiredTransition(PaymentInterface $payment, $targetState)
 {
     if ($targetState === $payment->getState()) {
         return;
     }
     /** @var StateMachineInterface $stateMachine */
     $stateMachine = $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH);
     $targetTransition = $stateMachine->getTransitionToState($targetState);
     if (null !== $targetTransition) {
         $stateMachine->apply($targetTransition);
     }
 }
예제 #11
0
 function it_returns_last_payment_with_any_state_if_there_is_no_target_state_specified(PaymentInterface $payment1, PaymentInterface $payment2, PaymentInterface $payment3, PaymentInterface $payment4)
 {
     $payment1->getState()->willReturn(PaymentInterface::STATE_CART);
     $payment1->setOrder($this)->shouldBeCalled();
     $payment2->getState()->willReturn(PaymentInterface::STATE_CANCELLED);
     $payment2->setOrder($this)->shouldBeCalled();
     $payment3->getState()->willReturn(PaymentInterface::STATE_PROCESSING);
     $payment3->setOrder($this)->shouldBeCalled();
     $payment4->getState()->willReturn(PaymentInterface::STATE_FAILED);
     $payment4->setOrder($this)->shouldBeCalled();
     $this->addPayment($payment1);
     $this->addPayment($payment2);
     $this->addPayment($payment3);
     $this->addPayment($payment4);
     $this->getLastPayment()->shouldReturn($payment4);
 }