Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ralphmorris's avatar

Stripe Webhook pushing email onto queue. Failed jobs not adding to failed_jobs table

I wonder if anyone has experienced this before?

I'm using Laravel Cashier with Stripe, hosted on Digital Ocean with Forge and have a webhook set up for invoice.payment.failed which sends then an email to the user. The email is put onto a queue to send with the payload.

I have the failed_jobs table set up and works with other forms that send mail on the site if I force the job to fail but if the failed payment email job fails it doesn't add it to the failed_jobs table.

I've been forcing it to fail by putting a random variable in the view and can see the error in the logs but not in the failed_jobs table. Why does the failed job work for other forms but not this webhook?

Some of my code if helpful.

   public function handleInvoicePaymentFailed($payload)
    {
        $user = $this->getUserByStripeId($payload['data']['object']['customer']);

        if ($user) {

            $this->mailer->failedPayment($user, $payload);

        }

        return new Response('Invoice Payment Failed Webhook Handled', 200);
    }

    public function failedPayment(User $user, $payload)
    {
        $view = "emails.artist.failedPayment";
        $subject = "Failed to take membership payment";
        $data = [
            'user' => $user,
            'payload' => $payload,
        ];

        return $this->sendTo($user, $subject, $view, $data);
    }

    public function sendTo($user, $subject, $view, $data = [], $replyTo = null)
    {
        Mail::queue($view, $data, function ($message) use($user, $subject, $replyTo)
        {
            $message->to($user->email, $user->first_name)
                    ->subject($subject);
            
                if (!is_null($replyTo)) {

                    $message->replyTo($replyTo->email, $replyTo->first_name . ' ' . $replyTo->last_name);

                }

        });
    }

Any ideas appreciated.

Thanks

Ralph

0 likes
1 reply

Please or to participate in this conversation.