laravel/cashier-mollie

Bug: route:cache breaks routing and controller fetch

RosiersRobin opened this issue · 3 comments

Hi,

I'm trying to use this awesome package, but when I deploy my code to my live server (and run php artisan route:cache), I get an 500 with the following exception;

[2020-11-13 13:32:18] production.ERROR: Target class [App\Http\Controllers\Laravel\Cashier\Http\Controllers\WebhookController] does not exist. {"exception":"[object] (Illuminate\\Contracts\\Container\\BindingResolutionException(code: 0): Target class [App\\Http\\Controllers\\Laravel\\Cashier\\Http\\Controllers\\WebhookController] does not exist.

Which makes sence, since that doesn't exist indeed, BUT I don't reffer to that anywhere?

I have the following set up in my routing;

Route::post(Cashier::webhookUrl(), WebhookController::class . '@handleWebhook');
Route::post(Cashier::firstPaymentWebhookUrl(), FirstPaymentWebhookController::class . '@handleWebhook');

Where the Controller classess are an exact copy of those in the vendor (I tried those in the vendor, exact same exception).

The route:list gives me the following outcome;

App\Domains\Common\Controllers\Payments\WebhookController@handleWebhook
App\Domains\Common\Controllers\Payments\FirstPaymentWebhookController@handleWebhook

So these are the urls webhooks/mollie and webhooks/mollie/first-payment.

They are correct in here. When I look in the cached routes file, the reference is also correct. I do wonder why this is referencing to something completely different. I don't use the default laravel structure, but I use a Domain Driven Design instead. When I don't cache the route, it should work, but I haven't tested it enough. When I don't cache the route, then the code works just fine. So there is some sort of issue with the caching?!

Hi @RosiersRobin ,

Can you try switching these lines in your local package installation, so the config is merged before the routes are loaded? I think this is causing this bug, would be really helpful if you could confirm this.

if (Cashier::$registersRoutes) {
$this->loadRoutesFrom(__DIR__.'/../routes/webhooks.php');
}
$this->mergeConfig();

Hi @sandervanhooft

Sorry for the late reply, didn't find any time to check this. But that did the trick! I've made a Pull Request, with the lines swapped :)

Don't know if that is allowed tho!

Thanks @RosiersRobin !

Your PR has been included in the latest release, v1.14.1. Enjoy!