This repository was archived by the owner on Sep 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOffsitePaymentFactory.php
85 lines (72 loc) · 2.7 KB
/
OffsitePaymentFactory.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
<?php
namespace Ledjin\Sagepay;
use Payum\Core\Action\ExecuteSameRequestWithModelDetailsAction;
use Payum\Core\Extension\EndlessCycleDetectorExtension;
use Ledjin\Sagepay\Action\CaptureOffsiteAction;
use Ledjin\Sagepay\Action\ConvertPaymentAction;
use Ledjin\Sagepay\Action\NotifyAction;
use Ledjin\Sagepay\Action\StatusAction;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\GatewayFactoryInterface;
use Payum\Core\GatewayFactory;
class OffsitePaymentFactory implements GatewayFactoryInterface
{
/**
* @var GatewayFactoryInterface
*/
protected $gatewayFactory;
/**
* @var array
*/
private $defaultConfig;
/**
* @param array $defaultConfig
* @param GatewayFactoryInterface $coreGatewayFactory
*/
public function __construct(array $defaultConfig = array(), GatewayFactoryInterface $coreGatewayFactory = null)
{
$this->gatewayFactory = $coreGatewayFactory ?: new GatewayFactory();
$this->defaultConfig = $defaultConfig;
}
/**
* {@inheritDoc}
*/
public function create(array $config = array())
{
return $this->gatewayFactory->create($this->createConfig($config));
}
/**
* {@inheritDoc}
*/
public function createConfig(array $config = array())
{
$config = ArrayObject::ensureArrayObject($config);
$config->defaults($this->defaultConfig);
$config->defaults($this->gatewayFactory->createConfig((array) $config));
$config->defaults(array(
'payum.factory_name' => 'sagepay_offsite',
'payum.factory_title' => 'Sagepay Offsite',
'payum.action.capture' => new CaptureOffsiteAction(),
'payum.action.status' => new StatusAction(),
'payum.action.notify' => new NotifyAction(),
'payum.action.convert_payment' => new ConvertPaymentAction(),
'payum.action.execute_same_request_with_model_details' => new ExecuteSameRequestWithModelDetailsAction(),
'payum.extension.endless_cycle_detector' => new EndlessCycleDetectorExtension(),
));
if (false == $config['payum.api']) {
$config['options.required'] = array('vendor');
$config->defaults(array(
'sandbox' => true,
));
$config['payum.api'] = function (ArrayObject $config) {
$config->validateNotEmpty($config['options.required']);
$sagepayConfig = array(
'vendor' => $config['vendor'],
'sandbox' => $config['sandbox'],
);
return new Api($sagepayConfig, $config['buzz.client']);
};
}
return (array) $config;
}
}