|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file has been created by developers from BitBag. |
|
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
|
6
|
|
|
* You can find more information about us on https://bitbag.io and write us |
|
7
|
|
|
* an email on [email protected]. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace BitBag\SyliusMolliePlugin\EmailSender; |
|
13
|
|
|
|
|
14
|
|
|
use BitBag\SyliusMolliePlugin\Entity\TemplateMollieEmailTranslationInterface; |
|
15
|
|
|
use BitBag\SyliusMolliePlugin\Mailer\Emails; |
|
16
|
|
|
use BitBag\SyliusMolliePlugin\Twig\Parser\ContentParserInterface; |
|
17
|
|
|
use Sylius\Component\Core\Model\CustomerInterface; |
|
18
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
|
19
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
|
20
|
|
|
use Sylius\Component\Mailer\Sender\SenderInterface; |
|
21
|
|
|
|
|
22
|
|
|
final class PaymentLinkEmailSender implements PaymentLinkEmailSenderInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var SenderInterface */ |
|
25
|
|
|
private $emailSender; |
|
26
|
|
|
|
|
27
|
|
|
/** @var ContentParserInterface */ |
|
28
|
|
|
private $contentParser; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct( |
|
31
|
|
|
SenderInterface $emailSender, |
|
32
|
|
|
ContentParserInterface $contentParser |
|
33
|
|
|
) { |
|
34
|
|
|
$this->emailSender = $emailSender; |
|
35
|
|
|
$this->contentParser = $contentParser; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function sendConfirmationEmail(OrderInterface $order, TemplateMollieEmailTranslationInterface $template): void |
|
39
|
|
|
{ |
|
40
|
|
|
/** @var PaymentInterface $payment */ |
|
41
|
|
|
$payment = $order->getPayments()->last(); |
|
42
|
|
|
|
|
43
|
|
|
if (empty($payment->getDetails())) { |
|
44
|
|
|
return; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$paymentLink = $payment->getDetails()['payment_mollie_link']; |
|
48
|
|
|
$content = $this->contentParser->parse($template->getContent(), $paymentLink); |
|
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
/** @var CustomerInterface $customer */ |
|
51
|
|
|
$customer = $order->getCustomer(); |
|
52
|
|
|
|
|
53
|
|
|
$this->emailSender->send(Emails::PAYMENT_LINK, [$customer->getEmail()], [ |
|
54
|
|
|
'order' => $order, |
|
55
|
|
|
'template' => $template, |
|
56
|
|
|
'content' => $content, |
|
57
|
|
|
]); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|