forked from crevillo/payum-redsys
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RedsysGatewayFactory.php
88 lines (74 loc) · 2.71 KB
/
RedsysGatewayFactory.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
80
81
82
83
84
85
86
87
88
<?php
namespace Crevillo\Payum\Redsys;
use Crevillo\Payum\Redsys\Action\NotifyAction;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\GatewayFactory as CoreGatewayFactory;
use Crevillo\Payum\Redsys\Action\CaptureAction;
use Crevillo\Payum\Redsys\Action\ConvertPaymentAction;
use Crevillo\Payum\Redsys\Action\StatusAction;
use Payum\Core\GatewayFactoryInterface;
class RedsysGatewayFactory implements GatewayFactoryInterface
{
/**
* @var GatewayFactoryInterface
*/
protected $coreGatewayFactory;
/**
* @var array
*/
private $defaultConfig;
/**
* @param array $defaultConfig
* @param GatewayFactoryInterface $coreGatewayFactory
*/
public function __construct(array $defaultConfig = array(), GatewayFactoryInterface $coreGatewayFactory = null)
{
$this->coreGatewayFactory = $coreGatewayFactory ?: new CoreGatewayFactory();
$this->defaultConfig = $defaultConfig;
}
/**
* {@inheritDoc}
*/
public function create(array $config = array())
{
return $this->coreGatewayFactory->create($this->createConfig($config));
}
/**
* {@inheritDoc}
*/
public function createConfig(array $config = array())
{
$config = ArrayObject::ensureArrayObject($config);
$config->defaults($this->defaultConfig);
$config->defaults($this->coreGatewayFactory->createConfig());
$config->defaults(array(
'payum.factory_name' => 'redsys',
'payum.factory_title' => 'Redsys',
'payum.action.capture' => new CaptureAction(),
'payum.action.notify' => new NotifyAction(),
'payum.action.convert_payment' => new ConvertPaymentAction(),
'payum.action.status' => new StatusAction(),
));
if (false == $config['payum.api']) {
$config['payum.default_options'] = array(
'merchant_code' => '',
'terminal' => '',
'secret_key' => '',
'sandbox' => true,
);
$config->defaults($config['payum.default_options']);
$config['payum.required_options'] = array('merchant_code', 'terminal', 'secret_key');
$config['payum.api'] = function (ArrayObject $config) {
$config->validateNotEmpty($config['payum.required_options']);
$redsysConfig = array(
'merchant_code' => $config['merchant_code'],
'terminal' => $config['terminal'],
'secret_key' => $config['secret_key'],
'sandbox' => $config['sandbox'],
);
return new Api($redsysConfig);
};
}
return (array) $config;
}
}