-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathResendDriver.php
More file actions
128 lines (108 loc) · 4.02 KB
/
Copy pathResendDriver.php
File metadata and controls
128 lines (108 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
namespace Vormkracht10\Mails\Drivers;
use Illuminate\Mail\Events\MessageSending;
use Vormkracht10\Mails\Contracts\MailDriverContract;
use Vormkracht10\Mails\Enums\EventType;
use Vormkracht10\Mails\Exceptions\LaravelResendException;
use Vormkracht10\Mails\Models\Mail;
class ResendDriver extends MailDriver implements MailDriverContract
{
protected array $trackingConfig;
public function __construct()
{
parent::__construct();
$this->trackingConfig = (array) config('mails.logging.tracking');
}
/**
* This method only checks that the Laravel Resend package is installed
* and configured as this package sets up webhook functionality
*/
public function registerWebhooks($components): void
{
/**
* Configuration for webhooks are only available in dashboard
*/
if (! class_exists('Resend\Laravel\ResendServiceProvider')) {
throw new LaravelResendException('Unable to find Laravel Resend Package');
}
if (empty(config('resend.webhook.secret'))) {
throw new LaravelResendException('Invalid Resend webhook secret');
}
}
public function verifyWebhookSignature(array $payload): bool
{
/**
* Using webhook created by laravel resend package.
*/
return false;
}
public function attachUuidToMail(MessageSending $event, string $uuid): MessageSending
{
$event->message->getHeaders()->addTextHeader('X-Resend-Variables', json_encode([config('mails.headers.uuid') => $uuid]));
return $event;
}
public function getUuidFromPayload(array $payload): ?string
{
return $payload['data']['email_id'];
}
protected function getTimestampFromPayload(array $payload): string
{
return $payload['data']['created_at'] ?? now();
}
public function eventMapping(): array
{
return [
EventType::ACCEPTED->value => ['type' => 'email.sent'],
EventType::CLICKED->value => ['type' => 'email.clicked'],
EventType::COMPLAINED->value => ['type' => 'email.complained'],
EventType::DELIVERED->value => ['type' => 'email.delivered'],
EventType::HARD_BOUNCED->value => ['type' => 'email.bounced'],
EventType::OPENED->value => ['type' => 'email.opened'],
EventType::SOFT_BOUNCED->value => ['type' => 'email.delivery_delayed'],
];
}
public function dataMapping(): array
{
return [
'ip_address' => 'data.click.ipAddress',
'link' => 'data.click.link',
'user_agent' => 'data.click.userAgent',
];
}
public function clicked(Mail $mail, string $timestamp): void
{
if (! empty($this->trackingConfig['clicks']) && $this->trackingConfig['clicks']) {
parent::clicked($mail, $timestamp);
}
}
public function complained(Mail $mail, string $timestamp): void
{
if (! empty($this->trackingConfig['complaints']) && $this->trackingConfig['complaints']) {
parent::complained($mail, $timestamp);
}
}
public function delivered(Mail $mail, string $timestamp): void
{
if (! empty($this->trackingConfig['deliveries']) && $this->trackingConfig['deliveries']) {
parent::delivered($mail, $timestamp);
}
}
public function hardBounced(Mail $mail, string $timestamp): void
{
if (! empty($this->trackingConfig['bounces']) && $this->trackingConfig['bounces']) {
parent::hardBounced($mail, $timestamp);
}
}
public function softBounced(Mail $mail, string $timestamp): void
{
if (! empty($this->trackingConfig['bounces']) && $this->trackingConfig['bounces']) {
parent::softBounced($mail, $timestamp);
}
}
public function opened(Mail $mail, string $timestamp): void
{
if (! empty($this->trackingConfig['opened']) && $this->trackingConfig['opened']) {
parent::softBounced($mail, $timestamp);
}
}
}