-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPaynlGatewayFactory.php
101 lines (84 loc) · 2.67 KB
/
PaynlGatewayFactory.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
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
namespace PaynlPayum;
use PaynlPayum\Action\CaptureAction;
use PaynlPayum\Action\GetPaymentMethodsAction;
use PaynlPayum\Action\RefundAction;
use PaynlPayum\Action\StartAction;
use PaynlPayum\Action\StatusAction;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\GatewayFactory;
class PaynlGatewayFactory extends GatewayFactory
{
private $apiToken;
private $serviceID;
/**
* @return mixed
*/
public function getApiToken()
{
return $this->apiToken;
}
/**
* @param mixed $apiToken
*/
public function setApiToken($apiToken)
{
$this->apiToken = $apiToken;
}
/**
* @return mixed
*/
public function getServiceID()
{
return $this->serviceID;
}
/**
* @param mixed $serviceID
*/
public function setServiceID($serviceID)
{
$this->serviceID = $serviceID;
}
/**
* {@inheritDoc}
*/
protected function populateConfig(ArrayObject $config)
{
$defaults = array(
'payum.factory_name' => 'paynl_factory',
'payum.factory_title' => 'Paynl',
'payum.action.capture' => new CaptureAction(),
'payum.action.start' => new StartAction(),
'payum.action.get_payment_methods' => new GetPaymentMethodsAction(),
'payum.action.refund' => new RefundAction(),
'payum.action.status' => new StatusAction()
);
$config->defaults($defaults);
$config['payum.prepend_actions'] = [
'payum.action.start',
'payum.action.status',
'payum.action.refund'
];
if (false == $config['payum.api']) {
$config['payum.required_options'] = array(
PaynlApi::API_TOKEN,
PaynlApi::SERVICE_ID
);
$config['payum.api'] = function (ArrayObject $config) {
$config->validateNotEmpty($config['payum.required_options']);
$paynlApi = new PaynlApi();
$paynlApi->setApiToken($config[PaynlApi::API_TOKEN]);
$paynlApi->setServiceId($config[PaynlApi::SERVICE_ID]);
if (!empty($config[PaynlApi::PAYMENT_OPTION_ID])) {
$paynlApi->setPaymentMethod($config[PaynlApi::PAYMENT_OPTION_ID]);
}
if (!empty($config[PaynlApi::TOKEN_CODE])) {
$paynlApi->setTokenCode($config[PaynlApi::TOKEN_CODE]);
}
$testMode = !empty($config[PaynlApi::TEST_MODE]) ? (bool)$config[PaynlApi::TEST_MODE] : false;
$paynlApi->setTestMode($testMode);
return $paynlApi;
};
}
}
}