Exemplo n.º 1
0
 /**
  * @param OrderInterface $order
  *
  * @return null|PaymentInterface
  */
 private function getLastPayment(OrderInterface $order)
 {
     $lastPayment = $order->getLastPayment(PaymentInterface::STATE_CANCELLED);
     if (null === $lastPayment) {
         $lastPayment = $order->getLastPayment(PaymentInterface::STATE_FAILED);
     }
     return $lastPayment;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 private function setPaymentMethodIfNeeded(OrderInterface $order, PaymentInterface $payment)
 {
     $lastCancelledPayment = $order->getLastPayment(PaymentInterface::STATE_CANCELLED);
     $lastNewPayment = $order->getLastPayment(PaymentInterface::STATE_NEW);
     if (!$lastNewPayment && $lastCancelledPayment) {
         $payment->setMethod($lastCancelledPayment->getMethod());
     }
 }
Exemplo n.º 3
0
 function it_does_not_set_payment_method_from_last_cancelled_payment_during_processing_if_new_payment_exists(PaymentFactoryInterface $paymentFactory, PaymentInterface $newPaymentReadyToPay, PaymentInterface $cancelledPayment, PaymentInterface $payment, OrderInterface $order)
 {
     $order->getTotal()->willReturn(1234);
     $order->getCurrency()->willReturn('EUR');
     $order->getLastPayment(PaymentInterface::STATE_CANCELLED)->willReturn($cancelledPayment);
     $order->getLastPayment(PaymentInterface::STATE_NEW)->willReturn($newPaymentReadyToPay);
     $paymentFactory->createWithAmountAndCurrency(1234, 'EUR')->willReturn($payment);
     $payment->setMethod($cancelledPayment)->shouldNotBeCalled();
     $order->addPayment($payment)->shouldBeCalled();
     $this->processOrderPayments($order);
 }
Exemplo n.º 4
0
 /**
  * @param OrderInterface $order
  *
  * @return PaymentInterface|null
  */
 private function getLastPayment(OrderInterface $order)
 {
     $lastCancelledPayment = $order->getLastPayment(PaymentInterface::STATE_CANCELLED);
     if (null !== $lastCancelledPayment) {
         return $lastCancelledPayment;
     }
     $lastFailedPayment = $order->getLastPayment(PaymentInterface::STATE_FAILED);
     if (null !== $lastFailedPayment) {
         return $lastFailedPayment;
     }
     return null;
 }
 function it_does_not_set_order_payment_if_it_cannot_be_provided(OrderInterface $order, OrderPaymentProviderInterface $orderPaymentProvider)
 {
     $order->getState()->willReturn(OrderInterface::STATE_CART);
     $order->getLastPayment(PaymentInterface::STATE_CART)->willReturn(null);
     $orderPaymentProvider->provideOrderPayment($order, PaymentInterface::STATE_CART)->willThrow(NotProvidedOrderPaymentException::class);
     $order->addPayment(Argument::any())->shouldNotBeCalled();
     $this->process($order);
 }
Exemplo n.º 6
0
 function it_tries_to_pay_again(SharedStorageInterface $sharedStorage, OrderRepositoryInterface $orderRepository, PaypalApiMocker $paypalApiMocker, OrderPaymentsPageInterface $orderPaymentsPage, OrderInterface $order, CustomerInterface $customer, UserInterface $user, PaymentInterface $payment)
 {
     $sharedStorage->get('user')->willReturn($user);
     $user->getCustomer()->willReturn($customer);
     $orderRepository->findByCustomer($customer)->willReturn([$order]);
     $order->getLastPayment()->willReturn($payment);
     $paypalApiMocker->mockApiPaymentInitializeResponse()->shouldBeCalled();
     $orderPaymentsPage->clickPayButtonForGivenPayment($payment)->shouldBeCalled();
     $this->iTryToPayAgain();
 }
 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);
 }
Exemplo n.º 8
0
 /**
  * @Given /^(this order) is already paid$/
  */
 public function thisOrderIsAlreadyPaid(OrderInterface $order)
 {
     $payment = $order->getLastPayment();
     $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH)->apply(PaymentTransitions::TRANSITION_COMPLETE);
     $this->objectManager->flush();
 }
 function it_throws_exception_if_payment_method_cannot_be_resolved_for_provided_payment(OrderInterface $order, PaymentFactoryInterface $paymentFactory, PaymentInterface $lastFailedPayment, PaymentInterface $newPayment)
 {
     $order->getTotal()->willReturn(1000);
     $order->getCurrencyCode()->willReturn('USD');
     $order->getLastPayment(PaymentInterface::STATE_CANCELLED)->willReturn(null);
     $order->getLastPayment(PaymentInterface::STATE_FAILED)->willReturn($lastFailedPayment);
     $lastFailedPayment->getMethod()->willReturn(null);
     $paymentFactory->createWithAmountAndCurrencyCode(1000, 'USD')->willReturn($newPayment);
     $this->shouldThrow(NotProvidedOrderPaymentException::class)->during('provideOrderPayment', [$order, PaymentInterface::STATE_NEW]);
 }
Exemplo n.º 10
0
 /**
  * @param OrderInterface $order
  *
  * @return null|PaymentInterface
  */
 private function getLastPayment(OrderInterface $order)
 {
     return $order->getLastPayment(PaymentInterface::STATE_CANCELLED) ?: $order->getLastPayment(PaymentInterface::STATE_FAILED);
 }