|
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\Factory; |
|
13
|
|
|
|
|
14
|
|
|
use BitBag\SyliusMolliePlugin\Entity\MollieGatewayConfigInterface; |
|
15
|
|
|
use BitBag\SyliusMolliePlugin\Payments\Methods\MethodInterface; |
|
16
|
|
|
use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface; |
|
17
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
|
18
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
|
19
|
|
|
|
|
20
|
|
|
final class MollieGatewayConfigFactory implements MollieGatewayConfigFactoryInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var FactoryInterface */ |
|
23
|
|
|
private $mollieGatewayConfigFactory; |
|
24
|
|
|
|
|
25
|
|
|
/** @var RepositoryInterface */ |
|
26
|
|
|
private $repository; |
|
27
|
|
|
|
|
28
|
|
|
public function __construct(FactoryInterface $mollieGatewayConfigFactory, RepositoryInterface $repository) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->mollieGatewayConfigFactory = $mollieGatewayConfigFactory; |
|
31
|
|
|
$this->repository = $repository; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
private function createNewOrUpdate(MethodInterface $method, GatewayConfigInterface $gateway): MollieGatewayConfigInterface |
|
35
|
|
|
{ |
|
36
|
|
|
$methodExist = $this->repository->findOneBy([ |
|
37
|
|
|
'methodId' => $method->getMethodId(), |
|
|
|
|
|
|
38
|
|
|
'gateway' => $gateway, |
|
39
|
|
|
]); |
|
40
|
|
|
|
|
41
|
|
|
return null !== $methodExist ? $methodExist : $this->mollieGatewayConfigFactory->createNew(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function create( |
|
45
|
|
|
MethodInterface $method, |
|
46
|
|
|
GatewayConfigInterface $gateway, |
|
47
|
|
|
int $key |
|
48
|
|
|
): MollieGatewayConfigInterface { |
|
49
|
|
|
$mollieGatewayConfig = $this->createNewOrUpdate($method, $gateway); |
|
50
|
|
|
|
|
51
|
|
|
$mollieGatewayConfig->setMethodId($method->getMethodId()); |
|
52
|
|
|
$mollieGatewayConfig->setName($method->getName()); |
|
53
|
|
|
$mollieGatewayConfig->setMinimumAmount($method->getMinimumAmount()); |
|
54
|
|
|
$mollieGatewayConfig->setMaximumAmount($method->getMinimumAmount()); |
|
55
|
|
|
$mollieGatewayConfig->setImage($method->getImage()); |
|
56
|
|
|
$mollieGatewayConfig->setGateway($gateway); |
|
57
|
|
|
$mollieGatewayConfig->setIssuers($method->getIssuers()); |
|
58
|
|
|
$mollieGatewayConfig->setPaymentType($method->getPaymentType()); |
|
59
|
|
|
$mollieGatewayConfig->setApplePayDirectButton(false); |
|
60
|
|
|
$mollieGatewayConfig->setPosition($key); |
|
61
|
|
|
|
|
62
|
|
|
return $mollieGatewayConfig; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|