Skip to content

2862339 - Add event listener to payments #791

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

Closed
wants to merge 10 commits into from

Conversation

jackbravo
Copy link
Contributor

This is a reroll of PR 684 with some changes. I added the 'event' annotation to the Payment entity, so now all the events should work. There are tests right now for the create and load event and both pass (load event was not working). I also changed the getOrder method to getEntity, and added a test for that (as mentioned in comment #6. This issue is related to https://www.drupal.org/node/2856586 so I'm planning on adding the order_paid_in_full event too but maybe in another PR that depends on this one.

$payment = parent::doCreate($values);

// Notify other modules.
$event = new PaymentEvent($payment);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can move these 2 lines into a new private method: notifyOfPaymentCreation() (or suggest another name that fits better)

That way the comment is no longer needed and it will be easier to follow the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be. I'm also trying to tie this to issue 2856586-add-paid-in-full-event, which depends on 2804227-add-order-getBalance (PR 786).

PR 786 sets the payment balance on Payment::preSave() method, which gets the $storage interface as an argument, so if we can notify general events from the EntityStorageInterface we can solve that issue too. Right now, inside the Payment object, we don't have access to the eventDispatcher...

Copy link
Contributor

@haringsrob haringsrob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got a small comment that could improve code quality

Copy link

@heddn heddn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already events available from state_machine. See https://docs.drupalcommerce.org/commerce2/developer-guide/orders/react-to-workflow-transitions.

Do we need this at all?

Examples:
'commerce_payment.authorize_capture.post_transition'
'commerce_payment.receive.post_transition'
'commerce_payment.partially_refund.post_transition'

@jackbravo
Copy link
Contributor Author

jackbravo commented Sep 13, 2017

Hmmmm, this is indeed a very good question @heddn =p. I was planning on using this code as foundation to implement the 'order is paid in full' event (issue 2856586).

Maybe we can skip that and people should just subscribe to those events.

But then again, that event sounds really useful, but maybe we don't need to implement these CRUD events first, and we can just add the 'order paid in full' without all the others.

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

Successfully merging this pull request may close these issues.

3 participants