function it_applies_payment_charges(
        $adjustmentRepository,
        $delegatingFeeCalculator,
        AdjustmentInterface $adjustment,
        OrderInterface $order,
        PaymentSubjectInterface $payment,
        PaymentMethodInterface $paymentMethod
    ) {
        $order->removeAdjustments('payment')->shouldBeCalled();
        $order->getPayments()->willReturn(array($payment))->shouldBeCalled();

        $order->calculateTotal()->shouldBeCalled();

        $payment->getState()->willReturn('new')->shouldBeCalled();
        $payment->getMethod()->willReturn($paymentMethod);
        $paymentMethod->getName()->willReturn('testPaymentMethod');

        $delegatingFeeCalculator->calculate($payment)->willReturn(50);

        $adjustmentRepository->createNew()->willReturn($adjustment)->shouldBeCalled();
        $adjustment->setType('payment')->shouldBeCalled();
        $adjustment->setAmount(50)->shouldBeCalled();
        $adjustment->setDescription('testPaymentMethod')->shouldBeCalled();

        $order->addAdjustment($adjustment)->shouldBeCalled();

        $this->applyPaymentCharges($order);
    }
示例#2
0
 /**
  * @param OrderInterface $order
  */
 private function updateExistingPaymentsStates(OrderInterface $order)
 {
     foreach ($order->getPayments() as $payment) {
         $this->cancelPaymentStateIfNotStarted($payment);
     }
     $this->paymentManager->flush();
 }
示例#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);
 }
 /**
  * @param OrderInterface $order
  */
 public function applyPaymentCharges(OrderInterface $order)
 {
     $order->removeAdjustments(AdjustmentInterface::PAYMENT_ADJUSTMENT);
     $order->calculateTotal();
     foreach ($order->getPayments() as $payment) {
         $this->addAdjustmentIfForNotCancelled($order, $payment);
     }
 }
示例#5
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);
 }
示例#7
0
 function it_must_dispatch_pre_and_post_payment_state_changed_if_state_changed($factory, SecuredNotifyRequest $request, OrderInterface $order, PaymentModelInterface $paymentModel, PaymentInterface $payment, ObjectManager $objectManager, StateMachineInterface $sm, Collection $payments)
 {
     $request->getModel()->willReturn($paymentModel);
     $order->getPayments()->willReturn($payments);
     $payments->last()->willReturn($payment);
     $paymentModel->getState()->willReturn(Payment::STATE_PENDING);
     $factory->get($paymentModel, PaymentTransitions::GRAPH)->willReturn($sm);
     $sm->getTransitionToState('cancelled')->willReturn(PaymentTransitions::SYLIUS_CANCEL);
     $sm->apply(PaymentTransitions::SYLIUS_CANCEL)->shouldBeCalled()->will(function ($args) use($paymentModel) {
         $paymentModel->getState()->willReturn(Payment::STATE_CANCELLED);
     });
     $payment->execute(Argument::type('Payum\\Core\\Request\\SyncRequest'))->willReturn(null);
     $payment->execute(Argument::type('Sylius\\Bundle\\PayumBundle\\Payum\\Request\\StatusRequest'))->will(function ($args) {
         $args[0]->markCanceled();
     });
     $objectManager->flush()->shouldBeCalled();
     $this->execute($request);
 }
示例#8
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);
 }
示例#9
0
 /**
  * @param OrderInterface $order
  */
 private function selectPayment(OrderInterface $order)
 {
     $paymentMethod = $this->faker->randomElement($order->getChannel()->getPaymentMethods()->toArray());
     Assert::notNull($paymentMethod);
     foreach ($order->getPayments() as $payment) {
         $payment->setMethod($paymentMethod);
     }
     $this->applyCheckoutStateTransition($order, OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT);
 }
示例#10
0
 /**
  * @param OrderInterface $order
  * @param string $transition
  */
 private function applyPaymentTransitionOnOrder(OrderInterface $order, $transition)
 {
     foreach ($order->getPayments() as $payment) {
         $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH)->apply($transition);
     }
 }
 function it_sets_orders_total_on_payment_amount_when_payment_is_new(OrderInterface $order, PaymentInterface $payment)
 {
     $payments = new ArrayCollection();
     $order->getPayments()->willReturn($payments);
     $order->getState()->willReturn(OrderInterface::STATE_NEW);
     $order->getTotal()->willReturn(123);
     $order->getCurrencyCode()->willReturn('EUR');
     $payment->getState()->willReturn(PaymentInterface::STATE_NEW);
     $order->getLastNewPayment()->willReturn($payment);
     $payment->setAmount(123)->shouldBeCalled();
     $payment->setCurrencyCode('EUR')->shouldBeCalled();
     $this->process($order);
 }
示例#12
0
 /**
  * @param OrderInterface $order
  *
  * @return NodeElement|null
  */
 private function getLastOrderPaymentElement(OrderInterface $order)
 {
     $payment = $order->getPayments()->last();
     $paymentStateElements = $this->getElement('payments')->findAll('css', sprintf('span.ui.label:contains(\'%s\')', ucfirst($payment->getState())));
     $paymentStateElement = end($paymentStateElements);
     return $paymentStateElement->getParent()->getParent();
 }
示例#13
0
 /**
  * @param OrderInterface $order
  */
 private function selectPayment(OrderInterface $order)
 {
     $paymentMethod = $this->faker->randomElement($this->paymentMethodRepository->findEnabledForChannel($order->getChannel()));
     Assert::notNull($paymentMethod, 'Payment method should not be null.');
     foreach ($order->getPayments() as $payment) {
         $payment->setMethod($paymentMethod);
     }
     $this->applyCheckoutStateTransition($order, OrderCheckoutTransitions::TRANSITION_SELECT_PAYMENT);
 }
示例#14
0
 /**
  * @param OrderInterface $order
  * @param string $state
  *
  * @return null|PaymentInterface
  */
 private function getLastPaymentWithState(OrderInterface $order, $state)
 {
     $lastPayment = $order->getPayments()->filter(function (PaymentInterface $payment) use($state) {
         return $payment->getState() === $state;
     })->last();
     return $lastPayment !== false ? $lastPayment : null;
 }