- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Create An Invoice For An Existing Credit Card order
I've had several credit card orders come in and they always create an invoice automagically like they are supposed to. However 1 credit card order did not create an invoice. I'm unable to figure out how to force the system to create an invoice for this product. It doesn't give you the "Invoice" button because it's a credit card order.
Does anyone know how to do this? Programmatically possibly? I'm using Magento 2.3.1.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Create An Invoice For An Existing Credit Card order
Hello @legacy_polo
Let me help you to create invoice from admin first :
- On the Admin sidebar, click Sales.
- In the Operations section, choose Orders.
- Find the sales order with the status of Processing in the grid. Then, do the following:
- In the Action column, click View.
- In the header of the sales order, choose the Invoice option.
Note : The Invoice option does not appear if the payment method is set to Authorize and Capture.
Now create invoice from code level :
- Start the settings with events.xml file in your custom module: /app/code/Vendor/Module/etc/events.xml
<?xml version="1.0"?> <event name="sales_order_invoice_pay"> <observer name="webpos_sales_order_invoice_pay" instance="Vendor\Module\Observer\SalesOrderInvoicePay" /> </event> </config>
- Setup the observer class
/app/code/Vendor/Module/Observer/SalesOrderInvoicePay.php<?php namespace Vendor\Module\Observer\Sales; use Magento\Framework\Event\Observer as EventObserver; use Magento\Framework\Event\ObserverInterface; 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()); } }
- Dispatch event (sales_order_invoice_pay) in file in your desired step.
// Code... $this->eventManager->dispatch('sales_order_invoice_pay'); // More code that sets $data... $this->eventManager->dispatch('sales_order_invoice_pay', ['Data' => $data]);

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Create An Invoice For An Existing Credit Card order
That is my problem:
The Invoice option does not appear if the payment method is set to Authorize and Capture.
The Invoice is from an "Authorize and Capture", so from the admin gui I can't create it. How do I tell the code you gave me that I want to generate an invoice for order_id 86 for example?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Create An Invoice For An Existing Credit Card order
In the above code it is fetching order from event, you can get order by fetching with id from repository.
check the answer here for help :

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Create An Invoice For An Existing Credit Card order
but event observer works when you add it with some functionality,
you can do this with console command as well where you can pass ID in console command which will not be dependent on other functionality
