2862339 - Add event listener to payments#791
2862339 - Add event listener to payments#791jackbravo wants to merge 10 commits intodrupalcommerce:8.x-2.xfrom
Conversation
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
haringsrob
left a comment
There was a problem hiding this comment.
Got a small comment that could improve code quality
heddn
left a comment
There was a problem hiding this comment.
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'
|
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. |
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.