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); }
/** * @param OrderInterface $order */ public function applyPaymentCharges(OrderInterface $order) { $order->removeAdjustments(AdjustmentInterface::PAYMENT_ADJUSTMENT); $order->calculateTotal(); foreach ($order->getPayments() as $payment) { $this->addAdjustmentIfForNotCancelled($order, $payment); } }
/** * {@inheritdoc} */ public function applyShippingCharges(OrderInterface $order) { // Remove all shipping adjustments, we recalculate everything from scratch. $order->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT); foreach ($order->getShipments() as $shipment) { $shippingCharge = $this->calculator->calculate($shipment); $adjustment = $this->adjustmentFactory->createNew(); $adjustment->setType(AdjustmentInterface::SHIPPING_ADJUSTMENT); $adjustment->setAmount($shippingCharge); $adjustment->setDescription($shipment->getMethod()->getName()); $order->addAdjustment($adjustment); } $order->calculateTotal(); }
function it_applies_calculated_shipping_charge_for_each_shipment_associated_with_the_order(FactoryInterface $adjustmentFactory, $calculator, AdjustmentInterface $adjustment, OrderInterface $order, ShipmentInterface $shipment, ShippingMethodInterface $shippingMethod) { $adjustmentFactory->createNew()->willReturn($adjustment); $order->getShipments()->willReturn(array($shipment)); $calculator->calculate($shipment)->willReturn(450); $shipment->getMethod()->willReturn($shippingMethod); $shippingMethod->getName()->willReturn('FedEx'); $adjustment->setAmount(450)->shouldBeCalled(); $adjustment->setType(AdjustmentInterface::SHIPPING_ADJUSTMENT)->shouldBeCalled(); $adjustment->setDescription('FedEx')->shouldBeCalled(); $order->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->shouldBeCalled(); $order->addAdjustment($adjustment)->shouldBeCalled(); $order->calculateTotal()->shouldBeCalled(); $this->applyShippingCharges($order); }