コード例 #1
0
 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);
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  *
  * @throws \InvalidArgumentException
  */
 public function update(OrderInterface $order)
 {
     $currencyCode = $order->getCurrencyCode();
     /** @var CurrencyInterface $currency */
     $currency = $this->currencyRepository->findOneBy(['code' => $currencyCode]);
     Assert::notNull($currency);
     $order->setExchangeRate($currency->getExchangeRate());
 }
コード例 #3
0
 function it_updates_orders_exchange_rate(RepositoryInterface $currencyRepository, OrderInterface $order, CurrencyInterface $currency)
 {
     $order->getCurrencyCode()->willReturn('USD');
     $currency->getCode()->willReturn('USD');
     $currency->getExchangeRate()->willReturn(2);
     $currencyRepository->findOneBy(['code' => 'USD'])->willReturn($currency);
     $order->setExchangeRate(2)->shouldBeCalled();
     $this->update($order);
 }
コード例 #4
0
 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);
 }
コード例 #5
0
ファイル: PaymentProcessor.php プロジェクト: okwinza/Sylius
 /**
  * {@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);
 }
コード例 #6
0
 function it_does_not_apply_bigger_discount_than_promotion_subject_total(ChannelInterface $channel, OrderInterface $order, OrderItemInterface $firstItem, OrderItemInterface $secondItem, PromotionInterface $promotion, ProportionalIntegerDistributorInterface $proportionalIntegerDistributor, UnitsPromotionAdjustmentsApplicatorInterface $unitsPromotionAdjustmentsApplicator)
 {
     $order->getCurrencyCode()->willReturn('USD');
     $order->getChannel()->willReturn($channel);
     $channel->getCode()->willReturn('WEB_US');
     $order->countItems()->willReturn(2);
     $order->getItems()->willReturn(new \ArrayIterator([$firstItem->getWrappedObject(), $secondItem->getWrappedObject()]));
     $order->getPromotionSubjectTotal()->willReturn(10000);
     $firstItem->getTotal()->willReturn(6000);
     $secondItem->getTotal()->willReturn(4000);
     $proportionalIntegerDistributor->distribute([6000, 4000], -10000)->willReturn([-6000, -4000]);
     $unitsPromotionAdjustmentsApplicator->apply($order, $promotion, [-6000, -4000])->shouldBeCalled();
     $this->execute($order, ['WEB_US' => ['amount' => 15000]], $promotion)->shouldReturn(true);
 }
コード例 #7
0
 function it_recalculates_prices_adding_customer_to_the_context(ChannelInterface $channel, CustomerGroupInterface $group, CustomerInterface $customer, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, ProductVariantPriceCalculatorInterface $productVariantPriceCalculator)
 {
     $order->getCustomer()->willReturn($customer);
     $order->getChannel()->willReturn(null);
     $order->getItems()->willReturn([$item]);
     $order->getCurrencyCode()->willReturn(null);
     $customer->getGroup()->willReturn($group);
     $item->isImmutable()->willReturn(false);
     $item->getQuantity()->willReturn(5);
     $item->getVariant()->willReturn($variant);
     $order->getChannel()->willReturn($channel);
     $productVariantPriceCalculator->calculate($variant, ['channel' => $channel])->willReturn(10);
     $item->setUnitPrice(10)->shouldBeCalled();
     $this->process($order);
 }
コード例 #8
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);
 }
コード例 #9
0
 /**
  * {@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;
 }
コード例 #10
0
 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);
 }
コード例 #11
0
 function it_does_not_add_payment_during_processing_if_new_payment_already_exists(PaymentFactoryInterface $paymentFactory, PaymentInterface $newPaymentReadyToPay, PaymentInterface $cancelledPayment, PaymentInterface $payment, OrderInterface $order)
 {
     $order->getState()->willReturn(OrderInterface::STATE_NEW);
     $order->getTotal()->willReturn(1234);
     $order->getCurrencyCode()->willReturn('EUR');
     $order->getLastPayment(PaymentInterface::STATE_CANCELLED)->willReturn($cancelledPayment);
     $order->getLastPayment(PaymentInterface::STATE_FAILED)->willReturn(null);
     $order->getLastPayment(PaymentInterface::STATE_NEW)->willReturn($newPaymentReadyToPay);
     $paymentFactory->createWithAmountAndCurrencyCode(1234, 'EUR')->willReturn($payment);
     $payment->setMethod($cancelledPayment)->shouldNotBeCalled();
     $order->addPayment($payment)->shouldNotBeCalled();
     $this->processOrderPayments($order);
 }
コード例 #12
0
 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]);
 }