Currently Magento2 sets the order status to the default status of the state STATE_PROCESSING when a credit card payment is captured. This is done in vendor/magento/module-sales/Model/Order/Payment/State/CaptureCommand.php in the excute function.

I am trying to make after payment capture status as "processing_invoiced" so the history item in the order saying it has capture uses the processing_invoiced status instead of resetting to the default.

I have it working with an aroundExecute:


namespace Vendor\Module\Plugin;

use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\Data\OrderPaymentInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Payment\State\CommandInterface as BaseCommandInterface;

class InvoicedOrderStatus
     * Set pending order status on order place
     * see https://github.com/magento/magento2/issues/5860
     * @todo Refactor this when another option becomes available
     * @param BaseCommandInterface $subject
     * @param \Closure $proceed
     * @param OrderPaymentInterface $payment
     * @param $amount
     * @param OrderInterface $order
     * @return mixed
    public function aroundExecute(
        BaseCommandInterface $subject,
        \Closure $proceed,
        OrderPaymentInterface $payment,
        OrderInterface $order)

      $result = $proceed($payment, $amount, $order);

        if($order->getState() == Order::STATE_PROCESSING) {
                $state = Order::STATE_PROCESSING;
                $status = 'processing_invoiced';


        return $result;

But can't get it working with afterExecute. How can I rewrite this to be afterExcute as Magento cautions against around functions when it's not needed?

1 Answer 1


Try this one

public function afterExecute(
    \Magento\Sales\Model\Order\Payment\State\CaptureCommand $subject,

  //your code is here
   return $result;

There, the $result parameter is the returned value of the Execute function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.