0

Im trying to do an offline payment where my customer wants to "payonbill". All works fine and i added this snippet:

 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <payment>
            <checkmo>
                <active>1</active>
                <model>Magento\OfflinePayments\Model\Checkmo</model>
                <order_status>processing</order_status>
                <title>Check / Money order</title>
                <allowspecific>0</allowspecific>
                <group>offline</group>
                <payment_action>authorize_capture</payment_action>
            </checkmo>
        </payment>
    </default>
</config>

The problem however exists where i have to connect some stuff once a payment is receive for certain products. I do this with an observer on sales_order_invoice_pay

Thing is that the event is thrown for the offline payment however the event is empty. What can i do to resolve that? Or is there a better way to approach this scenario? At this moment i am receiving the orderId in the observer and continue from there.

/**
 * Execute observer
 *
 * @param Observer $observer
 * @return void
 */
public function execute(
    Observer $observer
) {
    $invoice = $observer->getEvent()->getInvoice(); ## This is empty
    $order = $invoice->getOrder();
}

In above example is when the offline payment is done. With an online payment all works fine.

Best,

Pim

4
  • what's the problem with sales_order_invoice_pay ? Commented Oct 25, 2021 at 16:19
  • As mentioned in the topic, after the offline payment is placed the event is triggered however there is no payload in the event
    – Dirkos
    Commented Oct 25, 2021 at 19:30
  • what you mean by no payload?? you mean you want to get order's payment method? Commented Oct 26, 2021 at 3:58
  • The event does not hold an order nor invoice. The event is completely empty
    – Dirkos
    Commented Oct 26, 2021 at 9:24

2 Answers 2

0

Get the payment model from the order, then get the method instance from the payment:

    $invoice = $observer->getEvent()->getInvoice();
    $order = $invoice->getOrder();
    $payment = $order->getPayment();
    $method = $payment->getMethodInstance();
    $methodTitle = $method->getTitle();

Where $order is an instance of Magento\Sales\Model\Order.

1
  • This is not the problem. As mentioned when the observer is triggered there is no eventData. The getInvoice is empty
    – Dirkos
    Commented Oct 26, 2021 at 9:23
0

I fixed the issue by actually removing the stuff i previously did and by implementing this module:

https://github.com/dominicwatts/autoinvoice

The actual problem was that all was working fine but in the end for the offline payment the invoice is generated when booking it inside admin. Bypassing the status won't generate the invoice for you.

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.