function it_returns_first_payment_method_from_availables_which_is_enclosed_in_channel(CorePaymentInterface $payment, PaymentMethodRepositoryInterface $paymentMethodRepository, PaymentMethodInterface $firstPaymentMethod, PaymentMethodInterface $secondPaymentMethod, ChannelInterface $channel, OrderInterface $order) { $payment->getOrder()->willReturn($order); $order->getChannel()->willReturn($channel); $paymentMethodRepository->findEnabledForChannel($channel)->willReturn([$firstPaymentMethod, $secondPaymentMethod]); $this->getDefaultPaymentMethod($payment)->shouldReturn($firstPaymentMethod); }
function it_should_mark_new_if_order_have_empty_payment_details(PaymentInterface $payment, StatusRequestInterface $statusRequest) { $payment->getDetails()->willReturn(array()); $statusRequest->getModel()->willReturn($payment); $statusRequest->markNew()->shouldBeCalled(); $this->execute($statusRequest); }
/** * {@inheritdoc} */ public function clickPayButtonForGivenPayment(PaymentInterface $payment) { $table = $this->getElement('table'); $row = $this->tableAccessor->getRowWithFields($this->getElement('table'), ['#' => $payment->getId()]); $actions = $this->tableAccessor->getFieldFromRow($table, $row, 'Action'); $actions->clickLink('Pay'); }
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); }
/** * {@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()); } }
/** * {@inheritdoc} */ private function setPaymentMethodIfNeeded(OrderInterface $order, PaymentInterface $payment) { $lastPayment = $this->getLastPayment($order); if (null === $lastPayment) { return; } $payment->setMethod($lastPayment->getMethod()); }
function it_dispatches_event_on_payment_update($factory, PaymentInterface $payment, OrderInterface $order, StateMachineInterface $sm, Collection $payments) { $payment->getOrder()->willReturn($order); $order->getPayments()->willReturn($payments); $order->getTotal()->willReturn(0); $payments->getIterator()->willReturn(new \EmptyIterator()); $factory->get($order, OrderTransitions::GRAPH)->willReturn($sm); $sm->apply(OrderTransitions::SYLIUS_CONFIRM, true)->shouldBeCalled(); $this->updateOrderOnPayment($payment); }
/** * {@inheritDoc} */ protected function composeDetails(PaymentInterface $payment, TokenInterface $token) { if ($payment->getDetails()) { return; } $order = $payment->getOrder(); $this->payment->execute($obtainCreditCardRequest = new ObtainCreditCardRequest($order)); $creditCard = $obtainCreditCardRequest->getCreditCard(); $total = $this->currencyConverter->convert($order->getTotal(), $order->getCurrency()); $payment->setDetails(array('card' => new SensitiveValue(array('number' => $creditCard->getNumber(), 'expiryMonth' => $creditCard->getExpiryMonth(), 'expiryYear' => $creditCard->getExpiryYear(), 'cvv' => $creditCard->getSecurityCode())), 'amount' => round($total / 100, 2), 'currency' => $order->getCurrency())); }
private function composeDetails(PaymentInterface $payment, TokenInterface $token) { $order = $payment->getOrder(); $details = []; $details['hash'] = $token->getHash(); $details['p24_amount'] = $order->getTotal(); $details['p24_email'] = $order->getEmail(); $details['p24_payment_id'] = $payment->getId(); $details['p24_session_id'] = $payment->getId() . time(); $details['p24_desc'] = sprintf("Zamówienie zawierające %d produktów na całkowitą kwotę %01.2f", $order->getItems()->count(), $order->getTotal() / 100); $payment->setDetails($details); }
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_dispatches_event_on_payment_update($factory, PaymentInterface $payment, OrderInterface $order, StateMachineInterface $sm, Collection $payments, Collection $filteredPayments) { $payment->getOrder()->willReturn($order); $payment->getState()->willReturn(PaymentInterface::STATE_COMPLETED); $payment->getAmount()->willReturn(1000); $order->getPayments()->willReturn($payments); $order->getTotal()->willReturn(1000); $order->setPaymentState(PaymentInterface::STATE_COMPLETED)->shouldBeCalled(); $payments->filter(Argument::any())->willReturn($filteredPayments); $payments->count()->willReturn(1); $filteredPayments->count()->willReturn(1); $factory->get($order, OrderTransitions::GRAPH)->willReturn($sm); $sm->apply(OrderTransitions::SYLIUS_CONFIRM, true)->shouldBeCalled(); $this->updateOrderOnPayment($payment); }
public function updateOrderOnPayment(PaymentInterface $payment) { $order = $payment->getOrder(); if (null === $order) { throw new \RuntimeException(sprintf('Cannot retrieve Order from Payment with id %s', $payment->getId())); } $total = 0; foreach ($order->getPayments() as $payment) { if ($payment->getState() === PaymentInterface::STATE_COMPLETED) { $total += $payment->getAmount(); } } if ($total === $order->getTotal()) { $this->factory->get($order, OrderTransitions::GRAPH)->apply(OrderTransitions::SYLIUS_CONFIRM, true); } }
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); }
/** * @param PaymentInterface $payment * @param TokenInterface $token * * @throws LogicException */ protected function composeDetails(PaymentInterface $payment, TokenInterface $token) { if ($payment->getDetails()) { return; } if (!$this->httpRequest) { throw new LogicException('The action can be run only when http request is set.'); } $order = $payment->getOrder(); $details = array(); $details['AMOUNT'] = $order->getTotal(); $details['CLIENTEMAIL'] = $order->getUser()->getEmail(); $details['HIDECLIENTEMAIL'] = 'yes'; $details['CLIENTUSERAGENT'] = $this->httpRequest->headers->get('User-Agent', 'Unknown'); $details['CLIENTIP'] = $this->httpRequest->getClientIp(); $details['CLIENTIDENT'] = $order->getUser()->getId(); $details['DESCRIPTION'] = sprintf('Order containing %d items for a total of %01.2f', $order->getItems()->count(), $order->getTotal() / 100); $details['ORDERID'] = $payment->getId(); $payment->setDetails($details); }
/** * {@inheritDoc} */ protected function composeDetails(PaymentInterface $payment, TokenInterface $token) { if ($payment->getDetails()) { return; } $order = $payment->getOrder(); $details = array(); $details['PAYMENTREQUEST_0_NOTIFYURL'] = $this->tokenFactory->createNotifyToken($token->getPaymentName(), $payment)->getTargetUrl(); $details['PAYMENTREQUEST_0_INVNUM'] = $order->getNumber() . '-' . $payment->getId(); $details['PAYMENTREQUEST_0_CURRENCYCODE'] = $order->getCurrency(); $details['PAYMENTREQUEST_0_AMT'] = round($order->getTotal() / 100, 2); $details['PAYMENTREQUEST_0_ITEMAMT'] = round($order->getTotal() / 100, 2); $m = 0; foreach ($order->getItems() as $item) { $details['L_PAYMENTREQUEST_0_AMT' . $m] = round($item->getTotal() / $item->getQuantity() / 100, 2); $details['L_PAYMENTREQUEST_0_QTY' . $m] = $item->getQuantity(); $m++; } if ($order->getTaxTotal() !== 0) { $details['L_PAYMENTREQUEST_0_NAME' . $m] = 'Tax Total'; $details['L_PAYMENTREQUEST_0_AMT' . $m] = round($order->getTaxTotal() / 100, 2); $details['L_PAYMENTREQUEST_0_QTY' . $m] = 1; $m++; } if ($order->getPromotionTotal() !== 0) { $details['L_PAYMENTREQUEST_0_NAME' . $m] = 'Discount'; $details['L_PAYMENTREQUEST_0_AMT' . $m] = round($order->getPromotionTotal() / 100, 2); $details['L_PAYMENTREQUEST_0_QTY' . $m] = 1; $m++; } if ($order->getShippingTotal() !== 0) { $details['L_PAYMENTREQUEST_0_NAME' . $m] = 'Shipping Total'; $details['L_PAYMENTREQUEST_0_AMT' . $m] = round($order->getShippingTotal() / 100, 2); $details['L_PAYMENTREQUEST_0_QTY' . $m] = 1; } $payment->setDetails($details); }
/** * {@inheritDoc} */ protected function composeDetails(PaymentInterface $payment, TokenInterface $token) { if ($payment->getDetails()) { return; } if (!$this->httpRequest) { throw new LogicException('The action can be run only when http request is set.'); } $order = $payment->getOrder(); $this->payment->execute($obtainCreditCardRequest = new ObtainCreditCardRequest($order)); $details = array(); $details['AMOUNT'] = $order->getTotal(); $details['CLIENTEMAIL'] = $order->getUser()->getEmail(); $details['CLIENTUSERAGENT'] = $this->httpRequest->headers->get('User-Agent', 'Unknown'); $details['CLIENTIP'] = $this->httpRequest->getClientIp(); $details['CLIENTIDENT'] = $order->getUser()->getId(); $details['DESCRIPTION'] = sprintf('Order containing %d items for a total of %01.2f', $order->getItems()->count(), $order->getTotal() / 100); $details['ORDERID'] = $payment->getId(); $details['CARDCODE'] = new SensitiveValue($obtainCreditCardRequest->getCreditCard()->getNumber()); $details['CARDCVV'] = new SensitiveValue($obtainCreditCardRequest->getCreditCard()->getSecurityCode()); $details['CARDFULLNAME'] = new SensitiveValue($obtainCreditCardRequest->getCreditCard()->getCardholderName()); $details['CARDVALIDITYDATE'] = new SensitiveValue(sprintf('%02d-%02d', $obtainCreditCardRequest->getCreditCard()->getExpiryMonth(), substr($obtainCreditCardRequest->getCreditCard()->getExpiryYear(), -2))); $payment->setDetails($details); }
public function updateOrderOnPayment(PaymentInterface $payment) { /** @var $order OrderInterface */ $order = $payment->getOrder(); if (null === $order) { throw new \RuntimeException(sprintf('Cannot retrieve Order from Payment with id %s', $payment->getId())); } $total = 0; if (PaymentInterface::STATE_COMPLETED === $payment->getState()) { $payments = $order->getPayments()->filter(function (PaymentInterface $payment) { return PaymentInterface::STATE_COMPLETED === $payment->getState(); }); if ($payments->count() === $order->getPayments()->count()) { $order->setPaymentState(PaymentInterface::STATE_COMPLETED); } $total += $payment->getAmount(); } else { $order->setPaymentState($payment->getState()); } if ($total >= $order->getTotal()) { $this->factory->get($order, OrderTransitions::GRAPH)->apply(OrderTransitions::SYLIUS_CONFIRM, true); } }
function it_returns_last_new_payment_from_payments_in_various_states(PaymentInterface $payment1, PaymentInterface $payment2, PaymentInterface $payment3, PaymentInterface $payment4) { $payment1->getState()->willReturn(PaymentInterface::STATE_NEW); $payment1->setOrder($this)->shouldBeCalled(); $payment2->getState()->willReturn(PaymentInterface::STATE_CANCELLED); $payment2->setOrder($this)->shouldBeCalled(); $payment3->getState()->willReturn(PaymentInterface::STATE_CART); $payment3->setOrder($this)->shouldBeCalled(); $payment4->getState()->willReturn(PaymentInterface::STATE_FAILED); $payment4->setOrder($this)->shouldBeCalled(); $this->addPayment($payment1); $this->addPayment($payment2); $this->addPayment($payment3); $this->addPayment($payment4); $this->getLastNewPayment()->shouldReturn($payment1); }
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); }
function it_returns_last_payment(PaymentInterface $payment1, PaymentInterface $payment2) { $payment1->getState()->willReturn(PaymentInterface::STATE_NEW); $payment1->setOrder($this)->shouldBeCalled(); $payment2->getState()->willReturn(PaymentInterface::STATE_NEW); $payment2->setOrder($this)->shouldBeCalled(); $this->addPayment($payment1); $this->addPayment($payment2); $this->getLastPayment()->shouldReturn($payment2); }
/** * @param PaymentInterface $payment */ private function cancelPaymentStateIfNotStarted(PaymentInterface $payment) { if (PaymentInterface::STATE_NEW === $payment->getState()) { $payment->setState(PaymentInterface::STATE_CANCELLED); } }
function it_returns_last_payment_with_any_state_if_there_is_no_target_state_specified(PaymentInterface $payment1, PaymentInterface $payment2, PaymentInterface $payment3, PaymentInterface $payment4) { $payment1->getState()->willReturn(PaymentInterface::STATE_CART); $payment1->setOrder($this)->shouldBeCalled(); $payment2->getState()->willReturn(PaymentInterface::STATE_CANCELLED); $payment2->setOrder($this)->shouldBeCalled(); $payment3->getState()->willReturn(PaymentInterface::STATE_PROCESSING); $payment3->setOrder($this)->shouldBeCalled(); $payment4->getState()->willReturn(PaymentInterface::STATE_FAILED); $payment4->setOrder($this)->shouldBeCalled(); $this->addPayment($payment1); $this->addPayment($payment2); $this->addPayment($payment3); $this->addPayment($payment4); $this->getLastPayment()->shouldReturn($payment4); }
/** * @param PaymentInterface $payment * @param OrderInterface $order * * @return null|PaymentMethodInterface */ private function getDefaultPaymentMethod(PaymentInterface $payment, OrderInterface $order) { try { $payment->setOrder($order); $paymentMethod = $this->defaultPaymentMethodResolver->getDefaultPaymentMethod($payment); return $paymentMethod; } catch (UnresolvedDefaultPaymentMethodException $exception) { return null; } }
function it_does_not_support_payments_which_has_no_order_defined(PaymentInterface $payment) { $payment->getOrder()->willReturn(null); $this->supports($payment)->shouldReturn(false); }
/** * {@inheritdoc} */ public function clickPayButtonForGivenPayment(PaymentInterface $payment) { $this->getDocument()->clickLink(sprintf('pay_%s', $payment->getId())); }
/** * @param PaymentInterface $payment * @param string $targetState */ private function applyRequiredTransition(PaymentInterface $payment, $targetState) { if ($targetState === $payment->getState()) { return; } /** @var StateMachineInterface $stateMachine */ $stateMachine = $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH); $targetTransition = $stateMachine->getTransitionToState($targetState); if (null !== $targetTransition) { $stateMachine->apply($targetTransition); } }