1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ActionM\UnitPay; |
4
|
|
|
|
5
|
|
|
use ActionM\UnitPay\Events\UnitPayEvent; |
6
|
|
|
|
7
|
|
|
use Illuminate\Bus\Queueable; |
8
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
9
|
|
|
|
10
|
|
|
use Illuminate\Notifications\Messages\MailMessage; |
11
|
|
|
use Illuminate\Notifications\Messages\SlackMessage; |
12
|
|
|
use Illuminate\Notifications\Messages\SlackAttachment; |
13
|
|
|
use Illuminate\Notifications\Notification; |
14
|
|
|
|
15
|
|
|
class UnitPayNotification extends Notification implements ShouldQueue |
16
|
|
|
{ |
17
|
|
|
use Queueable; |
18
|
|
|
|
19
|
|
|
/** @var \ActionM\UnitPay\Events\UnitPayEvent * */ |
20
|
|
|
protected $event; |
21
|
|
|
|
22
|
|
|
public function via($notifiable) |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
return config('unitpay.channels'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function setEvent(UnitPayEvent $event) |
28
|
|
|
{ |
29
|
|
|
$this->event = $event; |
30
|
|
|
|
31
|
|
|
return $this; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function getEvent() |
35
|
|
|
{ |
36
|
|
|
return $this->event; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function toMail($notifiable) |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
return (new MailMessage) |
42
|
|
|
->error() |
43
|
|
|
->subject('UnitPay payment message from '.config('app.url')) |
44
|
|
|
->line($this->event->title) |
45
|
|
|
->line('IP: '.$this->event->ip) |
46
|
|
|
->line("Request details: {$this->event->details}"); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function toSlack() |
50
|
|
|
{ |
51
|
|
|
$slack_message = new SlackMessage(); |
52
|
|
|
$slack_message->level = $this->event->type; |
53
|
|
|
|
54
|
|
|
return $slack_message |
55
|
|
|
->content('UnitPay payment message from '.config('app.url')) |
56
|
|
|
->attachment(function (SlackAttachment $attachment) { |
57
|
|
|
$attachment->fields([ |
58
|
|
|
'Title' => $this->event->title, |
59
|
|
|
'IP' => $this->event->ip, |
60
|
|
|
'Request details' => $this->event->details, |
61
|
|
|
]); |
62
|
|
|
}); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.