Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added checks to see if the payment is available #15683

Merged
merged 1 commit into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
/** @var \Magento\Sales\Model\Order $order */
$order = $observer->getEvent()->getOrder();

if ($order->getPayment()->getMethodInstance()->getCode() != 'free') {
if ($order->getPayment() && $order->getPayment()->getMethodInstance()->getCode() != 'free') {
return $this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testSalesOrderBeforeSaveCantUnhold()
$paymentMock = $this->getMockBuilder(
\Magento\Sales\Model\Order\Payment::class
)->disableOriginalConstructor()->setMethods([])->getMock();
$order->expects($this->once())->method('getPayment')->will($this->returnValue($paymentMock));
$order->method('getPayment')->will($this->returnValue($paymentMock));
$methodInstance = $this->getMockBuilder(
\Magento\Payment\Model\MethodInterface::class
)->getMockForAbstractClass();
Expand All @@ -86,7 +86,7 @@ public function testSalesOrderBeforeSaveIsCanceled()
$paymentMock = $this->getMockBuilder(
\Magento\Sales\Model\Order\Payment::class
)->disableOriginalConstructor()->setMethods([])->getMock();
$order->expects($this->once())->method('getPayment')->will($this->returnValue($paymentMock));
$order->method('getPayment')->will($this->returnValue($paymentMock));
$methodInstance = $this->getMockBuilder(
\Magento\Payment\Model\MethodInterface::class
)->getMockForAbstractClass();
Expand Down Expand Up @@ -114,7 +114,7 @@ public function testSalesOrderBeforeSaveIsClosed()
$paymentMock = $this->getMockBuilder(
\Magento\Sales\Model\Order\Payment::class
)->disableOriginalConstructor()->setMethods([])->getMock();
$order->expects($this->once())->method('getPayment')->will($this->returnValue($paymentMock));
$order->method('getPayment')->will($this->returnValue($paymentMock));
$methodInstance = $this->getMockBuilder(
\Magento\Payment\Model\MethodInterface::class
)->getMockForAbstractClass();
Expand Down Expand Up @@ -156,6 +156,26 @@ public function testSalesOrderBeforeSaveSetForced()
$this->salesOrderBeforeSaveObserver->execute($this->observerMock);
}

/**
* The method should check that the payment is available, as this is not always the case.
*/
public function testDoesNothingWhenNoPaymentIsAvailable()
{
$this->_prepareEventMockWithMethods(['getOrder']);

$order = $this->getMockBuilder(\Magento\Sales\Model\Order::class)->disableOriginalConstructor()->setMethods(
array_merge(['__wakeup', 'getPayment'])
)->getMock();

$this->eventMock->expects($this->once())->method('getOrder')->will(
$this->returnValue($order)
);

$order->expects($this->exactly(1))->method('getPayment')->willReturn(null);

$this->salesOrderBeforeSaveObserver->execute($this->observerMock);
}

/**
* Prepares EventMock with set of methods
*
Expand Down Expand Up @@ -184,7 +204,7 @@ private function _getPreparedOrderMethod($methodCode, $orderMethods = [])
$paymentMock = $this->getMockBuilder(
\Magento\Sales\Model\Order\Payment::class
)->disableOriginalConstructor()->setMethods([])->getMock();
$order->expects($this->once())->method('getPayment')->will($this->returnValue($paymentMock));
$order->method('getPayment')->will($this->returnValue($paymentMock));
$methodInstance = $this->getMockBuilder(
\Magento\Payment\Model\MethodInterface::class
)->getMockForAbstractClass();
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/Paypal/Plugin/OrderCanInvoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public function __construct(Express $express)
*/
public function afterCanInvoice(Order $order, $result): bool
{
if (!$order->getPayment()) {
return false;
}

if ($this->express->isOrderAuthorizationAllowed($order->getPayment())) {
return false;
}
Expand Down