/**
  * @param OrderInterface   $order
  * @param PaymentSubjectInterface $payment
  */
 private function addAdjustmentIfForNotCancelled(OrderInterface $order, PaymentSubjectInterface $payment)
 {
     if (PaymentInterface::STATE_CANCELLED !== $payment->getState())
     {
         $order->addAdjustment($this->prepareAdjustmentForOrder($payment));
     }
 }
    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);
    }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function calculate(PaymentSubjectInterface $payment)
 {
     if (null === $payment->getMethod()) {
         throw new \InvalidArgumentException("Cannot calculate fee for payment without payment method configured.");
     }
     /** @var FeeCalculatorInterface $feeCalculator */
     $feeCalculator = $this->serviceRegistry->get($payment->getMethod()->getFeeCalculator());
     return $feeCalculator->calculate($payment, $payment->getMethod()->getFeeCalculatorConfiguration());
 }
 function it_throws_exception_if_passed_payment_has_no_payment_method_defined(PaymentSubjectInterface $payment)
 {
     $payment->getMethod()->willReturn(null);
     $this->shouldThrow(new \InvalidArgumentException("Cannot calculate fee for payment without payment method configured."))->during("calculate", array($payment));
 }
 function it_calculates_fee_for_given_payment_with_given_configuration(PaymentSubjectInterface $payment)
 {
     $payment->getAmount()->willReturn(1000);
     $this->calculate($payment, array('percent' => 20))->shouldReturn(200);
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function calculate(PaymentSubjectInterface $payment, array $configuration)
 {
     return (int) round($configuration['percent'] / 100 * $payment->getAmount());
 }