1
1
<?php
2
2
3
+ namespace App \MessageHandler \Event ;
3
4
4
- namespace App \MessageHandler ;
5
-
5
+ use App \Message \Event \OrderSavedEvent ;
6
6
use Mpdf \Mpdf ;
7
- use Symfony \ Component \ Mime \ Email ;
7
+ use Mpdf \ Output \ Destination ;
8
8
use Symfony \Component \Mailer \MailerInterface ;
9
- use App \Message \PurchaseConfirmationNotification ;
10
- use Symfony \Component \Messenger \Attribute \AsMessageHandler ;
11
9
use Symfony \Component \Messenger \Handler \MessageHandlerInterface ;
10
+ use Symfony \Component \Mime \Email ;
12
11
13
-
14
- class PurchaseConfirmationNotificationHandler implements MessageHandlerInterface
12
+ class OrderSavedEventHandler implements MessageHandlerInterface
15
13
{
16
14
public function __construct (private MailerInterface $ mailer )
17
15
{
18
16
}
19
17
20
- public function __invoke (PurchaseConfirmationNotification $ notification )
18
+ public function __invoke (OrderSavedEvent $ event )
21
19
{
22
20
// 1. Create a PDF contract note
23
21
$ mpdf = new Mpdf ();
24
- $ content = "<h1>Contract Note For Order {$ notification ->getOrderId ()}</h1> " ;
22
+ $ content = "<h1>Contract Note For Order {$ event ->getOrderId ()}</h1> " ;
25
23
$ content .= '<p>Total: <b>$1898.75</b></p> ' ;
26
24
27
25
$ mpdf ->writeHtml ($ content );
28
- $ contractNotePdf = $ mpdf ->output ('' , ' S ' );
26
+ $ contractNotePdf = $ mpdf ->output ('' , Destination:: STRING_RETURN );
29
27
30
28
// 2. Email the contract note to the buyer
31
29
32
30
$ email = (new Email ())
33
31
34
32
35
- ->subject ('Contract note for order ' . $ notification ->getOrderId ())
33
+ ->subject ('Contract note for order ' . $ event ->getOrderId ())
36
34
->text ('Here is your contract note ' )
37
35
->attach ($ contractNotePdf , 'contract-note.pdf ' );
38
36
39
37
$ this ->mailer ->send ($ email );
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
38
}
50
39
}
0 commit comments