laravel / cashier-mollie

MIT License
375 stars 63 forks source link

Testing webhooks locally #329

Closed MrMooky closed 3 years ago

MrMooky commented 3 years ago

I'm using expose to receive webhooks locally and it is working just fine in general.

For a new project, I use this package to create subscriptions, but I'm having a hard time getting started with the webhooks. Basically, they are not incoming.

In my config/cashier.php I set the following for the webhook_url:

'webhook_url' => (new GetWebhookUrlAction)->execute('webhooks/mollie'),

The action looks like this:

public function execute($routePath): string
    {
        if (config('app.env') === 'local' && env('WEBHOOK_BASEURL')) {
            $path = data_get(parse_url($routePath), 'path');

            return rtrim(env('WEBHOOK_BASEURL'), '/') . $path;
        }

        return $routePath;
    }

And in my env file, I set the expose url. The url is reachable from the outside.

Note: When just using webhooks/mollie in the config, Mollie complains that the webhook url is not reachable, thus the workaround for local development.

But when I want to create a subscription, I am directly to the Mollie Checkout, but when I am redirected back to my application, no webhook is incoming. Expose is running, as well as php artisan schedule:work. I am getting no errors or anything. Just the redirect from Mollie and then silence. No database records updated, nothing.

Just to be sure, Cashier should taking care of any incoming webhooks and there should be nothing for me to do to make this work, right? What could be the cause for this?

sandervanhooft commented 3 years ago

What happens if you use cashier's default webhook config?

MrMooky commented 3 years ago

Ah damn it, sorry! I just debugged $user->newSubscription($name, $user->plan_name)->create(); and noticed, that there was a / missing in the webhook url. Now it works just as expected.

sandervanhooft commented 3 years ago

No problem, enjoy!