I have two services: An OrderService which has handy methods for working with orders. And i have a TransactionService which has handy methods for working with payment transactions.
I want to update an orders status when a transaction has been paid. But i am not sure where to do this. It is, i think, neither the responsibility of the two services.
I can do something like this:
$this->orderService->updateOrderStatusUsingTransaction($order, $event->transaction);
But then i am making the orderService also responsible for updating the Transaction. While i only want it to be responsible for orders.
$this->transactionService->updateOrderStatusUsingTransaction($order, $event->transaction);
But then i am making the transactionService also responsible for updating the Transaction. While i only want that to be responsible for transactions.
/**
* Handle the event.
*
* @param TransactionChanged $event
* @return void
*/
public function handle(TransactionChanged $event) {
/** @var Order $order */
$order = $event->transaction->order()->first();
/** @var User $customer */
$customer = $order->customer()->first();
$this->orderService->updateOrderStatusUsingTransaction($order, $event->transaction);
$this->orderMailService->mailCustomerAboutCurrentOrderStatus($order, $customer);
}
I suspect i need an additional layer outside of these services to help me solve the problem. What would be some best practises?
Aucun commentaire:
Enregistrer un commentaire