1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\Payments\Gateways\Providers\AbstractGateway\Traits; |
4
|
|
|
|
5
|
|
|
use ByTIC\Common\Records\Record; |
6
|
|
|
use ByTIC\Common\Records\Traits\Media\Files\RecordTrait as HasFilesRecord; |
7
|
|
|
use ByTIC\Payments\Gateways\Manager; |
8
|
|
|
use ByTIC\Payments\Models\Methods\Traits\RecordTrait as PaymentMethodRecord; |
9
|
|
|
use ByTIC\Payments\Models\Purchase\Traits\IsPurchasableModelTrait; |
10
|
|
|
use ByTIC\Payments\Utility\GatewayImages; |
11
|
|
|
use Nip\Utility\Traits\NameWorksTrait; |
12
|
|
|
use Omnipay\Common\Message\RequestInterface; |
13
|
|
|
use Symfony\Component\HttpFoundation\Request as HttpRequest; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class Gateway |
17
|
|
|
* @package ByTIC\Payments\Gateways\Providers\AbstractGateway |
18
|
|
|
* |
19
|
|
|
* @property $parameters \Symfony\Component\HttpFoundation\ParameterBag |
20
|
|
|
*/ |
|
|
|
|
21
|
|
|
trait GatewayTrait |
22
|
|
|
{ |
23
|
|
|
use NameWorksTrait; |
24
|
|
|
use MagicMessagesTrait; |
25
|
|
|
use HasFormsTrait; |
26
|
|
|
use DetectFromHttpRequestTrait; |
27
|
|
|
use OverwriteCompletePurchaseTrait; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var null|string |
32
|
|
|
*/ |
33
|
|
|
protected $name = null; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var null|string |
37
|
|
|
*/ |
38
|
|
|
protected $label = null; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var Manager |
42
|
|
|
*/ |
43
|
|
|
protected $manager; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var PaymentMethodRecord |
47
|
|
|
*/ |
48
|
|
|
protected $paymentMethod; |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param IsPurchasableModelTrait $record |
54
|
|
|
* @return RequestInterface |
55
|
|
|
*/ |
56
|
7 |
|
public function purchaseFromModel($record) |
57
|
|
|
{ |
58
|
7 |
|
$parameters = $record->getPurchaseParameters(); |
59
|
|
|
|
60
|
7 |
|
return $this->purchase($parameters); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return null|string |
65
|
|
|
*/ |
66
|
1 |
|
public function getName() |
67
|
|
|
{ |
68
|
1 |
|
if ($this->name === null) { |
69
|
1 |
|
$this->initName(); |
70
|
|
|
} |
71
|
|
|
|
72
|
1 |
|
return $this->name; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// ------------ GETTERS & SETTERS ------------ // |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param null $name |
|
|
|
|
79
|
|
|
*/ |
80
|
1 |
|
public function setName($name) |
81
|
|
|
{ |
82
|
1 |
|
$this->name = $name; |
83
|
1 |
|
} |
84
|
|
|
|
85
|
1 |
|
public function initName() |
86
|
|
|
{ |
87
|
1 |
|
$this->setName($this->generateName()); |
88
|
1 |
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
1 |
|
protected function generateName() |
94
|
|
|
{ |
95
|
1 |
|
return strtolower($this->getLabel()); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return null|string |
100
|
|
|
*/ |
101
|
1 |
|
public function getLabel() |
102
|
|
|
{ |
103
|
1 |
|
if ($this->label === null) { |
104
|
1 |
|
$this->initLabel(); |
105
|
|
|
} |
106
|
|
|
|
107
|
1 |
|
return $this->label; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param null|string $label |
112
|
|
|
*/ |
113
|
1 |
|
public function setLabel($label) |
114
|
|
|
{ |
115
|
1 |
|
$this->label = $label; |
116
|
1 |
|
} |
117
|
|
|
|
118
|
1 |
|
public function initLabel() |
119
|
|
|
{ |
120
|
1 |
|
$this->setLabel($this->generateLabel()); |
121
|
1 |
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
1 |
|
public function generateLabel() |
127
|
|
|
{ |
128
|
1 |
|
return $this->getNamespaceParentFolder(); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param $value |
133
|
|
|
* @return mixed |
134
|
|
|
*/ |
135
|
|
|
public function setSandbox($value) |
136
|
|
|
{ |
137
|
|
|
$return = $this->setParameter('sandbox', $value); |
|
|
|
|
138
|
|
|
$this->setTestMode($this->getSandbox() == 'yes'); |
|
|
|
|
139
|
|
|
return $return; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return mixed |
144
|
|
|
*/ |
145
|
|
|
public function getSandbox() |
146
|
|
|
{ |
147
|
|
|
return $this->getParameter('sandbox'); |
|
|
|
|
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return Manager |
152
|
|
|
*/ |
153
|
|
|
public function getManager() |
154
|
|
|
{ |
155
|
|
|
return $this->manager; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param Manager $manager |
160
|
|
|
*/ |
161
|
|
|
public function setManager($manager) |
162
|
|
|
{ |
163
|
|
|
$this->manager = $manager; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return PaymentMethodRecord|Record|HasFilesRecord |
168
|
|
|
*/ |
169
|
|
|
public function getPaymentMethod() |
170
|
|
|
{ |
171
|
|
|
return $this->paymentMethod; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param PaymentMethodRecord $paymentMethod |
176
|
|
|
*/ |
177
|
24 |
|
public function setPaymentMethod($paymentMethod) |
178
|
|
|
{ |
179
|
24 |
|
$this->paymentMethod = $paymentMethod; |
180
|
24 |
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @param HttpRequest $httpRequest |
184
|
|
|
*/ |
185
|
15 |
|
public function setHttpRequest($httpRequest) |
186
|
|
|
{ |
187
|
15 |
|
$this->httpRequest = $httpRequest; |
|
|
|
|
188
|
15 |
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param null $default |
|
|
|
|
192
|
|
|
* @return string|null |
193
|
|
|
*/ |
194
|
|
|
public function getImageBand($default = null) |
195
|
|
|
{ |
196
|
|
|
return GatewayImages::band($this->getName(), $default); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param null $default |
|
|
|
|
201
|
|
|
* @return string|null |
202
|
|
|
*/ |
203
|
|
|
public function getLogo($default = null) |
204
|
|
|
{ |
205
|
|
|
return GatewayImages::logo($this->getName(), $default); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @return boolean |
210
|
|
|
*/ |
211
|
|
|
abstract public function isActive(); |
212
|
|
|
} |
213
|
|
|
|