public getDefaultPaymentMethod ( Sylius\Component\Payment\Model\PaymentInterface $payment ) : Sylius\Component\Payment\Model\PaymentMethodInterface | ||
$payment | Sylius\Component\Payment\Model\PaymentInterface | |
리턴 | Sylius\Component\Payment\Model\PaymentMethodInterface |
/** * @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_provides_payment_in_configured_state_with_default_payment_method(DefaultPaymentMethodResolverInterface $defaultPaymentMethodResolver, OrderInterface $order, PaymentFactoryInterface $paymentFactory, PaymentInterface $newPayment, PaymentMethodInterface $paymentMethod, StateMachineFactoryInterface $stateMachineFactory, StateMachineInterface $stateMachine) { $order->getTotal()->willReturn(1000); $order->getCurrencyCode()->willReturn('USD'); $order->getLastPayment(PaymentInterface::STATE_CANCELLED)->willReturn(null); $order->getLastPayment(PaymentInterface::STATE_FAILED)->willReturn(null); $paymentFactory->createWithAmountAndCurrencyCode(1000, 'USD')->willReturn($newPayment); $newPayment->setOrder($order)->shouldBeCalled(); $defaultPaymentMethodResolver->getDefaultPaymentMethod($newPayment)->willReturn($paymentMethod); $newPayment->setMethod($paymentMethod)->shouldBeCalled(); $newPayment->getState()->willReturn(PaymentInterface::STATE_CART); $stateMachineFactory->get($newPayment, PaymentTransitions::GRAPH)->willReturn($stateMachine); $stateMachine->getTransitionToState(PaymentInterface::STATE_NEW)->willReturn(PaymentTransitions::TRANSITION_CREATE); $stateMachine->apply(PaymentTransitions::TRANSITION_CREATE)->shouldBeCalled(); $this->provideOrderPayment($order, PaymentInterface::STATE_NEW)->shouldReturn($newPayment); }
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); }