Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function processOrderPayments(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);
 }
 function it_executes_request(InvoiceNumberGeneratorInterface $invoiceNumberGenerator, CurrencyConverterInterface $currencyConverter, Convert $request, PaymentInterface $payment, OrderInterface $order, OrderItemInterface $orderItem, ProductVariantInterface $productVariant, ProductInterface $product)
 {
     $request->getTo()->willReturn('array');
     $payment->getId()->willReturn(19);
     $order->getId()->willReturn(92);
     $order->getId()->willReturn(92);
     $order->getCurrencyCode()->willReturn('PLN');
     $order->getTotal()->willReturn(22000);
     $order->getItems()->willReturn([$orderItem]);
     $order->getAdjustmentsTotalRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->willReturn(0);
     $order->getOrderPromotionTotal()->willReturn(0);
     $order->getShippingTotal()->willReturn(2000);
     $orderItem->getVariant()->willReturn($productVariant);
     $orderItem->getDiscountedUnitPrice()->willReturn(20000);
     $orderItem->getQuantity()->willReturn(1);
     $productVariant->getProduct()->willReturn($product);
     $product->getName()->willReturn('Lamborghini Aventador Model');
     $request->getSource()->willReturn($payment);
     $payment->getOrder()->willReturn($order);
     $invoiceNumberGenerator->generate($order, $payment)->willReturn('19-92');
     $currencyConverter->convertFromBase(22000, 'PLN')->willReturn(88000);
     $currencyConverter->convertFromBase(20000, 'PLN')->willReturn(80000);
     $currencyConverter->convertFromBase(2000, 'PLN')->willReturn(8000);
     $details = ['PAYMENTREQUEST_0_INVNUM' => '19-92', 'PAYMENTREQUEST_0_CURRENCYCODE' => 'PLN', 'PAYMENTREQUEST_0_AMT' => 880.0, 'PAYMENTREQUEST_0_ITEMAMT' => 880.0, 'L_PAYMENTREQUEST_0_NAME0' => 'Lamborghini Aventador Model', 'L_PAYMENTREQUEST_0_AMT0' => 800.0, 'L_PAYMENTREQUEST_0_QTY0' => 1, 'L_PAYMENTREQUEST_0_NAME1' => 'Shipping Total', 'L_PAYMENTREQUEST_0_AMT1' => 80.0, 'L_PAYMENTREQUEST_0_QTY1' => 1];
     $request->setResult($details)->shouldBeCalled();
     $this->execute($request);
 }
Esempio n. 3
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);
 }
Esempio n. 4
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);
 }
Esempio n. 5
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);
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 public function createPayment(OrderInterface $order)
 {
     $payment = $this->paymentRepository->createNew();
     $payment->setCurrency($order->getCurrency());
     $payment->setAmount($order->getTotal());
     $order->addPayment($payment);
     return $payment;
 }
 function it_sets_last_order_currency_with_target_state_currency_code_and_amount(OrderInterface $order, PaymentInterface $payment)
 {
     $order->getState()->willReturn(OrderInterface::STATE_CART);
     $order->getLastPayment(PaymentInterface::STATE_CART)->willReturn($payment);
     $order->getCurrencyCode()->willReturn('PLN');
     $order->getTotal()->willReturn(1000);
     $payment->setCurrencyCode('PLN')->shouldBeCalled();
     $payment->setAmount(1000)->shouldBeCalled();
     $this->process($order);
 }
Esempio n. 8
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);
 }
Esempio n. 9
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);
 }
 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);
 }
 /**
  * {@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_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);
 }
Esempio n. 13
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);
 }
 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]);
 }