Skip to content

Commit

Permalink
feat: Add SubscriptionUpdatedNotification for subs
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Mar 11, 2024
1 parent bda6df5 commit 458c6e0
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions app/Notifications/SubscriptionUpdatedNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class SubscriptionUpdatedNotification extends Notification implements ShouldQueue
{
use Queueable;

protected $subscriptionDetails;

public function __construct(array $subscriptionDetails)
{
$this->subscriptionDetails = $subscriptionDetails;
}

public function via($notifiable)
{
return ['mail'];
}

public function toMail($notifiable)
{
$mailMessage = (new MailMessage)
->subject('Subscription Update')
->greeting('Hello!');

if ($this->subscriptionDetails['type'] === 'plan_change') {
$mailMessage->line('Your subscription plan has been successfully updated.')
->line('Old Plan: ' . $this->subscriptionDetails['old_plan'])
->line('New Plan: ' . $this->subscriptionDetails['new_plan'])
->line('Effective Date: ' . $this->subscriptionDetails['effective_date']);
} elseif ($this->subscriptionDetails['type'] === 'cancellation') {
$mailMessage->line('Your subscription has been cancelled.')
->line('Cancellation Date: ' . $this->subscriptionDetails['cancellation_date'])
->line('Your subscription will not renew.');
}

$mailMessage->action('View Subscription', url('/subscription'))
->line('Thank you for using our application!');

return $mailMessage;
}

public function toArray($notifiable)
{
return [
'subscription_details' => $this->subscriptionDetails,
];
}
}

0 comments on commit 458c6e0

Please sign in to comment.