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\Resolver; |
13
|
|
|
|
14
|
|
|
use BitBag\SyliusMolliePlugin\Creator\ApiKeysTestCreatorInterface; |
15
|
|
|
use BitBag\SyliusMolliePlugin\Entity\GatewayConfigInterface; |
16
|
|
|
use BitBag\SyliusMolliePlugin\Factory\MollieGatewayFactory; |
17
|
|
|
use BitBag\SyliusMolliePlugin\Form\Type\MollieGatewayConfigurationType; |
18
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
19
|
|
|
use Symfony\Component\HttpFoundation\Request; |
20
|
|
|
|
21
|
|
|
final class ApiKeysTestResolver implements ApiKeysTestResolverInterface |
22
|
|
|
{ |
23
|
|
|
/** @var RepositoryInterface */ |
24
|
|
|
private $gatewayConfigRepository; |
25
|
|
|
|
26
|
|
|
/** @var ApiKeysTestCreatorInterface */ |
27
|
|
|
private $apiKeysTestCreator; |
28
|
|
|
|
29
|
|
|
public function __construct( |
30
|
|
|
RepositoryInterface $gatewayConfigRepository, |
31
|
|
|
ApiKeysTestCreatorInterface $apiKeysTestCreator |
32
|
|
|
) { |
33
|
|
|
$this->gatewayConfigRepository = $gatewayConfigRepository; |
34
|
|
|
$this->apiKeysTestCreator = $apiKeysTestCreator; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function fromRequest(Request $request): array |
38
|
|
|
{ |
39
|
|
|
$testApiKey = $request->get(MollieGatewayConfigurationType::API_KEY_TEST); |
40
|
|
|
|
41
|
|
|
/** @var GatewayConfigInterface $gateway */ |
42
|
|
|
$gateway = $this->gatewayConfigRepository->findOneBy(['factoryName' => MollieGatewayFactory::FACTORY_NAME]); |
43
|
|
|
$config = $gateway->getConfig(); |
44
|
|
|
|
45
|
|
|
$liveApiKey = $config[MollieGatewayConfigurationType::API_KEY_LIVE] ?? null; |
46
|
|
|
|
47
|
|
|
return [ |
48
|
|
|
$this->apiKeysTestCreator->create(MollieGatewayConfigurationType::API_KEY_TEST, $testApiKey), |
49
|
|
|
$this->apiKeysTestCreator->create(MollieGatewayConfigurationType::API_KEY_LIVE, $liveApiKey), |
50
|
|
|
]; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|