Magento 2.2 – How to Change Invoice Status in Database

authorize.netinvoicemagento2.2

We are getting problems with Authorize.net 'timing out' but then creating the order in Magento and then creating the transaction on Authorize.net.

To resolve, I have to go to Authorize.net and capture funds there. However, this leaves the invoice in Magento as unpaid.

Is there a place in the DB where I can change this status or is there some code to make the Authorize.net/Magento 2.2 connection more reliable? It doesn't happen often, but it happens enough to be annoying.

Best Answer

In DB you can change 'state' Column value to 2 in 'sales_invoice' table.

Gel all invoice state : vendor/magento/module-sales/Model/Order/Invoice.php

const STATE_OPEN = 1;

const STATE_PAID = 2;

const STATE_CANCELED = 3;

For changing the state by coding, looks this model : vendor/magento/module-sales/Model/InvoiceOrder.php

  $connection->beginTransaction();
        try {
            $order = $this->paymentAdapter->pay($order, $invoice, $capture);
            $order->setState(
                $this->orderStateResolver->getStateForOrder($order, [OrderStateResolverInterface::IN_PROGRESS])
            );
            $order->setStatus($this->config->getStateDefaultStatus($order->getState()));
            $invoice->setState(\Magento\Sales\Model\Order\Invoice::STATE_PAID);
            $this->invoiceRepository->save($invoice);
            $this->orderRepository->save($order);
            $connection->commit();
        } catch (\Exception $e) {
            $this->logger->critical($e);
            $connection->rollBack();
            throw new \Magento\Sales\Exception\CouldNotInvoiceException(
                __('Could not save an invoice, see error log for details')
            );
        }
Related Topic