lasthourcloud/app/Jobs/SubscriptionTrialEndsSoonJob.php

45 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2023-09-12 09:19:21 +00:00
<?php
namespace App\Jobs;
use App\Models\Team;
use Illuminate\Bus\Queueable;
2023-09-14 08:12:44 +00:00
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
2023-09-12 09:19:21 +00:00
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
2024-06-10 20:43:34 +00:00
class SubscriptionTrialEndsSoonJob implements ShouldBeEncrypted, ShouldQueue
2023-09-12 09:19:21 +00:00
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(
public Team $team
2024-06-19 06:59:46 +00:00
) {}
2023-09-12 09:19:21 +00:00
public function handle(): void
{
try {
$session = getStripeCustomerPortalSession($this->team);
2024-07-24 12:27:21 +00:00
$mail = new MailMessage;
2023-09-12 09:19:21 +00:00
$mail->subject('You trial in Coolify Cloud ends soon.');
$mail->view('emails.trial-ends-soon', [
'stripeCustomerPortal' => $session->url,
]);
$this->team->members()->each(function ($member) use ($mail) {
if ($member->isAdmin()) {
2024-06-10 20:43:34 +00:00
ray('Sending trial ending email to '.$member->email);
2023-09-12 09:19:21 +00:00
send_user_an_email($mail, $member->email);
2024-06-10 20:43:34 +00:00
send_internal_notification('Trial reminder email sent to '.$member->email);
2023-09-12 09:19:21 +00:00
}
});
} catch (\Throwable $e) {
2024-06-10 20:43:34 +00:00
send_internal_notification('SubscriptionTrialEndsSoonJob failed with: '.$e->getMessage());
2023-09-12 09:19:21 +00:00
ray($e->getMessage());
throw $e;
}
}
}