示例#1
0
 /**
  * {@inheritdoc}
  */
 public function processOrderPayments(OrderInterface $order)
 {
     /** @var $payment PaymentInterface */
     $payment = $this->paymentFactory->createWithAmountAndCurrency($order->getTotal(), $order->getCurrency());
     $this->setPaymentMethodIfNeeded($order, $payment);
     $order->addPayment($payment);
 }
示例#2
0
 function it_processes_payment_for_given_order(PaymentFactoryInterface $paymentFactory, PaymentInterface $payment, OrderInterface $order)
 {
     $order->getTotal()->willReturn(1234);
     $order->getCurrency()->willReturn('EUR');
     $paymentFactory->createWithAmountAndCurrency(1234, 'EUR')->willReturn($payment);
     $order->addPayment($payment)->shouldBeCalled();
     $this->processOrderPayments($order);
 }
示例#3
0
 /**
  * {@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);
 }
 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);
 }
示例#5
0
 /**
  * @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);
 }
示例#6
0
 /**
  * {@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;
 }
 function it_adds_shipping_payment_and_addressing_info_to_an_order(AddressInterface $address, Collection $shipmentCollection, OrderInterface $order, OrderShipmentProcessorInterface $orderShipmentFactory, PaymentFactoryInterface $paymentFactory, PaymentInterface $payment, PaymentMethodInterface $paymentMethod, SharedStorageInterface $sharedStorage, ShipmentInterface $shipment, ShippingMethodInterface $shippingMethod, ObjectManager $objectManager)
 {
     $sharedStorage->get('order')->willReturn($order);
     $order->getCurrency()->willReturn('EUR');
     $order->getTotal()->willReturn(1234);
     $order->getShipments()->willReturn($shipmentCollection);
     $shipmentCollection->first()->willReturn($shipment);
     $paymentFactory->createWithAmountAndCurrency(1234, 'EUR')->willReturn($payment);
     $order->setBillingAddress($address)->shouldBeCalled();
     $order->setShippingAddress($address)->shouldBeCalled();
     $order->addPayment($payment)->shouldBeCalled();
     $payment->setMethod($paymentMethod)->shouldBeCalled();
     $shipment->setMethod($shippingMethod)->shouldBeCalled();
     $orderShipmentFactory->processOrderShipment($order)->shouldBeCalled();
     $objectManager->flush()->shouldBeCalled();
     $this->theCustomerChoseShippingToWithPayment($shippingMethod, $address, $paymentMethod);
 }
示例#9
0
 /**
  * @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_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]);
 }