laravel/cashier-mollie

Help wanted: Webhook Event Handlers

Closed this issue · 5 comments

After visiting the Mollie payment screen and selecting either: Open, Paid, Failed, Cancelled or Expired, in all cases I get redirected to the home page.

Now I want to get the result of each payment for propper redirects, notifications, etc.

I edited my EventServiceProvider like this:

<?php

namespace App\Providers;

use Laravel\Cashier\Events\OrderPaymentPaid;
use Laravel\Cashier\Events\OrderPaymentFailed;
use Laravel\Cashier\Events\FirstPaymentPaid;
use Laravel\Cashier\Events\FirstPaymentFailed;
use Laravel\Cashier\Events\OrderInvoiceAvailable;

use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
        Registered::class => [
            SendEmailVerificationNotification::class,
        ],
    ];

    /**
     * Register any events for your application.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Determine if events and listeners should be automatically discovered.
     *
     * @return bool
     */
    public function shouldDiscoverEvents()
    {
        return true;
    }
}

And created the listener files. event:list gives me:

+-----------------------------------+-------------------------------------------------------------+
| Event                             | Listeners                                                   |
+-----------------------------------+-------------------------------------------------------------+
| App\Events\FirstPaymentFailed     | App\Listeners\OnFirstPaymentFailed@handle                   |
| App\Events\FirstPaymentPaid       | App\Listeners\OnFirstPaymentPaid@handle                     |
| App\Events\OrderInvoiceAvailable  | App\Listeners\OnOrderInvoiceAvailable@handle                |
| App\Events\OrderPaymentFailed     | App\Listeners\OnOrderPaymentFailed@handle                   |
| App\Events\OrderPaymentPaid       | App\Listeners\OnOrderPaymentPaid@handle                     |
| Illuminate\Auth\Events\Registered | Illuminate\Auth\Listeners\SendEmailVerificationNotification |
+-----------------------------------+-------------------------------------------------------------+

In the handle() method of each listener I added:

var_dump($event)

But after visiting Mollie and selecting a payment result, none of my listeners triggered. I get the same redirect to my index page without any flash message.

Any idea's how to get this working?

This package listens to the webhook called by Mollie. If you are running your project locally, Mollie can't call your application's webhook endpoint.

You can check in the Mollie dashboard which webhook-URL it is calling, and also (on the right side of the screen), you see the events (for example, the reason why webhook failed).

Therefore you need to use a service like expose (https://beyondco.de/docs/expose/introduction).

See #136 (comment)

This package listens to the webhook called by Mollie. If you are running your project locally, Mollie can't call your application's webhook endpoint.

You can check in the Mollie dashboard which webhook-URL it is calling, and also (on the right side of the screen), you see the events (for example, the reason why webhook failed).

Therefore you need to use a service like expose (https://beyondco.de/docs/expose/introduction).

See #136 (comment)

Hi @robindirksen1, I do use expose :-)

After selecting payment failed I get redirected to my index page without listeners being triggered.

In my Mollie dashboard I see:

Redirect URL https://xxxxxxxxxx.sharedwithexpose.com

and:

Webhook URL https://xxxxxxxxxx.sharedwithexpose.com/webhooks/mollie/first-payment

So, there is a connection between Mollie and my application. When selecting paid it also does update my database and gives the propper status in Mollie.

In cashier.php I've set:

'webhook_url' => 'https://xxxxxxxxxx.sharedwithexpose.com/webhooks/mollie',

'webhook_url' => 'https://xxxxxxxxxx.sharedwithexpose.com/webhooks/mollie/first-payment',

'redirect_url' => 'https://xxxxxxxxxx.sharedwithexpose.com',

Aha, so. Sorry, misunderstand it.

image

Any idea where this event namespace is coming from? It should be Laravel\Cashier\Events.

That probably explains why the listeners do not get triggered, they are listening for the wrong class.

Closing this for now, let me know if it needs to be reopened.