Magento2 – Plugin/Event After Invoice is Created

event-observerinvoicemagento-2.1magento2plugin

I need to execute some custom code after invoice is created

I have some code working fine, when invoices are created in admin storeview (I am observing sales_order_save_before event & checking for a state change to detect if the invoice has been created), but this does not work when 3rd party payment methods create the invoice during frontend checkout process

I am not sure if I can achieve this with observer / event approach, or maybe a plugin should be the right method. Any tips?

Best Answer

I finally solved this using sales_order_invoice_pay event, which is fired both in admin & frontend scopes