-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Create cancel invoice method on API #12049
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Sales\Api; | ||
|
||
/** | ||
* Interface InvoiceCancelInterface | ||
* | ||
* @package Magento\Sales\Api | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
*/ | ||
interface InvoiceCancelInterface | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be a good idea to mark this with |
||
{ | ||
|
||
/** | ||
* Cancel invoice | ||
* | ||
* @param int $invoiceId | ||
* @return bool | ||
*/ | ||
public function cancel($invoiceId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this PR is targeting |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Sales\Model\Order; | ||
|
||
use Magento\Sales\Api\InvoiceCancelInterface; | ||
use Magento\Sales\Api\InvoiceRepositoryInterface; | ||
|
||
/** | ||
* Class InvoiceCancel | ||
*/ | ||
class InvoiceCancel implements InvoiceCancelInterface | ||
{ | ||
|
||
/** | ||
* @var InvoiceRepositoryInterface | ||
*/ | ||
protected $invoiceRepository; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please avoid creating |
||
|
||
/** | ||
* InvoiceCancel constructor. | ||
* @param InvoiceRepositoryInterface $invoiceRepository | ||
*/ | ||
public function __construct( | ||
InvoiceRepositoryInterface $invoiceRepository | ||
) { | ||
$this->invoiceRepository = $invoiceRepository; | ||
} | ||
|
||
/** | ||
* Cancel invoice | ||
* | ||
* @param int $invoiceId | ||
* @return bool | ||
*/ | ||
public function cancel($invoiceId) | ||
{ | ||
/** @var \Magento\Sales\Api\Data\InvoiceInterface $invoice */ | ||
$invoice = $this->invoiceRepository->get($invoiceId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method may throw an exception, which has to be either caught or declared in the interface. |
||
if ($invoice && $invoice->canCancel()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe there is no reason to check for |
||
$invoice->cancel(); | ||
$this->invoiceRepository->save($invoice); | ||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to return value of |
||
} | ||
|
||
return false; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide description for the interface in the doc block.
It may be some information regarding it's responsibility and reasons for introduction.