|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PHP version 5.4 and 8 |
|
5
|
|
|
* |
|
6
|
|
|
* @category RequestEntity |
|
7
|
|
|
* @package Payever\Payments |
|
8
|
|
|
* @author payever GmbH <[email protected]> |
|
9
|
|
|
* @copyright 2017-2021 payever GmbH |
|
10
|
|
|
* @license MIT <https://opensource.org/licenses/MIT> |
|
11
|
|
|
* @link https://docs.payever.org/shopsystems/api/getting-started |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Payever\ExternalIntegration\Payments\Http\RequestEntity; |
|
15
|
|
|
|
|
16
|
|
|
use Payever\ExternalIntegration\Core\Http\RequestEntity; |
|
17
|
|
|
use Payever\ExternalIntegration\Payments\Http\MessageEntity\CartItemEntity; |
|
18
|
|
|
use Payever\ExternalIntegration\Payments\Http\MessageEntity\CustomerAddressEntity; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* This class represents Create Payment RequestInterface Entity |
|
22
|
|
|
* |
|
23
|
|
|
* @method string getChannel() |
|
24
|
|
|
* @method integer getChannelSetId() |
|
25
|
|
|
* @method float getAmount() |
|
26
|
|
|
* @method float getFee() |
|
27
|
|
|
* @method string getOrderId() |
|
28
|
|
|
* @method string getCurrency() |
|
29
|
|
|
* @method CartItemEntity[] getCart() |
|
30
|
|
|
* @method string getSalutation() |
|
31
|
|
|
* @method string getPaymentMethod() |
|
32
|
|
|
* @method string|null getVariantId() |
|
33
|
|
|
* @method string getFirstName() |
|
34
|
|
|
* @method string getLastName() |
|
35
|
|
|
* @method string getStreet() |
|
36
|
|
|
* @method string getStreetNumber() |
|
37
|
|
|
* @method string getZip() |
|
38
|
|
|
* @method string getCity() |
|
39
|
|
|
* @method string getRegion() |
|
40
|
|
|
* @method string getCountry() |
|
41
|
|
|
* @method string getSocialSecurityNumber() |
|
42
|
|
|
* @method \DateTime|false getBirthdate() |
|
43
|
|
|
* @method string getPhone() |
|
44
|
|
|
* @method string getEmail() |
|
45
|
|
|
* @method string getLocale() |
|
46
|
|
|
* @method string getShippingAddress() |
|
47
|
|
|
* @method string getSuccessUrl() |
|
48
|
|
|
* @method string getFailureUrl() |
|
49
|
|
|
* @method string getCancelUrl() |
|
50
|
|
|
* @method string getNoticeUrl() |
|
51
|
|
|
* @method string getPendingUrl() |
|
52
|
|
|
* @method string getCustomerRedirectUrl() |
|
53
|
|
|
* @method string getXFrameHost() |
|
54
|
|
|
* @method string getPluginVersion() |
|
55
|
|
|
* @method self setChannel(string $channel) |
|
56
|
|
|
* @method self setChannelSetId(int $id) |
|
57
|
|
|
* @method self setAmount(float $amount) |
|
58
|
|
|
* @method self setFee(float $fee) |
|
59
|
|
|
* @method self setOrderId(string $id) |
|
60
|
|
|
* @method self setPaymentMethod(string $method) |
|
61
|
|
|
* @method self setVariantId(string|null $variantId) |
|
62
|
|
|
* @method self setCurrency(string $currency) |
|
63
|
|
|
* @method self setSalutation(string $salutation) |
|
64
|
|
|
* @method self setFirstName(string $name) |
|
65
|
|
|
* @method self setLastName(string $name) |
|
66
|
|
|
* @method self setStreet(string $street) |
|
67
|
|
|
* @method self setStreetNumber(string $streetNumber) |
|
68
|
|
|
* @method self setZip(string $zip) |
|
69
|
|
|
* @method self setCity(string $city) |
|
70
|
|
|
* @method self setRegion(string $region) |
|
71
|
|
|
* @method self setCountry(string $country) |
|
72
|
|
|
* @method self setSocialSecurityNumber(string $ssn) |
|
73
|
|
|
* @method self setPhone(string $phone) |
|
74
|
|
|
* @method self setEmail(string $email) |
|
75
|
|
|
* @method self setLocale(string $locale) |
|
76
|
|
|
* @method self setSuccessUrl(string $url) |
|
77
|
|
|
* @method self setFailureUrl(string $url) |
|
78
|
|
|
* @method self setCancelUrl(string $url) |
|
79
|
|
|
* @method self setNoticeUrl(string $url) |
|
80
|
|
|
* @method self setPendingUrl(string $url) |
|
81
|
|
|
* @method self setCustomerRedirectUrl(string $url) |
|
82
|
|
|
* @method self setXFrameHost(string $host) |
|
83
|
|
|
* @method self setPluginVersion(string $version) |
|
84
|
|
|
* |
|
85
|
|
|
* @SuppressWarnings(PHPMD.TooManyFields) |
|
86
|
|
|
*/ |
|
87
|
|
|
class CreatePaymentRequest extends RequestEntity |
|
88
|
|
|
{ |
|
89
|
|
|
/** @var string $channel */ |
|
90
|
|
|
protected $channel; |
|
91
|
|
|
|
|
92
|
|
|
/** @var integer $channelSetId */ |
|
93
|
|
|
protected $channelSetId; |
|
94
|
|
|
|
|
95
|
|
|
/** @var string $paymentMethod */ |
|
96
|
|
|
protected $paymentMethod; |
|
97
|
|
|
|
|
98
|
|
|
/** @var string|null */ |
|
99
|
|
|
protected $variantId; |
|
100
|
|
|
|
|
101
|
|
|
/** @var float $amount */ |
|
102
|
|
|
protected $amount; |
|
103
|
|
|
|
|
104
|
|
|
/** @var float $fee */ |
|
105
|
|
|
protected $fee; |
|
106
|
|
|
|
|
107
|
|
|
/** @var string $orderId */ |
|
108
|
|
|
protected $orderId; |
|
109
|
|
|
|
|
110
|
|
|
/** @var string $currency */ |
|
111
|
|
|
protected $currency; |
|
112
|
|
|
|
|
113
|
|
|
/** @var CartItemEntity[] $cart */ |
|
114
|
|
|
protected $cart; |
|
115
|
|
|
|
|
116
|
|
|
/** @var string $salutation */ |
|
117
|
|
|
protected $salutation; |
|
118
|
|
|
|
|
119
|
|
|
/** @var string $firstName */ |
|
120
|
|
|
protected $firstName; |
|
121
|
|
|
|
|
122
|
|
|
/** @var string $lastName */ |
|
123
|
|
|
protected $lastName; |
|
124
|
|
|
|
|
125
|
|
|
/** @var string $street */ |
|
126
|
|
|
protected $street; |
|
127
|
|
|
|
|
128
|
|
|
/** @var string $streetNumber */ |
|
129
|
|
|
protected $streetNumber; |
|
130
|
|
|
|
|
131
|
|
|
/** @var string $zip */ |
|
132
|
|
|
protected $zip; |
|
133
|
|
|
|
|
134
|
|
|
/** @var string $city */ |
|
135
|
|
|
protected $city; |
|
136
|
|
|
|
|
137
|
|
|
/** @var string $region */ |
|
138
|
|
|
protected $region; |
|
139
|
|
|
|
|
140
|
|
|
/** @var string $country */ |
|
141
|
|
|
protected $country; |
|
142
|
|
|
|
|
143
|
|
|
/** @var string $socialSecurityNumber */ |
|
144
|
|
|
protected $socialSecurityNumber; |
|
145
|
|
|
|
|
146
|
|
|
/** @var \DateTime|bool $birthdate */ |
|
147
|
|
|
protected $birthdate; |
|
148
|
|
|
|
|
149
|
|
|
/** @var string $phone */ |
|
150
|
|
|
protected $phone; |
|
151
|
|
|
|
|
152
|
|
|
/** @var string $email */ |
|
153
|
|
|
protected $email; |
|
154
|
|
|
|
|
155
|
|
|
/** @var string $successUrl */ |
|
156
|
|
|
protected $successUrl; |
|
157
|
|
|
|
|
158
|
|
|
/** @var string $failureUrl */ |
|
159
|
|
|
protected $failureUrl; |
|
160
|
|
|
|
|
161
|
|
|
/** @var string $cancelUrl */ |
|
162
|
|
|
protected $cancelUrl; |
|
163
|
|
|
|
|
164
|
|
|
/** @var string $noticeUrl */ |
|
165
|
|
|
protected $noticeUrl; |
|
166
|
|
|
|
|
167
|
|
|
/** @var string $pendingUrl */ |
|
168
|
|
|
protected $pendingUrl; |
|
169
|
|
|
|
|
170
|
|
|
/** @var string $customerRedirectUrl */ |
|
171
|
|
|
protected $customerRedirectUrl; |
|
172
|
|
|
|
|
173
|
|
|
/** @var string $xFrameHost */ |
|
174
|
|
|
protected $xFrameHost; |
|
175
|
|
|
|
|
176
|
|
|
/** @var string $pluginVersion */ |
|
177
|
|
|
protected $pluginVersion; |
|
178
|
|
|
|
|
179
|
|
|
/** @var CustomerAddressEntity $shippingAddress */ |
|
180
|
|
|
protected $shippingAddress; |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* {@inheritdoc} |
|
184
|
|
|
*/ |
|
185
|
|
|
public function getRequired() |
|
186
|
|
|
{ |
|
187
|
|
|
return [ |
|
188
|
|
|
'channel', |
|
189
|
|
|
'amount', |
|
190
|
|
|
'order_id', |
|
191
|
|
|
'currency', |
|
192
|
|
|
]; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* {@inheritdoc} |
|
197
|
|
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity) |
|
198
|
|
|
*/ |
|
199
|
|
|
public function isValid() |
|
200
|
|
|
{ |
|
201
|
|
|
if (is_array($this->cart)) { |
|
|
|
|
|
|
202
|
|
|
foreach ($this->cart as $item) { |
|
203
|
|
|
if (!$item instanceof CartItemEntity || !$item->isValid()) { |
|
204
|
|
|
return false; |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
return parent::isValid() && |
|
210
|
|
|
is_numeric($this->amount) && |
|
211
|
|
|
is_array($this->cart) && |
|
212
|
|
|
!empty($this->cart) && |
|
213
|
|
|
(!$this->channelSetId || is_integer($this->channelSetId)) && |
|
214
|
|
|
(!$this->fee || is_numeric($this->fee)) && |
|
215
|
|
|
(!$this->birthdate || $this->birthdate instanceof \DateTime); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* Sets Cart |
|
220
|
|
|
* |
|
221
|
|
|
* @param array|string $cart |
|
222
|
|
|
* |
|
223
|
|
|
* @return $this |
|
224
|
|
|
*/ |
|
225
|
|
|
public function setCart($cart) |
|
226
|
|
|
{ |
|
227
|
|
|
if (!$cart) { |
|
228
|
|
|
return $this; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
if (is_string($cart)) { |
|
232
|
|
|
$cart = json_decode($cart); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
if (!is_array($cart)) { |
|
236
|
|
|
return $this; |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
$this->cart = []; |
|
240
|
|
|
|
|
241
|
|
|
foreach ($cart as $item) { |
|
242
|
|
|
$this->cart[] = new CartItemEntity($item); |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
return $this; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* Sets shipping address |
|
250
|
|
|
* |
|
251
|
|
|
* @param CustomerAddressEntity|string $shippingAddress |
|
252
|
|
|
* |
|
253
|
|
|
* @return $this |
|
254
|
|
|
*/ |
|
255
|
|
|
public function setShippingAddress($shippingAddress) |
|
256
|
|
|
{ |
|
257
|
|
|
if (!$shippingAddress) { |
|
258
|
|
|
return $this; |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
if (is_string($shippingAddress)) { |
|
262
|
|
|
$shippingAddress = json_decode($shippingAddress); |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
if (!is_array($shippingAddress) && !is_object($shippingAddress)) { |
|
266
|
|
|
return $this; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
$this->shippingAddress = new CustomerAddressEntity($shippingAddress); |
|
270
|
|
|
|
|
271
|
|
|
return $this; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* Sets Birthdate |
|
276
|
|
|
* |
|
277
|
|
|
* @param string $birthdate |
|
278
|
|
|
* |
|
279
|
|
|
* @return $this |
|
280
|
|
|
*/ |
|
281
|
|
|
public function setBirthdate($birthdate) |
|
282
|
|
|
{ |
|
283
|
|
|
if ($birthdate) { |
|
284
|
|
|
$this->birthdate = date_create($birthdate); |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
return $this; |
|
288
|
|
|
} |
|
289
|
|
|
} |
|
290
|
|
|
|