Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooking to Order::EVENT_AFTER_ORDER_PAID doesn't work #1026

Closed
Saboteur777 opened this issue Oct 3, 2019 · 7 comments
Closed

Hooking to Order::EVENT_AFTER_ORDER_PAID doesn't work #1026

Saboteur777 opened this issue Oct 3, 2019 · 7 comments
Labels

Comments

@Saboteur777
Copy link
Contributor

Description

Trying to listening to Order::EVENT_AFTER_ORDER_PAID events, but the code attached to this event never runs.

Steps to reproduce

  1. Example code:
<?php 

namespace webmenedzser\billingo;

use craft\commerce\elements\Order;

class Billingo extends Plugin
{
    public function init()
    {
        parent::init();
        self::$plugin = $this;

        $this->_registerTransactionEvents();
    }

    private function _registerTransactionEvents()
    {
        // This runs
        Event::on(
            Payments::class,
            Payments::EVENT_AFTER_CAPTURE_TRANSACTION,
            function(TransactionEvent $e) {
                // @var Order $order
                $order = $e->transaction->order;

                Craft::$app->queue->push(new CreateInvoice([
                    'order' => $order,
                ]));
            }
        );

        // This doesn't
        Event::on(
            Order::class,
            Order::EVENT_AFTER_ORDER_PAID,
            function(Event $e) {
                Craft::info(
                    'Order paid, event called',
                    __METHOD__
                );
            }
        );
    }
}
  1. Initiating a payment via the CP, and capturing it doesn't fires the Order::EVENT_AFTER_ORDER_PAID event.

It might be that I should listen to multiple events for different payment methods, but that seems counter-intuitive.

Additional info

@lukeholder
Copy link
Member

Does you order have a date paid after you refund them?

@Saboteur777
Copy link
Contributor Author

No, it doesn't have (at least it is not shown in the sidebar).
With a completely new Order the event happened and the "Order paid,..." text ended up in the logs, so my question is: why the Order::EVENT_AFTER_ORDER_PAID event is not happening after a refund + new payment combination?

@lukeholder
Copy link
Member

lukeholder commented Oct 3, 2019

It is because the datePaid isn't unset on refund, so the new paid event isn't triggered. Will need to fix for next release.

@lukeholder lukeholder added the bug label Oct 3, 2019
@Saboteur777
Copy link
Contributor Author

Thanks!

@lukeholder
Copy link
Member

lukeholder commented Oct 5, 2019

Fixed in e7f9569 will be in the next release.

@Saboteur777
Copy link
Contributor Author

Saboteur777 commented Oct 6, 2019 via email

@kevinmu17
Copy link

kevinmu17 commented Jan 29, 2020

Seems to be happening again in Commerce 3, I updated today and the event is not being called, neither is EVENT_AFTER_COMPLETE_ORDER

Other events like EVENT_AFTER_ADD_LINE_ITEM are working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants