Created
March 23, 2024 10:50
-
-
Save karandatwani92/cbf83a72605f6994e9a9a0eed7ebb323 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Notifications; | |
use Illuminate\Bus\Queueable; | |
use Illuminate\Contracts\Queue\ShouldQueue; | |
use Illuminate\Notifications\Messages\MailMessage; | |
use Illuminate\Notifications\Notification; | |
use App\Models\Order; | |
use Illuminate\Notifications\Slack\BlockKit\Blocks\ContextBlock; | |
use Illuminate\Notifications\Slack\BlockKit\Blocks\SectionBlock; | |
use Illuminate\Notifications\Slack\BlockKit\Blocks\ActionsBlock; | |
use Illuminate\Notifications\Slack\BlockKit\Composites\ConfirmObject; | |
use Illuminate\Notifications\Slack\SlackMessage; | |
class OrderNotification extends Notification implements ShouldQueue | |
{ | |
use Queueable; | |
protected $order; | |
public function __construct(Order $order) | |
{ | |
$this->order = $order; | |
} | |
public function via($notifiable) | |
{ | |
return [SmsChannel::class, 'mail', 'slack']; | |
} | |
public function toMail($notifiable) | |
{ | |
$part = "successfully"; | |
$amount = currency_format($this->order->amount * $this->order->currency_rate, $this->order->customer_currency); | |
$order_id = $this->order->id; | |
$user = $notifiable?->name; | |
return (new MailMessage) | |
->success() | |
->subject("BulkMake™ Order Placed #OD$order_id") | |
->greeting("Hello! $user") | |
->line("Thank you for placing an order at BulkMake. You have $part paid **$amount** for your order **#OD$order_id**. Order updates will be shared with you soon.") | |
->action('View Order', url("account/orders/$order_id")) | |
->salutation('Thank you for your purchase!'); | |
} | |
public function toSms($notifiable) | |
{ | |
return (new OrderSms) | |
->order($this->order) | |
->to($notifiable->contact); | |
} | |
public function toSlack(): SlackMessage | |
{ | |
return (new SlackMessage) | |
->to("#orders") | |
->text('Check & update order status.') | |
->headerBlock('#' . $this->order->id . ' Order Received🎉') | |
->contextBlock(function (ContextBlock $block) { | |
$block->text('Check & update order status.'); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment