IyzicoGatewayFactory::populateConfig()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 30
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 20
nc 2
nop 1
dl 0
loc 30
rs 9.6
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Eres\SyliusIyzicoPlugin;
6
7
use Eres\SyliusIyzicoPlugin\Bridge\IyzicoBridgeInterface;
8
use Payum\Core\Bridge\Spl\ArrayObject;
9
use Payum\Core\GatewayFactory;
10
11
final class IyzicoGatewayFactory extends GatewayFactory
12
{
13
    public const FACTORY_NAME = 'iyzico';
14
15
    protected function populateConfig(ArrayObject $config): void
16
    {
17
        $config->defaults([
18
            'payum.factory_name' => self::FACTORY_NAME,
19
            'payum.factory_title' => 'Iyzico'
20
        ]);
21
22
        if (false === (bool)$config['payum.api']) {
23
            $config['payum.default_options'] = [
24
                'api_key' => null,
25
                'secret_key' => null,
26
                'environment' => IyzicoBridgeInterface::SANDBOX_ENVIRONMENT,
27
                'threeds' => false,
28
            ];
29
30
            $config->defaults($config['payum.default_options']);
31
32
            $config['payum.required_options'] = [
33
                'api_key',
34
                'secret_key',
35
            ];
36
37
            $config['payum.api'] = static function (ArrayObject $config): array {
38
                $config->validateNotEmpty($config['payum.required_options']);
39
40
                return [
41
                    'api_key' => $config['api_key'],
42
                    'secret_key' => $config['secret_key'],
43
                    'environment' => $config['environment'],
44
                    'threeds' => $config['threeds'],
45
                ];
46
            };
47
        }
48
    }
49
}
50