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
|
|
|
* another great project. |
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
8
|
|
|
* an email on [email protected]. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace BitBag\SyliusMolliePlugin\Creator; |
14
|
|
|
|
15
|
|
|
use BitBag\SyliusMolliePlugin\Entity\GatewayConfigInterface; |
16
|
|
|
use BitBag\SyliusMolliePlugin\Entity\OrderInterface; |
|
|
|
|
17
|
|
|
use BitBag\SyliusMolliePlugin\Entity\TemplateMollieEmailInterface; |
|
|
|
|
18
|
|
|
use BitBag\SyliusMolliePlugin\Factory\MollieGatewayFactory; |
19
|
|
|
use BitBag\SyliusMolliePlugin\Preparer\PaymentLinkEmailPreparerInterface; |
|
|
|
|
20
|
|
|
use BitBag\SyliusMolliePlugin\Repository\OrderRepositoryInterface; |
|
|
|
|
21
|
|
|
use BitBag\SyliusMolliePlugin\Resolver\PaymentlinkResolverInterface; |
|
|
|
|
22
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
23
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
24
|
|
|
|
25
|
|
|
final class AbandonedPaymentLinkCreator implements AbandonedPaymentLinkCreatorInterface |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
/** @var PaymentlinkResolverInterface */ |
28
|
|
|
private $paymentlinkResolver; |
29
|
|
|
|
30
|
|
|
/** @var OrderRepositoryInterface */ |
31
|
|
|
private $orderRepository; |
32
|
|
|
|
33
|
|
|
/** @var PaymentLinkEmailPreparerInterface */ |
34
|
|
|
private $emailPreparer; |
35
|
|
|
|
36
|
|
|
/** @var RepositoryInterface */ |
37
|
|
|
private $gatewayConfigRepository; |
38
|
|
|
|
39
|
|
|
public function __construct( |
40
|
|
|
PaymentlinkResolverInterface $paymentlinkResolver, |
41
|
|
|
OrderRepositoryInterface $orderRepository, |
42
|
|
|
PaymentLinkEmailPreparerInterface $emailPreparer, |
43
|
|
|
RepositoryInterface $gatewayConfigRepository |
44
|
|
|
) { |
45
|
|
|
$this->paymentlinkResolver = $paymentlinkResolver; |
46
|
|
|
$this->orderRepository = $orderRepository; |
47
|
|
|
$this->emailPreparer = $emailPreparer; |
48
|
|
|
$this->gatewayConfigRepository = $gatewayConfigRepository; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function create(): void |
52
|
|
|
{ |
53
|
|
|
/** @var GatewayConfigInterface $gateway */ |
54
|
|
|
$gateway = $this->gatewayConfigRepository->findOneBy(['factoryName' => MollieGatewayFactory::FACTORY_NAME]); |
55
|
|
|
|
56
|
|
|
if (null === $gateway) { |
57
|
|
|
return; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$abandonedEnabled = $gateway->getConfig()['abandoned_email_enabled'] ?? false; |
61
|
|
|
|
62
|
|
|
if (false === $abandonedEnabled) { |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$abandonedDuration = $gateway->getConfig()['abandoned_hours'] ?? 4; |
67
|
|
|
|
68
|
|
|
$dateTime = new \DateTime('now'); |
69
|
|
|
$duration = new \DateInterval(\sprintf('PT%sH', $abandonedDuration)); |
70
|
|
|
$dateTime->sub($duration); |
71
|
|
|
|
72
|
|
|
$orders = $this->orderRepository->findAbandonedByDateTime($dateTime); |
73
|
|
|
|
74
|
|
|
/** @var OrderInterface $order */ |
75
|
|
|
foreach ($orders as $order) { |
76
|
|
|
/** @var PaymentInterface $payment */ |
77
|
|
|
$payment = $order->getPayments()->first(); |
78
|
|
|
|
79
|
|
|
if ($payment->getMethod()->getGatewayConfig()->getFactoryName() === MollieGatewayFactory::FACTORY_NAME) { |
|
|
|
|
80
|
|
|
$this->paymentlinkResolver->resolve($order, [], TemplateMollieEmailInterface::PAYMENT_LINK_ABANDONED); |
81
|
|
|
$order->setAbandonedEmail(true); |
82
|
|
|
$this->orderRepository->add($order); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths