Hi,
The system receives payments from third-party services.
I add a middleware for those requests.
Route::group(['prefix' => 'payments', 'middleware' => 'payment'], function () {
Route::post('/service1', 'PaymentController@storeService1');
Route::post('/service2', function(){ }); //handles the whole process in the middleware
});
What makes sense (at least for me) to handle the payment in the middleware (determine the Payment Provider, check if the request comes from a whitelist service-provider IP or if the data structure is okay, etc.)
Here is the part which feels wrong
After the middleware determines the PaymentService it creates a ProcessorClass for it ( like XPaymentProcessor, YPaymentProcessor) which implements IPaymentProvider (with handlePayment, sendResult). After that, it triggers the handlePayment function with request content.
From there I want to emit an Event to further ServiceProviders.
But somehow it feels terribly wrong to handle the whole process in the middleware.
Shall I just validate the request and give the information to my Controller or what would be a good solution for my problem?