laravel / cashier-mollie

MIT License
375 stars 63 forks source link

Question about events #330

Closed maxxi12356 closed 3 years ago

maxxi12356 commented 3 years ago

Hi

I keep trying to get the current user in events...

So I have this:

<?php

namespace App\Listeners;

use App\Mail\Cashier\FirstPaymentFailedMail;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;
use Laravel\Cashier\Events\FirstPaymentFailed;

class SendFirstPaymentFailedNotification implements ShouldQueue
{
    public function __construct(){}

    public function handle(FirstPaymentFailed $event)
    {
        Log::debug($event->owner);
    }
}

But I can't manage to get the user that performs the action so I can send an email. What am I doing wrong here? I'm searching for hours to get a solution and it's probably something stupid 😅

Thanks!

sandervanhooft commented 3 years ago

Try $event->payment->owner

sandervanhooft commented 3 years ago

See https://github.com/laravel/cashier-mollie/blob/develop/src/Events/FirstPaymentFailed.php

maxxi12356 commented 3 years ago

So I have edited to: $event->payment->owner->email

But it gives me: [2021-08-10 11:39:08] production.ERROR: Undefined property: Mollie\Api\Resources\Payment::$owner {"exception":"[object] (ErrorException(code: 0): Undefined property: Mollie\Api\Resources\Payment::$owner at /home/ploi/website.be/app/Listeners/SendFirstPaymentFailedNotification.php:18)

sandervanhooft commented 3 years ago

Ah I get it. We'll need to add the owner to the event then. Are you sure you need this? The user will get an onscreen failed confirmation from Mollie.

maxxi12356 commented 3 years ago

It is just to let the user known their payment has failed. Or are there other methods to do this?

sandervanhooft commented 3 years ago

No. Just asking because doing that via email is uncommon for the first payment