forked from ekyna/PayumPayzen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPayzenGatewayFactory.php
79 lines (65 loc) · 2.44 KB
/
PayzenGatewayFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace Ekyna\Component\Payum\Payzen;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\GatewayFactory;
use Payum\Core\GatewayFactoryInterface;
/**
* Class PayzenGatewayFactory
* @package Ekyna\Component\Payum\Payzen
* @author Etienne Dauvergne <[email protected]>
*/
class PayzenGatewayFactory extends GatewayFactory
{
/**
* Builds a new factory.
*
* @param array $defaultConfig
* @param GatewayFactoryInterface $coreGatewayFactory
*
* @return PayzenGatewayFactory
*/
public static function build(array $defaultConfig, GatewayFactoryInterface $coreGatewayFactory = null)
{
return new static($defaultConfig, $coreGatewayFactory);
}
/**
* @inheritDoc
*/
protected function populateConfig(ArrayObject $config)
{
$apiConfig = false != $config['payum.api_config']
? (array)$config['payum.api_config']
: [];
$config->defaults([
'payum.factory_name' => 'payzen',
'payum.factory_title' => 'Payzen',
'payum.action.capture' => new Action\CaptureAction(),
'payum.action.convert_payment' => new Action\ConvertPaymentAction(),
'payum.action.api_request' => new Action\Api\ApiRequestAction(),
'payum.action.api_response' => new Action\Api\ApiResponseAction(),
'payum.action.sync' => new Action\SyncAction(),
'payum.action.refund' => new Action\RefundAction(),
'payum.action.status' => new Action\StatusAction(),
]);
$defaultOptions = [];
$requiredOptions = [];
if (false == $config['payum.api']) {
$defaultOptions['api'] = array_replace([
'site_id' => null,
'certificate' => null,
'ctx_mode' => null,
'debug' => false,
], $apiConfig);
$requiredOptions[] = 'api';
$config['payum.api'] = function (ArrayObject $config) {
$config->validateNotEmpty($config['payum.required_options']);
$api = new Api\Api();
$api->setConfig($config['api']);
return $api;
};
}
$config['payum.default_options'] = $defaultOptions;
$config['payum.required_options'] = $requiredOptions;
$config->defaults($config['payum.default_options']);
}
}