/** * {@inheritdoc} */ public function processOrderPayments(OrderInterface $order) { if ($order->getLastPayment(PaymentInterface::STATE_NEW)) { return; } /** @var $payment PaymentInterface */ $payment = $this->paymentFactory->createWithAmountAndCurrencyCode($order->getTotal(), $order->getCurrencyCode()); $this->setPaymentMethodIfNeeded($order, $payment); $order->addPayment($payment); }
/** * @param BaseOrderInterface $order */ private function createNewPayment(BaseOrderInterface $order) { /** @var $payment PaymentInterface */ $payment = $this->paymentFactory->createWithAmountAndCurrencyCode($order->getTotal(), $order->getCurrencyCode()); $paymentMethod = $this->getDefaultPaymentMethod($payment, $order); $lastPayment = $this->getLastPayment($order); if (null !== $lastPayment) { $paymentMethod = $lastPayment->getMethod(); } if (null === $paymentMethod) { return; } $payment->setMethod($paymentMethod); $order->addPayment($payment); }
/** * {@inheritdoc} */ public function process(OrderInterface $order) { if (OrderInterface::STATE_CANCELLED === $order->getState()) { return; } $newPayment = $order->getLastPayment(PaymentInterface::STATE_NEW); if (null !== $newPayment) { $newPayment->setAmount($order->getTotal()); return; } /** @var $payment PaymentInterface */ $payment = $this->paymentFactory->createWithAmountAndCurrencyCode($order->getTotal(), $order->getCurrencyCode()); $this->setPaymentMethodIfNeeded($order, $payment); $order->addPayment($payment); }
/** * {@inheritdoc} */ public function provideOrderPayment(OrderInterface $order, $targetState) { /** @var PaymentInterface $payment */ $payment = $this->paymentFactory->createWithAmountAndCurrencyCode($order->getTotal(), $order->getCurrencyCode()); $paymentMethod = $this->getDefaultPaymentMethod($payment, $order); $lastPayment = $this->getLastPayment($order); if (null !== $lastPayment) { $paymentMethod = $lastPayment->getMethod(); } if (null === $paymentMethod) { throw new NotProvidedOrderPaymentException(); } $payment->setMethod($paymentMethod); $this->applyRequiredTransition($payment, $targetState); return $payment; }
/** * @Given /^the customer chose ("[^"]+" shipping method) with ("[^"]+" payment)$/ */ public function theCustomerChoseShippingWithPayment(ShippingMethodInterface $shippingMethod, PaymentMethodInterface $paymentMethod) { /** @var OrderInterface $order */ $order = $this->sharedStorage->get('order'); $this->orderShipmentFactory->processOrderShipment($order); $order->getShipments()->first()->setMethod($shippingMethod); $this->orderRecalculator->recalculate($order); $payment = $this->paymentFactory->createWithAmountAndCurrencyCode($order->getTotal(), $order->getCurrencyCode()); $payment->setMethod($paymentMethod); $order->addPayment($payment); $this->objectManager->flush(); }
function it_does_not_add_payment_during_processing_if_new_payment_already_exists(PaymentFactoryInterface $paymentFactory, PaymentInterface $newPaymentReadyToPay, PaymentInterface $cancelledPayment, PaymentInterface $payment, OrderInterface $order) { $order->getState()->willReturn(OrderInterface::STATE_NEW); $order->getTotal()->willReturn(1234); $order->getCurrencyCode()->willReturn('EUR'); $order->getLastPayment(PaymentInterface::STATE_CANCELLED)->willReturn($cancelledPayment); $order->getLastPayment(PaymentInterface::STATE_FAILED)->willReturn(null); $order->getLastPayment(PaymentInterface::STATE_NEW)->willReturn($newPaymentReadyToPay); $paymentFactory->createWithAmountAndCurrencyCode(1234, 'EUR')->willReturn($payment); $payment->setMethod($cancelledPayment)->shouldNotBeCalled(); $order->addPayment($payment)->shouldNotBeCalled(); $this->process($order); }
function it_does_not_add_payment_method_to_payment_when_default_method_resolver_throw_an_exception(PaymentFactoryInterface $paymentFactory, PaymentInterface $payment, OrderInterface $order, DefaultPaymentMethodResolverInterface $defaultPaymentMethodResolver) { $payments = new ArrayCollection(); $order->getPayments()->willReturn($payments); $order->getState()->willReturn(OrderInterface::STATE_NEW); $order->getLastNewPayment()->willReturn(null); $order->getTotal()->willReturn(1234); $order->getCurrencyCode()->willReturn('EUR'); $paymentFactory->createWithAmountAndCurrencyCode(1234, 'EUR')->willReturn($payment); $defaultPaymentMethodResolver->getDefaultPaymentMethod($payment)->shouldBeCalled(); $payment->setOrder($order)->shouldBeCalled(); $payment->setMethod(Argument::any())->shouldNotBeCalled(); $order->addPayment($payment)->shouldNotBeCalled(); $this->process($order); }
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]); }