Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function resolvePaymentState(OrderInterface $order)
 {
     $paymentState = PaymentInterface::STATE_NEW;
     if ($order->hasPayments()) {
         $payments = $order->getPayments();
         $completedPaymentTotal = 0;
         foreach ($payments as $payment) {
             if (PaymentInterface::STATE_COMPLETED === $payment->getState()) {
                 $completedPaymentTotal += $payment->getAmount();
             }
         }
         if ($completedPaymentTotal >= $order->getTotal()) {
             // Payment is completed if we have received full amount.
             $paymentState = PaymentInterface::STATE_COMPLETED;
         } else {
             // Payment is processing if one of the payment is.
             if ($payments->exists(function ($key, $payment) {
                 return in_array($payment->getState(), [PaymentInterface::STATE_PROCESSING, PaymentInterface::STATE_PENDING]);
             })) {
                 $paymentState = PaymentInterface::STATE_PROCESSING;
             }
         }
     }
     $order->setPaymentState($paymentState);
 }
 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);
 }
Exemplo n.º 3
0
 function it_marks_order_as_new_if_no_payment_is_in_process(OrderInterface $order)
 {
     $payment1 = new Payment();
     $payment1->setAmount(6000);
     $payment1->setState(PaymentInterface::STATE_NEW);
     $payment2 = new Payment();
     $payment2->setAmount(4000);
     $payment2->setState(PaymentInterface::STATE_NEW);
     $payments = new ArrayCollection(array($payment1, $payment2));
     $order->hasPayments()->willReturn(true);
     $order->getPayments()->willReturn($payments);
     $order->getTotal()->willReturn(10000);
     $order->setPaymentState(PaymentInterface::STATE_NEW)->shouldBeCalled();
     $this->resolvePaymentState($order);
 }