1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file was created by developers working at BitBag |
5
|
|
|
* Do you need more information about us and what we do? Visit our https://bitbag.io website! |
6
|
|
|
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
declare(strict_types=1); |
10
|
|
|
|
11
|
|
|
namespace BitBag\SyliusMultiSafepayPlugin; |
12
|
|
|
|
13
|
|
|
use BitBag\SyliusMultiSafepayPlugin\ApiClient\MultiSafepayApiClientInterface; |
14
|
|
|
use Payum\Core\Bridge\Spl\ArrayObject; |
15
|
|
|
use Payum\Core\GatewayFactory; |
16
|
|
|
|
17
|
|
|
final class MultiSafepayGatewayFactory extends GatewayFactory |
18
|
|
|
{ |
19
|
|
|
public const FACTORY_NAME = 'multisafepay'; |
20
|
|
|
|
21
|
|
|
protected function populateConfig(ArrayObject $config): void |
22
|
|
|
{ |
23
|
|
|
$config->defaults([ |
24
|
|
|
'payum.factory_name' => self::FACTORY_NAME, |
25
|
|
|
'payum.factory_title' => 'MultiSafepay', |
26
|
|
|
'payum.http_client' => '@bitbag_sylius_multisafepay_plugin.api_client.multisafepay_api_client', |
27
|
|
|
]); |
28
|
|
|
|
29
|
|
|
if (false === (bool) $config['payum.api']) { |
30
|
|
|
$config['payum.default_options'] = [ |
31
|
|
|
'apiKey' => null, |
32
|
|
|
'sandbox' => true, |
33
|
|
|
'type' => null, |
34
|
|
|
'allow_multi_currency' => false, |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
$config->defaults($config['payum.default_options']); |
38
|
|
|
|
39
|
|
|
$config['payum.required_options'] = [ |
40
|
|
|
'apiKey', |
41
|
|
|
'type', |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
$config['payum.api'] = function (ArrayObject $config): MultiSafepayApiClientInterface { |
45
|
|
|
$config->validateNotEmpty($config['payum.required_options']); |
46
|
|
|
|
47
|
|
|
/** @var MultiSafepayApiClientInterface $multiSafepayApiClient */ |
48
|
|
|
$multiSafepayApiClient = $config['payum.http_client']; |
49
|
|
|
$multiSafepayApiClient->initialise($config['apiKey'], $config['type'], $config['sandbox'], $config['allow_multi_currency']); |
50
|
|
|
|
51
|
|
|
return $multiSafepayApiClient; |
52
|
|
|
}; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|