Skip to content

Commit

Permalink
Merge pull request #9394 from venyii/fix-payment-processor-remove
Browse files Browse the repository at this point in the history
Fix removal of cart payments in OrderPaymentProcessor
  • Loading branch information
pamil authored May 21, 2018
2 parents b1d6e53 + 538448d commit 66db890
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ public function process(BaseOrderInterface $order): void
}

if (0 === $order->getTotal()) {
foreach ($order->getPayments(OrderPaymentStates::STATE_CART) as $payment) {
$removablePayments = $order->getPayments()->filter(function (PaymentInterface $payment): bool {
return $payment->getState() === OrderPaymentStates::STATE_CART;
});

foreach ($removablePayments as $payment) {
$order->removePayment($payment);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace spec\Sylius\Component\Core\OrderProcessing;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Sylius\Component\Core\Model\OrderInterface;
Expand Down Expand Up @@ -46,13 +47,21 @@ function it_throws_exception_if_passed_order_is_not_core_order(BaseOrderInterfac

function it_removes_cart_payments_from_order_if_its_total_is_zero(
OrderInterface $order,
PaymentInterface $cartPayment
PaymentInterface $cartPayment,
PaymentInterface $cancelledPayment,
Collection $payments
): void {
$order->getState()->willReturn(OrderInterface::STATE_CART);
$order->getTotal()->willReturn(0);

$order->getPayments(OrderPaymentStates::STATE_CART)->willReturn(new ArrayCollection([$cartPayment->getWrappedObject()]));
$order->removePayment($cartPayment)->shouldBeCalled();
$cartPayment->getState()->willReturn(OrderPaymentStates::STATE_CART);
$cancelledPayment->getState()->willReturn(OrderPaymentStates::STATE_CANCELLED);

$payments->filter(Argument::type(\Closure::class))->willReturn([$cartPayment]);

$order->getPayments()->willReturn($payments);
$order->removePayment($cartPayment)->shouldBeCalledTimes(1);
$order->removePayment($cancelledPayment)->shouldNotBeCalled();

$this->process($order);
}
Expand Down

0 comments on commit 66db890

Please sign in to comment.