Here are the steps to create an invoice without updating total paid of order in Magento 2:
- Step 1: Use event sales_order_invoice_pay
- Step 2: Write the observer class
In Magento, the total paid by Orders will be increased after created an invoice. That means every time you create a new invoice, Magento records that you received money from customers. However in the case of using partial payment, customers can make the payment many times for an Order. You don’t want that each time they make a payment, you must create a new invoice. So how can we create the invoice without updating the total paid of Order? Just follow a few easy steps below. If want to programmatically create an invoice for an order then the solution is here you can learn here how to create an invoice for an order or a part of your order.
Create an invoice in Magento 2
Step 1: Use event sales_order_invoice_pay
Declare observer in events.xml of your custom module: /app/code/[NameSpace]/[ModuleName]/etc/events.xml
<observer name="webpos_sales_order_invoice_pay" instance="[NameSapce]\[ModuleName]\Observer\SalesOrderInvoicePay" />
Step 2: Write the observer class
use Magento\Framework\Event\Observer as EventObserver;
class SalesOrderInvoicePay implements ObserverInterface
* @param EventObserver $observer
* @return $this
public function execute(EventObserver $observer)
$invoice = $observer->getEvent()->getInvoice();
$order = $invoice->getOrder();
/* reset total_paid & base_total_paid of order */
$order->setTotalPaid($order->getTotalPaid() - $invoice->getGrandTotal());
$order->setBaseTotalPaid($order->getBaseTotalPaid() - $invoice->getBaseGrandTotal());
We also contribute great content of Magento Tutorial for Magento 1.x.
DON'T MISS THE CHANCE!