-
Notifications
You must be signed in to change notification settings - Fork 2
/
TcomPayWayDirectGatewayFactory.php
119 lines (105 loc) · 4.51 KB
/
TcomPayWayDirectGatewayFactory.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
namespace Locastic\TcomPayWayPayumBundle;
use Locastic\TcomPayWay\AuthorizeDirect\Api;
use Locastic\TcomPayWay\AuthorizeDirect\Model\Payment as PaymentOnsite;
use Locastic\TcomPayWayPayumBundle\Action\CaptureDirectAction;
use Locastic\TcomPayWayPayumBundle\Action\ConvertPaymentAction;
use Locastic\TcomPayWayPayumBundle\Action\ObtainCreditCardAction;
use Locastic\TcomPayWayPayumBundle\Action\StatusAction;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\GatewayFactory;
class TcomPayWayDirectGatewayFactory extends GatewayFactory
{
/**
* {@inheritDoc}
*/
protected function populateConfig(ArrayObject $config)
{
$config = ArrayObject::ensureArrayObject($config);
$config->defaults($this->defaultConfig);
$config->defaults($this->coreGatewayFactory->createConfig((array)$config));
$config->defaults([
// it will not work outside symfony full stack. If have to configure form factory manually and set it.
'symfony.form_factory' => '@form.factory',
'symfony.request_stack' => '@request_stack',
'payum.tcompayway.template.capture' => '@LocasticTcomPayWayDirect/capture.html.twig',
'payum.template.obtain_credit_card' => '@LocasticTcomPayWayDirect/obtainCreditCard.html.twig',
'payum.factory_name' => 'tcompayway_direct',
'payum.factory_title' => 'TcomPayWay Direct',
'payum.action.capture' => function(ArrayObject $config) {
return new CaptureDirectAction($config['payum.tcompayway.template.capture']);
},
'payum.action.status' => new StatusAction(),
'payum.action.convert_payment' => new ConvertPaymentAction(),
'payum.action.tcompayway_obtain_credit_card' => function(ArrayObject $config) {
$action = new ObtainCreditCardAction(
$config['symfony.form_factory'],
$config['payum.template.obtain_credit_card']
);
$action->setRequestStack($config['symfony.request_stack']);
return $action;
}
]);
$prependActions = $config->getArray('payum.prepend_actions');
$prependActions[] = 'payum.action.tcompayway_obtain_credit_card';
$config['payum.prepend_actions'] = (array) $prependActions;
if (false == $config['payum.api']) {
$config['payum.default_options'] = array(
'shop_name' => null, # this will be used in transaction description in user's bank account transactions
'shop_id' => '',
'username' => null,
'password' => null,
'secret_key' => '',
'authorization_type' => '0',
'sandbox' => true,
'disable_installments' => true,
);
$config->defaults($config['payum.default_options']);
$config['payum.required_options'] = array(
'shop_id',
'username',
'password',
'secret_key',
);
$config['payum.api'] = function (ArrayObject $config) {
$config->validateNotEmpty($config['payum.required_options']);
$api = new PaymentOnsite(
$config['shop_id'],
$config['secret_key'],
null,
null,
$config['authorization_type'],
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
$config['sandbox']
);
return $api;
};
$config['payum.api.authorization'] = function (ArrayObject $config) {
$config->validateNotEmpty($config['payum.required_options']);
$api = new Api(
$config['username'],
$config['password'],
$config['shop_id'],
$config['secret_key'],
$config['authorization_type'],
$config['sandbox']
);
return $api;
};
}
$config['payum.paths'] = array_replace([
'LocasticTcomPayWayDirect' => __DIR__.'/Resources/views/TcomPayWay/Direct',
], $config['payum.paths'] ?: []);
}
}