Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kferran's avatar

Command Bus doing too much

I am in the middle of building an ecommerce site and have been implementing the command bus process. I am curious how you guys might handle the situation when creating an order.

My current process is this: 1. Post to order controller 2. Fire up command bus passing in all form data from checkout process 3. In the command handler (this is where I am curious), I am sending a request to my stripe service for the payment, then sending a request to my order repository to store the order header than a request to my orderItem repository for each item in the cart.

I am wondering if/how I might be able to break this process up a little instead of doing all of this in one handler.

Everything works as is, I'm just looking for some insight from everybody.

Thanks in advance!

0 likes
3 replies
SP1966's avatar

This is where the listeners come in. You have to broadcast the new order, then the event listener will pick that up and you could then have one event that handles Stripe, one that saves the order, on that emails a confirmation and so on. Watch the Commands and Domain Events series a few time and you'll pick it up!

kferran's avatar

Thanks for the feedback, I really appreciate it. Here is another part of my handler that I forget to mention. In my handler I am running the various repository entries in a database transaction closure. This way I don't have orders created if a payment fails or if an order entry fails I don't have order details without an order.

Any suggestions on how to divide this up through different events and services?

Thanks again for the input!

SP1966's avatar

I would handle both the Stripe authorization and the database entry of the related records in the CommandHandler as both are 100% required to succeed before you truly have an order. After that is done then you could raise an event for things such as confirmation emails.

1 like

Please or to participate in this conversation.